mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 19:36:44 +01:00
Parametrize ChainID
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
@@ -128,7 +129,7 @@ func (tx *PoolL2Tx) SetID() error {
|
||||
// [ 16 bits ] chainId // 2 bytes
|
||||
// [ 32 bits ] signatureConstant // 4 bytes
|
||||
// Total bits compressed data: 241 bits // 31 bytes in *big.Int representation
|
||||
func (tx *PoolL2Tx) TxCompressedData() (*big.Int, error) {
|
||||
func (tx *PoolL2Tx) TxCompressedData(chainID uint16) (*big.Int, error) {
|
||||
amountFloat16, err := NewFloat16(tx.Amount)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
@@ -160,7 +161,7 @@ func (tx *PoolL2Tx) TxCompressedData() (*big.Int, error) {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
copy(b[19:25], fromIdxBytes[:])
|
||||
copy(b[25:27], []byte{0, 0}) // TODO this will be generated by the ChainID config parameter
|
||||
binary.BigEndian.PutUint16(b[25:27], chainID)
|
||||
copy(b[27:31], SignatureConstantBytes[:])
|
||||
|
||||
bi := new(big.Int).SetBytes(b[:])
|
||||
@@ -271,8 +272,8 @@ func (tx *PoolL2Tx) RqTxCompressedDataV2() (*big.Int, error) {
|
||||
}
|
||||
|
||||
// HashToSign returns the computed Poseidon hash from the *PoolL2Tx that will be signed by the sender.
|
||||
func (tx *PoolL2Tx) HashToSign() (*big.Int, error) {
|
||||
toCompressedData, err := tx.TxCompressedData()
|
||||
func (tx *PoolL2Tx) HashToSign(chainID uint16) (*big.Int, error) {
|
||||
toCompressedData, err := tx.TxCompressedData(chainID)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
@@ -292,8 +293,8 @@ func (tx *PoolL2Tx) HashToSign() (*big.Int, error) {
|
||||
}
|
||||
|
||||
// VerifySignature returns true if the signature verification is correct for the given PublicKeyComp
|
||||
func (tx *PoolL2Tx) VerifySignature(pkComp babyjub.PublicKeyComp) bool {
|
||||
h, err := tx.HashToSign()
|
||||
func (tx *PoolL2Tx) VerifySignature(chainID uint16, pkComp babyjub.PublicKeyComp) bool {
|
||||
h, err := tx.HashToSign(chainID)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user