3

I need some ("Proof-able fair") randomization inside a contract, I was thinking of using the Transaction ID, but can the client before sending the contract know what the Transaction ID is going to be?

Jeth
  • 312
  • 1
  • 4

2 Answers2

2

A transaction ID is a hash of the transaction data, which is entirely determined by the user. If they wish, they can generate as many different transactions as they like until they get a hash that suits them. Further, it's not possible to access the current transaction's ID from inside Solidity.

If you need fair random numbers, see this question for advice.

Nick Johnson
  • 8,144
  • 1
  • 28
  • 35
  • Is there a English version available of that explanation? – Jeth Apr 13 '16 at 16:01
  • 1
    For random numbers, see How can I securely generate a random number in my smart contract? http://ethereum.stackexchange.com/q/191/42 – eth Apr 13 '16 at 20:12
  • @Jeth Let me know in what way it's confusing, and I'll be happy to reword it. – Nick Johnson Apr 14 '16 at 08:49
  • It used to link to a page in mandarin? (https://github.com/randao/randao). However it's fine now. – Jeth Apr 17 '16 at 21:53
  • By transaction data, do you mean the transaction data including the signature or excluding it? Does the transaction data include the nonce, gasPrice, and gasLimit? – 0xcaff Aug 20 '17 at 01:29
2

When sending a transaction to a contract does the sender beforehand know the ID that will be assigned to the transaction?

Yes.

The transaction hash is built from the transaction data. The user would be able to modify the transaction data to generate different transaction hashes.

From core/types/transaction.go#L126-L135 :

// Hash hashes the RLP encoding of tx.
// It uniquely identifies the transaction.
func (tx *Transaction) Hash() common.Hash {
    if hash := tx.hash.Load(); hash != nil {
        return hash.(common.Hash)
    }
    v := rlpHash(tx)
    tx.hash.Store(v)
    return v
}
BokkyPooBah
  • 40,274
  • 14
  • 123
  • 193