Trying to match "golang.org/x/crypto/sha3" lib with solidity sha3() is giving me a hard time. Its been discussed in here, but I somehow cant apply it in go. How do I handle a big.Int type s.t i get solidity.sha3(uint256(1))==golang.sha3.Sum256(convertMyBigInt(myBigInt)) ?
I turn the bigInt into a hex byte array, then fill up the left site with zeros, hash and then output.
//create a big int for test and set to 1
b1 := new(big.Int)
b1.SetInt64(1)
//create empty array with 32 bytes for padding
empty := make([]byte,32)
//turn the big int into a hex string (let me know if there is a more
//elegant way^^)
String := bytes.NewBufferString(b1.Text(16))
copy(empty[len(empty)-len(String.Bytes()):],String.Bytes())
//output of empty : [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 49]
res:= new(big.Int)
temp:=sha3.Sum256(empty)
res.SetBytes(temp[:])
fmt.Println("\nresult ",res.Text(16))
output: 26502030f0954243c70cb7fa68e0752ce2bf99aabfc0219d5184635d4c61dbd8
solidity gives me:
sha3(uint(1))
b10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6
can someone give me a short example how to match solidity sha3 with golang sha3 in an elegant manner? I'd be very thankful!