Update TxID to use eth Keccak256

- Update TxID to use eth Keccak256
- Added more tests to L2Tx TxID calculation to check compatibility with
js version from https://github.com/hermeznetwork/hermezjs/pull/57
This commit is contained in:
arnaucube
2021-02-01 15:24:57 +01:00
parent f0886b3d2a
commit c1cd37913f
8 changed files with 111 additions and 45 deletions

View File

@@ -1,10 +1,10 @@
package common
import (
"crypto/sha256"
"fmt"
"math/big"
ethCrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/hermeznetwork/tracerr"
)
@@ -104,15 +104,10 @@ func (tx L2Tx) CalculateTxID() ([TxIDLen]byte, error) {
b = append(b, byte(tx.Fee))
// calculate hash
h := sha256.New()
_, err = h.Write(b)
if err != nil {
return txID, tracerr.Wrap(err)
}
r := h.Sum(nil)
h := ethCrypto.Keccak256Hash(b).Bytes()
txID[0] = TxIDPrefixL2Tx
copy(txID[1:], r)
copy(txID[1:], h)
return txID, nil
}