Browse Source

Apply suggestions from code review

Co-authored-by: Eduard S. <eduard@iden3.io>
feature/sql-semaphore1
arnau 4 years ago
committed by arnaucube
parent
commit
2109d9f1cf
2 changed files with 2 additions and 6 deletions
  1. +1
    -5
      common/leaf.go
  2. +1
    -1
      common/tx.go

+ 1
- 5
common/leaf.go

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"math"
"math/big" "math/big"
eth "github.com/ethereum/go-ethereum/common" eth "github.com/ethereum/go-ethereum/common"
@ -28,7 +27,7 @@ type Leaf struct {
func (l *Leaf) Bytes() ([32 * NLEAFELEMS]byte, error) { func (l *Leaf) Bytes() ([32 * NLEAFELEMS]byte, error) {
var b [32 * NLEAFELEMS]byte var b [32 * NLEAFELEMS]byte
if l.Nonce >= uint64(math.Pow(2, 40)) {
if l.Nonce > 0xffffffffff {
return b, fmt.Errorf("%s Nonce", ErrNumOverflow) return b, fmt.Errorf("%s Nonce", ErrNumOverflow)
} }
if len(l.Balance.Bytes()) > 24 { if len(l.Balance.Bytes()) > 24 {
@ -102,9 +101,6 @@ func LeafFromBytes(b [32 * NLEAFELEMS]byte) (*Leaf, error) {
var nonceBytes [8]byte var nonceBytes [8]byte
copy(nonceBytes[:], b[4:9]) copy(nonceBytes[:], b[4:9])
nonce := binary.LittleEndian.Uint64(nonceBytes[:]) nonce := binary.LittleEndian.Uint64(nonceBytes[:])
if nonce >= uint64(math.Pow(2, 40)) {
return nil, fmt.Errorf("%s Nonce", ErrNumOverflow)
}
sign := b[10] == 1 sign := b[10] == 1
balance := new(big.Int).SetBytes(SwapEndianness(b[32:56])) // b[32:56], as Balance is 192 bits (24 bytes) 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}) { if !bytes.Equal(b[56:64], []byte{0, 0, 0, 0, 0, 0, 0, 0}) {

+ 1
- 1
common/tx.go

@ -22,7 +22,7 @@ func (idx Idx) BigInt() *big.Int {
// IdxFromBigInt converts a *big.Int to Idx type // IdxFromBigInt converts a *big.Int to Idx type
func IdxFromBigInt(b *big.Int) (Idx, error) { 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 0, ErrNumOverflow
} }
return Idx(uint32(b.Int64())), nil return Idx(uint32(b.Int64())), nil

Loading…
Cancel
Save