Apply suggestions from code review Co-authored-by: Eduard S. <eduard@iden3.io>
arnau 17317030+arnaucube@users.noreply.github.com
Thu, 06 Aug 2020 12:47:32 +0200
2 files changed,
2 insertions(+),
6 deletions(-)
M
common/leaf.go
→
common/leaf.go
@@ -4,7 +4,6 @@ import (
"bytes" "encoding/binary" "fmt" - "math" "math/big" eth "github.com/ethereum/go-ethereum/common"@@ -28,7 +27,7 @@ // Bytes returns the bytes representing the Leaf, in a way that each BigInt is represented by 32 bytes, in spite of the BigInt could be represented in less bytes (due a small big.Int), so in this way each BigInt is always 32 bytes and can be automatically parsed from a byte array.
func (l *Leaf) Bytes() ([32 * NLEAFELEMS]byte, error) { var b [32 * NLEAFELEMS]byte - if l.Nonce >= uint64(math.Pow(2, 40)) { + if l.Nonce > 0xffffffffff { return b, fmt.Errorf("%s Nonce", ErrNumOverflow) } if len(l.Balance.Bytes()) > 24 {@@ -102,9 +101,6 @@ tokenID := binary.LittleEndian.Uint32(b[0:4])
var nonceBytes [8]byte copy(nonceBytes[:], b[4:9]) nonce := binary.LittleEndian.Uint64(nonceBytes[:]) - if nonce >= uint64(math.Pow(2, 40)) { - return nil, fmt.Errorf("%s Nonce", ErrNumOverflow) - } sign := b[10] == 1 balance := new(big.Int).SetBytes(SwapEndianness(b[32:56])) // b[32:56], as Balance is 192 bits (24 bytes) if !bytes.Equal(b[56:64], []byte{0, 0, 0, 0, 0, 0, 0, 0}) {
M
common/tx.go
→
common/tx.go
@@ -22,7 +22,7 @@ }
// IdxFromBigInt converts a *big.Int to Idx type func IdxFromBigInt(b *big.Int) (Idx, error) { - if b.Int64() > 4294967295 { // 2**32-1 + if b.Int64() > 0xffffffff { // 2**32-1 return 0, ErrNumOverflow } return Idx(uint32(b.Int64())), nil