0

Hey below function is used to originate a dummy contract address. As tezos doesn't provide transaction hash or block hash. I am planning to use dummy contract address as a seed and then generate a random number .

@sp.entry_point
    def generate_address(self):
        # Generate the address but don't append the operation
        contract = sp.create_contract_operation(sp.Contract(), sp.unit, sp.tez(0), None);
        self.data.address = sp.some(sp.pack(contract.address))

I believe the above address cannot be manipulated externally or by any means? Or is this a bad idea?

1

1 Answer 1

4

The address of these dummy contracts depends directly on the hash of the transaction, so it can be easily manipulated by the one creating it. So if the transactions are created by users, they can basically cheat. And if only some kind of admin creates the transaction, it requires users to trust them, so it's no better than letting the admin directly provide a random number.

5
  • I haven't checked but I think that it can also be manipulated by the baker including the transaction as she could insert origination operations earlier in the block to alter the operation counter. Commented Dec 1, 2022 at 9:16
  • 1
    From what I understood, the origination index only depends on the current operation group, not the whole block.
    – LucasF
    Commented Dec 1, 2022 at 9:24
  • You are right LucasF. Commented Dec 1, 2022 at 10:07
  • there are two contract c1 and c2. the function on c1 is random() and function on c2 is generate_random() . the generate_random() consists of the above origination of address code , converted it into nat and then returns to c1 . the random() just calls the c2 for generate_random(). In this case user calls c1 and then c1 calls c2 . As the address will be originated by c2, so will the user be able to manipulate the address now?
    – Kin
    Commented Dec 5, 2022 at 1:36
  • 1
    The user is still responsible for crafting the operation and can adjust different parameters (such as fees) to generate different operation hashes and choose the one that suits her best. See this article for more info about random generation inside smart contracts.
    – LucasF
    Commented Dec 5, 2022 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.