Browse Source

StateDB ZKInputs generation compatible with circom

- Add SignatureConstant to L1Tx.TxCompressedData
- ZKInputs generation works initial version working and compatible with circom Hermez circuit
    - Lots of small updates for circuits compatibility
- Update version (with new changes) of `go-iden3-crypto` & `go-merkletree`
feature/sql-semaphore1
arnaucube 4 years ago
parent
commit
80cbac24f9
13 changed files with 186 additions and 104 deletions
  1. +4
    -3
      common/l1tx.go
  2. +2
    -2
      common/l1tx_test.go
  3. +2
    -8
      common/pooll2tx.go
  4. +10
    -12
      common/pooll2tx_test.go
  5. +7
    -0
      common/tx.go
  6. +10
    -0
      common/tx_test.go
  7. +11
    -5
      common/zk.go
  8. +80
    -44
      db/statedb/txprocessors.go
  9. +36
    -12
      db/statedb/txprocessors_test.go
  10. +2
    -4
      go.mod
  11. +4
    -0
      go.sum
  12. +6
    -4
      test/til/lang.go
  13. +12
    -10
      test/til/txs.go

+ 4
- 3
common/l1tx.go

@ -167,8 +167,9 @@ func (tx L1Tx) TxCompressedData() (*big.Int, error) {
if err != nil {
return nil, tracerr.Wrap(err)
}
var b [31]byte
// b[0:7] empty: no fee neither nonce
// b[0:7] empty: no ToBJJSign, no fee, no nonce
copy(b[7:11], tx.TokenID.Bytes())
copy(b[11:13], amountFloat16.Bytes())
toIdxBytes, err := tx.ToIdx.Bytes()
@ -181,8 +182,8 @@ func (tx L1Tx) TxCompressedData() (*big.Int, error) {
return nil, tracerr.Wrap(err)
}
copy(b[19:25], fromIdxBytes[:])
copy(b[25:27], []byte{0, 1}) // TODO this will be generated by the ChainID config parameter
// b[27:] empty: no signature
copy(b[25:27], []byte{0, 0}) // TODO this will be generated by the ChainID config parameter
copy(b[27:31], SignatureConstantBytes[:])
bi := new(big.Int).SetBytes(b[:])
return bi, nil

+ 2
- 2
common/l1tx_test.go

@ -60,9 +60,9 @@ func TestL1TxCompressedData(t *testing.T) {
assert.Nil(t, err)
// test vector value generated from javascript implementation
expectedStr := "7307597389635308713748674793997299267460566876160"
expectedStr := "7307597389635308713748674793997299267459594577423"
assert.Equal(t, expectedStr, txCompressedData.String())
assert.Equal(t, "050004000000000003000000000002000100000000", hex.EncodeToString(txCompressedData.Bytes()))
assert.Equal(t, "0500040000000000030000000000020000c60be60f", hex.EncodeToString(txCompressedData.Bytes()))
}
func TestBytesDataAvailability(t *testing.T) {

+ 2
- 8
common/pooll2tx.go

@ -107,12 +107,6 @@ func NewPoolL2Tx(poolL2Tx *PoolL2Tx) (*PoolL2Tx, error) {
// [ 32 bits ] signatureConstant // 4 bytes
// Total bits compressed data: 241 bits // 31 bytes in *big.Int representation
func (tx *PoolL2Tx) TxCompressedData() (*big.Int, error) {
// sigconstant
sc, ok := new(big.Int).SetString("3322668559", 10)
if !ok {
return nil, tracerr.Wrap(fmt.Errorf("error parsing SignatureConstant"))
}
amountFloat16, err := NewFloat16(tx.Amount)
if err != nil {
return nil, tracerr.Wrap(err)
@ -141,8 +135,8 @@ func (tx *PoolL2Tx) TxCompressedData() (*big.Int, error) {
return nil, tracerr.Wrap(err)
}
copy(b[19:25], fromIdxBytes[:])
copy(b[25:27], []byte{0, 1}) // TODO this will be generated by the ChainID config parameter
copy(b[27:31], sc.Bytes())
copy(b[25:27], []byte{0, 0}) // TODO this will be generated by the ChainID config parameter
copy(b[27:31], SignatureConstantBytes[:])
bi := new(big.Int).SetBytes(b[:])
return bi, nil

+ 10
- 12
common/pooll2tx_test.go

@ -38,9 +38,9 @@ func TestTxCompressedData(t *testing.T) {
txCompressedData, err := tx.TxCompressedData()
assert.Nil(t, err)
// test vector value generated from javascript implementation
expectedStr := "1766847064778421992193717128424891165872736891548909569553540449389241871"
expectedStr := "1766847064778421992193717128424891165872736891548909569553540445094274575"
assert.Equal(t, expectedStr, txCompressedData.String())
assert.Equal(t, "010000000000060000000500040000000000030000000000020001c60be60f", hex.EncodeToString(txCompressedData.Bytes()))
assert.Equal(t, "010000000000060000000500040000000000030000000000020000c60be60f", hex.EncodeToString(txCompressedData.Bytes()))
tx = PoolL2Tx{
RqFromIdx: 7,
RqToIdx: 8,
@ -112,18 +112,16 @@ func TestHashToSign(t *testing.T) {
_, err := hex.Decode(sk[:], []byte("0001020304050607080900010203040506070809000102030405060708090001"))
assert.Nil(t, err)
tx := PoolL2Tx{
FromIdx: 2,
ToIdx: 3,
Amount: big.NewInt(4),
TokenID: 5,
Nonce: 6,
ToBJJ: sk.Public(),
RqToEthAddr: ethCommon.HexToAddress("0xc58d29fA6e86E4FAe04DDcEd660d45BCf3Cb2370"),
RqToBJJ: sk.Public(),
FromIdx: 2,
ToIdx: 3,
Amount: big.NewInt(4),
TokenID: 5,
Nonce: 6,
ToEthAddr: ethCommon.HexToAddress("0xc58d29fA6e86E4FAe04DDcEd660d45BCf3Cb2370"),
}
toSign, err := tx.HashToSign()
assert.Nil(t, err)
assert.Equal(t, "13412877307445712067533842795279849753265998687662992184595695642580679868064", toSign.String())
assert.Equal(t, "1469900657138253851938022936440971384682713995864967090251961124784132925291", toSign.String())
}
func TestVerifyTxSignature(t *testing.T) {
@ -142,7 +140,7 @@ func TestVerifyTxSignature(t *testing.T) {
}
toSign, err := tx.HashToSign()
assert.Nil(t, err)
assert.Equal(t, "13412877307445712067533842795279849753265998687662992184595695642580679868064", toSign.String())
assert.Equal(t, "18645218094210271622244722988708640202588315450486586312909439859037906375295", toSign.String())
sig := sk.SignPoseidon(toSign)
tx.Signature = sig.Compress()

+ 7
- 0
common/tx.go

@ -34,6 +34,13 @@ const (
TxIDLen = 12
)
var (
// SignatureConstantBytes contains the SignatureConstant in byte array
// format, which is equivalent to 3322668559 as uint32 in byte array in
// big endian representation.
SignatureConstantBytes = []byte{198, 11, 230, 15}
)
// TxID is the identifier of a Hermez network transaction
type TxID [TxIDLen]byte

+ 10
- 0
common/tx_test.go

@ -3,11 +3,21 @@ package common
import (
"database/sql"
"database/sql/driver"
"encoding/binary"
"encoding/hex"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSignatureConstant(t *testing.T) {
signatureConstant := uint32(3322668559)
var signatureConstantBytes [4]byte
binary.BigEndian.PutUint32(signatureConstantBytes[:], signatureConstant)
assert.Equal(t, SignatureConstantBytes, signatureConstantBytes[:])
assert.Equal(t, "c60be60f", hex.EncodeToString(SignatureConstantBytes))
}
func TestTxIDScannerValue(t *testing.T) {
txid0 := &TxID{}
txid1 := &TxID{}

+ 11
- 5
common/zk.go

@ -58,14 +58,16 @@ type ZKInputs struct {
OldLastIdx *big.Int `json:"oldLastIdx"` // uint64 (max nLevels bits)
// OldStateRoot is the current state merkle tree root
OldStateRoot *big.Int `json:"oldStateRoot"` // Hash
// GlobalChainID is the blockchain ID (0 for Ethereum mainnet). This value can be get from the smart contract.
// GlobalChainID is the blockchain ID (0 for Ethereum mainnet). This
// value can be get from the smart contract.
GlobalChainID *big.Int `json:"globalChainID"` // uint16
// FeeIdxs is an array of merkle tree indexes where the coordinator will receive the accumulated fees
// FeeIdxs is an array of merkle tree indexes where the coordinator
// will receive the accumulated fees
FeeIdxs []*big.Int `json:"feeIdxs"` // uint64 (max nLevels bits), len: [maxFeeIdxs]
// accumulate fees
// FeePlanTokens contains all the tokenIDs for which the fees are being accumulated
FeePlanTokens []*big.Int `json:"feePlanTokens"` // uint32 (max 32 bits), len: [maxFeeIdxs]
FeePlanTokens []*big.Int `json:"feePlanTokens"` // uint32 (max nLevels bits), len: [maxFeeIdxs]
//
// Txs (L1&L2)
@ -87,7 +89,9 @@ type ZKInputs struct {
// ToIdx
ToIdx []*big.Int `json:"toIdx"` // uint64 (max nLevels bits), len: [nTx]
// AuxToIdx is the Idx of the Tx that has 'toIdx==0', is the coordinator who will find which Idx corresponds to the 'toBJJAy' or 'toEthAddr'
// AuxToIdx is the Idx of the Tx that has 'toIdx==0', is the
// coordinator who will find which Idx corresponds to the 'toBJJAy' or
// 'toEthAddr'
AuxToIdx []*big.Int `json:"auxToIdx"` // uint64 (max nLevels bits), len: [nTx]
// ToBJJAy
ToBJJAy []*big.Int `json:"toBjjAy"` // big.Int, len: [nTx]
@ -136,7 +140,9 @@ type ZKInputs struct {
// State MerkleTree Leafs transitions
//
// state 1, value of the sender (from) account leaf
// state 1, value of the sender (from) account leaf. The values at the
// moment pre-smtprocessor of the update (before updating the Sender
// leaf).
TokenID1 []*big.Int `json:"tokenID1"` // uint32, len: [nTx]
Nonce1 []*big.Int `json:"nonce1"` // uint64 (max 40 bits), len: [nTx]
Sign1 []*big.Int `json:"sign1"` // bool, len: [nTx]

+ 80
- 44
db/statedb/txprocessors.go

@ -92,10 +92,18 @@ func (s *StateDB) ProcessTxs(ptc ProcessTxsConfig, coordIdxs []common.Idx, l1use
CollectedFees: nil,
}, nil
}
if nTx > int(ptc.MaxTx) {
return nil, tracerr.Wrap(fmt.Errorf("L1UserTx + L1CoordinatorTx + L2Tx (%d) can not be bigger than MaxTx (%d)", nTx, ptc.MaxTx))
}
if len(l1usertxs)+len(l1coordinatortxs) > int(ptc.MaxL1Tx) {
return nil, tracerr.Wrap(fmt.Errorf("L1UserTx + L1CoordinatorTx (%d) can not be bigger than MaxL1Tx (%d)", len(l1usertxs)+len(l1coordinatortxs), ptc.MaxTx))
}
exits := make([]processedExit, nTx)
if s.typ == TypeBatchBuilder {
s.zki = common.NewZKInputs(uint32(nTx), ptc.MaxL1Tx, ptc.MaxTx, ptc.MaxFeeTx, ptc.NLevels, s.currentBatch.BigInt())
s.zki = common.NewZKInputs(ptc.MaxTx, ptc.MaxL1Tx, ptc.MaxTx, ptc.MaxFeeTx, ptc.NLevels, s.currentBatch.BigInt())
s.zki.OldLastIdx = s.idx.BigInt()
s.zki.OldStateRoot = s.mt.Root().BigInt()
}
@ -146,10 +154,8 @@ func (s *StateDB) ProcessTxs(ptc ProcessTxsConfig, coordIdxs []common.Idx, l1use
}
s.zki.Metadata.L1TxsDataAvailability = append(s.zki.Metadata.L1TxsDataAvailability, l1TxDataAvailability)
if s.i < nTx-1 {
s.zki.ISOutIdx[s.i] = s.idx.BigInt()
s.zki.ISStateRoot[s.i] = s.mt.Root().BigInt()
}
s.zki.ISOutIdx[s.i] = s.idx.BigInt()
s.zki.ISStateRoot[s.i] = s.mt.Root().BigInt()
}
if s.typ == TypeSynchronizer || s.typ == TypeBatchBuilder {
if exitIdx != nil && exitTree != nil {
@ -183,10 +189,8 @@ func (s *StateDB) ProcessTxs(ptc ProcessTxsConfig, coordIdxs []common.Idx, l1use
}
s.zki.Metadata.L1TxsData = append(s.zki.Metadata.L1TxsData, l1TxData)
if s.i < nTx-1 {
s.zki.ISOutIdx[s.i] = s.idx.BigInt()
s.zki.ISStateRoot[s.i] = s.mt.Root().BigInt()
}
s.zki.ISOutIdx[s.i] = s.idx.BigInt()
s.zki.ISStateRoot[s.i] = s.mt.Root().BigInt()
s.i++
}
}
@ -260,6 +264,15 @@ func (s *StateDB) ProcessTxs(ptc ProcessTxsConfig, coordIdxs []common.Idx, l1use
}
if s.zki != nil {
for i := s.i - 1; i < int(ptc.MaxTx); i++ {
if i < int(ptc.MaxTx)-1 {
s.zki.ISOutIdx[i] = s.idx.BigInt()
s.zki.ISStateRoot[i] = s.mt.Root().BigInt()
}
if i >= s.i {
s.zki.TxCompressedData[i] = new(big.Int).SetBytes(common.SignatureConstantBytes)
}
}
// before computing the Fees txs, set the ISInitStateRootFee
s.zki.ISInitStateRootFee = s.mt.Root().BigInt()
}
@ -298,6 +311,11 @@ func (s *StateDB) ProcessTxs(ptc ProcessTxsConfig, coordIdxs []common.Idx, l1use
}
iFee++
}
if s.zki != nil {
for i := len(s.accumulatedFees); i < int(ptc.MaxFeeTx)-1; i++ {
s.zki.ISStateRootFee[i] = s.mt.Root().BigInt()
}
}
if s.typ == TypeTxSelector {
return nil, nil
@ -437,7 +455,11 @@ func (s *StateDB) processL1Tx(exitTree *merkletree.MerkleTree, tx *common.L1Tx)
s.zki.OnChain[s.i] = big.NewInt(1)
// L1Txs
s.zki.LoadAmountF[s.i] = tx.LoadAmount
loadAmountF16, err := common.NewFloat16(tx.LoadAmount)
if err != nil {
return nil, nil, false, nil, tracerr.Wrap(err)
}
s.zki.LoadAmountF[s.i] = big.NewInt(int64(loadAmountF16))
s.zki.FromEthAddr[s.i] = common.EthAddrToBigInt(tx.FromEthAddr)
if tx.FromBJJ != nil {
s.zki.FromBJJCompressed[s.i] = BJJCompressedTo256BigInts(tx.FromBJJ.Compress())
@ -587,6 +609,7 @@ func (s *StateDB) processL2Tx(coordIdxsMap map[common.TokenID]common.Idx, collec
// s.zki.RqTxCompressedDataV2[s.i] = // TODO
// s.zki.RqToEthAddr[s.i] = common.EthAddrToBigInt(tx.RqToEthAddr) // TODO
// s.zki.RqToBJJAy[s.i] = tx.ToBJJ.Y // TODO
signature, err := tx.Signature.Decompress()
if err != nil {
log.Error(err)
@ -760,6 +783,18 @@ func (s *StateDB) applyTransfer(coordIdxsMap map[common.TokenID]common.Idx,
log.Error(err)
return tracerr.Wrap(err)
}
if s.zki != nil {
// Set the State1 before updating the Sender leaf
s.zki.TokenID1[s.i] = accSender.TokenID.BigInt()
s.zki.Nonce1[s.i] = accSender.Nonce.BigInt()
if babyjub.PointCoordSign(accSender.PublicKey.X) {
s.zki.Sign1[s.i] = big.NewInt(1)
}
s.zki.Ay1[s.i] = accSender.PublicKey.Y
s.zki.Balance1[s.i] = accSender.Balance
s.zki.EthAddr1[s.i] = common.EthAddrToBigInt(accSender.EthAddr)
}
if !tx.IsL1 {
// increment nonce
accSender.Nonce++
@ -772,10 +807,11 @@ func (s *StateDB) applyTransfer(coordIdxsMap map[common.TokenID]common.Idx,
feeAndAmount := new(big.Int).Add(tx.Amount, fee)
accSender.Balance = new(big.Int).Sub(accSender.Balance, feeAndAmount)
accCoord, err := s.GetAccount(coordIdxsMap[accSender.TokenID])
if err != nil {
log.Debugw("No coord Idx to receive fee", "tx", tx)
} else {
if _, ok := coordIdxsMap[accSender.TokenID]; ok {
accCoord, err := s.GetAccount(coordIdxsMap[accSender.TokenID])
if err != nil {
return tracerr.Wrap(fmt.Errorf("Can not use CoordIdx that does not exist in the tree. TokenID: %d, CoordIdx: %d", accSender.TokenID, coordIdxsMap[accSender.TokenID]))
}
// accumulate the fee for the Coord account
accumulated := s.accumulatedFees[accCoord.Idx]
accumulated.Add(accumulated, fee)
@ -784,11 +820,23 @@ func (s *StateDB) applyTransfer(coordIdxsMap map[common.TokenID]common.Idx,
collected := collectedFees[accCoord.TokenID]
collected.Add(collected, fee)
}
} else {
log.Debugw("No coord Idx to receive fee", "tx", tx)
}
} else {
accSender.Balance = new(big.Int).Sub(accSender.Balance, tx.Amount)
}
// update sender account in localStateDB
pSender, err := s.UpdateAccount(tx.FromIdx, accSender)
if err != nil {
log.Error(err)
return tracerr.Wrap(err)
}
if s.zki != nil {
s.zki.Siblings1[s.i] = siblingsToZKInputFormat(pSender.Siblings)
}
var accReceiver *common.Account
if tx.FromIdx == auxToIdx {
// if Sender is the Receiver, reuse 'accSender' pointer,
@ -802,42 +850,27 @@ func (s *StateDB) applyTransfer(coordIdxsMap map[common.TokenID]common.Idx,
return tracerr.Wrap(err)
}
}
// add amount-feeAmount to the receiver
accReceiver.Balance = new(big.Int).Add(accReceiver.Balance, tx.Amount)
// update sender account in localStateDB
pSender, err := s.UpdateAccount(tx.FromIdx, accSender)
if err != nil {
log.Error(err)
return tracerr.Wrap(err)
}
if s.zki != nil {
s.zki.TokenID1[s.i] = accSender.TokenID.BigInt()
s.zki.Nonce1[s.i] = accSender.Nonce.BigInt()
if babyjub.PointCoordSign(accSender.PublicKey.X) {
s.zki.Sign1[s.i] = big.NewInt(1)
// Set the State2 before updating the Receiver leaf
s.zki.TokenID2[s.i] = accReceiver.TokenID.BigInt()
s.zki.Nonce2[s.i] = accReceiver.Nonce.BigInt()
if babyjub.PointCoordSign(accReceiver.PublicKey.X) {
s.zki.Sign2[s.i] = big.NewInt(1)
}
s.zki.Ay1[s.i] = accSender.PublicKey.Y
s.zki.Balance1[s.i] = accSender.Balance
s.zki.EthAddr1[s.i] = common.EthAddrToBigInt(accSender.EthAddr)
s.zki.Siblings1[s.i] = siblingsToZKInputFormat(pSender.Siblings)
s.zki.Ay2[s.i] = accReceiver.PublicKey.Y
s.zki.Balance2[s.i] = accReceiver.Balance
s.zki.EthAddr2[s.i] = common.EthAddrToBigInt(accReceiver.EthAddr)
}
// add amount-feeAmount to the receiver
accReceiver.Balance = new(big.Int).Add(accReceiver.Balance, tx.Amount)
// update receiver account in localStateDB
pReceiver, err := s.UpdateAccount(auxToIdx, accReceiver)
if err != nil {
return tracerr.Wrap(err)
}
if s.zki != nil {
s.zki.TokenID2[s.i] = accReceiver.TokenID.BigInt()
s.zki.Nonce2[s.i] = accReceiver.Nonce.BigInt()
if babyjub.PointCoordSign(accReceiver.PublicKey.X) {
s.zki.Sign2[s.i] = big.NewInt(1)
}
s.zki.Ay2[s.i] = accReceiver.PublicKey.Y
s.zki.Balance2[s.i] = accReceiver.Balance
s.zki.EthAddr2[s.i] = common.EthAddrToBigInt(accReceiver.EthAddr)
s.zki.Siblings2[s.i] = siblingsToZKInputFormat(pReceiver.Siblings)
}
@ -938,10 +971,11 @@ func (s *StateDB) applyExit(coordIdxsMap map[common.TokenID]common.Idx,
feeAndAmount := new(big.Int).Add(tx.Amount, fee)
acc.Balance = new(big.Int).Sub(acc.Balance, feeAndAmount)
accCoord, err := s.GetAccount(coordIdxsMap[acc.TokenID])
if err != nil {
log.Debugw("No coord Idx to receive fee", "tx", tx)
} else {
if _, ok := coordIdxsMap[acc.TokenID]; ok {
accCoord, err := s.GetAccount(coordIdxsMap[acc.TokenID])
if err != nil {
return nil, false, tracerr.Wrap(fmt.Errorf("Can not use CoordIdx that does not exist in the tree. TokenID: %d, CoordIdx: %d", acc.TokenID, coordIdxsMap[acc.TokenID]))
}
// accumulate the fee for the Coord account
accumulated := s.accumulatedFees[accCoord.Idx]
accumulated.Add(accumulated, fee)
@ -950,6 +984,8 @@ func (s *StateDB) applyExit(coordIdxsMap map[common.TokenID]common.Idx,
collected := collectedFees[accCoord.TokenID]
collected.Add(collected, fee)
}
} else {
log.Debugw("No coord Idx to receive fee", "tx", tx)
}
} else {
acc.Balance = new(big.Int).Sub(acc.Balance, tx.Amount)

+ 36
- 12
db/statedb/txprocessors_test.go
File diff suppressed because it is too large
View File


+ 2
- 4
go.mod

@ -13,8 +13,8 @@ require (
github.com/go-sql-driver/mysql v1.5.0 // indirect
github.com/gobuffalo/packr/v2 v2.8.0
github.com/hermeznetwork/tracerr v0.3.1-0.20201126162137-de9930d0cf29
github.com/iden3/go-iden3-crypto v0.0.6-0.20201016142444-94e92e88fb4e
github.com/iden3/go-merkletree v0.0.0-20201103115630-ad30c8309b44
github.com/iden3/go-iden3-crypto v0.0.6-0.20201203095229-821a601d2002
github.com/iden3/go-merkletree v0.0.0-20201203095330-4a8397a45644
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a
github.com/jmoiron/sqlx v1.2.1-0.20200615141059-0794cb1f47ee
github.com/joho/godotenv v1.3.0
@ -38,5 +38,3 @@ require (
gopkg.in/go-playground/validator.v9 v9.29.1
honnef.co/go/tools v0.0.1-2020.1.5 // indirect
)
// replace github.com/russross/meddler => /home/dev/git/iden3/hermez/meddler

+ 4
- 0
go.sum

@ -323,10 +323,14 @@ github.com/iden3/go-iden3-crypto v0.0.6-0.20200819064831-09d161e9f670 h1:gNBFu/W
github.com/iden3/go-iden3-crypto v0.0.6-0.20200819064831-09d161e9f670/go.mod h1:oBgthFLboAWi9feaBUFy7OxEcyn9vA1khHSL/WwWFyg=
github.com/iden3/go-iden3-crypto v0.0.6-0.20201016142444-94e92e88fb4e h1:DvzTgAkzfcW8l4mHgEaMv2hgDTlisym/gGNNTNKqnpQ=
github.com/iden3/go-iden3-crypto v0.0.6-0.20201016142444-94e92e88fb4e/go.mod h1:oBgthFLboAWi9feaBUFy7OxEcyn9vA1khHSL/WwWFyg=
github.com/iden3/go-iden3-crypto v0.0.6-0.20201203095229-821a601d2002 h1:f2twuL20aAqq1TlSdfQgL5r68hKjB/ioQdSctREQLuY=
github.com/iden3/go-iden3-crypto v0.0.6-0.20201203095229-821a601d2002/go.mod h1:oBgthFLboAWi9feaBUFy7OxEcyn9vA1khHSL/WwWFyg=
github.com/iden3/go-merkletree v0.0.0-20200902123354-eeb949f8c334 h1:FQngDJKiwM6i4kHlVFvSpJa9sO+QvZ7C+GqoPWe+5BI=
github.com/iden3/go-merkletree v0.0.0-20200902123354-eeb949f8c334/go.mod h1:MRe6i0mi2oDVUzgBIHsNRE6XAg8EBuqIQZMsd+do+dU=
github.com/iden3/go-merkletree v0.0.0-20201103115630-ad30c8309b44 h1:d6AbzJWWUosTpjb6Ab+I0bMO4UPY+u/HgkOdhksxDgY=
github.com/iden3/go-merkletree v0.0.0-20201103115630-ad30c8309b44/go.mod h1:MRe6i0mi2oDVUzgBIHsNRE6XAg8EBuqIQZMsd+do+dU=
github.com/iden3/go-merkletree v0.0.0-20201203095330-4a8397a45644 h1:obSehuklDMDpmQ4j0d6RxU70bjRjEWlGlkO13CKp8Fw=
github.com/iden3/go-merkletree v0.0.0-20201203095330-4a8397a45644/go.mod h1:MRe6i0mi2oDVUzgBIHsNRE6XAg8EBuqIQZMsd+do+dU=
github.com/iden3/go-wasm3 v0.0.1/go.mod h1:j+TcAB94Dfrjlu5kJt83h2OqAU+oyNUTwNZnQyII1sI=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY=

+ 6
- 4
test/til/lang.go

@ -42,12 +42,14 @@ var TypeNewBatchL1 common.TxType = "InstrTypeNewBatchL1"
var TypeNewBlock common.TxType = "InstrTypeNewBlock"
// TypeAddToken is used for testing purposes only, and represents the
// common.TxType of a new Token regsitration
// It has 'nolint:gosec' as the string 'Token' triggers gosec as a potential leaked Token (which is not the case)
// common.TxType of a new Token regsitration.
// It has 'nolint:gosec' as the string 'Token' triggers gosec as a potential
// leaked Token (which is not the case).
var TypeAddToken common.TxType = "InstrTypeAddToken" //nolint:gosec
// TxTypeCreateAccountDepositCoordinator is used for testing purposes only, and represents the
// common.TxType of a create acount deposit made by the coordinator
// TxTypeCreateAccountDepositCoordinator is used for testing purposes only,
// and represents the common.TxType of a create acount deposit made by the
// coordinator
var TxTypeCreateAccountDepositCoordinator common.TxType = "TypeCreateAccountDepositCoordinator"
//nolint

+ 12
- 10
test/til/txs.go

@ -57,7 +57,8 @@ type Context struct {
LastRegisteredTokenID common.TokenID
l1CreatedAccounts map[string]*Account // (Name, TokenID) -> *Account
// rollupConstMaxL1UserTx Maximum L1-user transactions allowed to be queued in a batch
// rollupConstMaxL1UserTx Maximum L1-user transactions allowed to be
// queued in a batch
rollupConstMaxL1UserTx int
idx int
@ -146,8 +147,8 @@ type L2Tx struct {
L2Tx common.L2Tx
}
// GenerateBlocks returns an array of BlockData for a given set made of a string. It uses the
// users (keys & nonces) of the Context.
// GenerateBlocks returns an array of BlockData for a given set made of a
// string. It uses the users (keys & nonces) of the Context.
func (tc *Context) GenerateBlocks(set string) ([]common.BlockData, error) {
parser := newParser(strings.NewReader(set))
parsedSet, err := parser.parse()
@ -164,8 +165,8 @@ func (tc *Context) GenerateBlocks(set string) ([]common.BlockData, error) {
return tc.generateBlocks()
}
// GenerateBlocksFromInstructions returns an array of BlockData for a given set made of instructions. It uses the
// users (keys & nonces) of the Context.
// GenerateBlocksFromInstructions returns an array of BlockData for a given set
// made of instructions. It uses the users (keys & nonces) of the Context.
func (tc *Context) GenerateBlocksFromInstructions(set []Instruction) ([]common.BlockData, error) {
userNames := []string{}
addedNames := make(map[string]bool)
@ -537,8 +538,8 @@ func (tc *Context) checkIfTokenIsRegistered(inst Instruction) error {
return nil
}
// GeneratePoolL2Txs returns an array of common.PoolL2Tx from a given set made of a string. It
// uses the users (keys) of the Context.
// GeneratePoolL2Txs returns an array of common.PoolL2Tx from a given set made
// of a string. It uses the users (keys) of the Context.
func (tc *Context) GeneratePoolL2Txs(set string) ([]common.PoolL2Tx, error) {
parser := newParser(strings.NewReader(set))
parsedSet, err := parser.parse()
@ -555,8 +556,8 @@ func (tc *Context) GeneratePoolL2Txs(set string) ([]common.PoolL2Tx, error) {
return tc.generatePoolL2Txs()
}
// GeneratePoolL2TxsFromInstructions returns an array of common.PoolL2Tx from a given set made of instructions. It
// uses the users (keys) of the Context.
// GeneratePoolL2TxsFromInstructions returns an array of common.PoolL2Tx from a
// given set made of instructions. It uses the users (keys) of the Context.
func (tc *Context) GeneratePoolL2TxsFromInstructions(set []Instruction) ([]common.PoolL2Tx, error) {
userNames := []string{}
addedNames := make(map[string]bool)
@ -775,7 +776,8 @@ func (tc *Context) FillBlocksForgedL1UserTxs(blocks []common.BlockData) error {
}
// FillBlocksExtra fills extra fields not generated by til in each block, so
// that the blockData is closer to what the HistoryDB stores. The filled fields are:
// that the blockData is closer to what the HistoryDB stores. The filled
// fields are:
// - blocks[].Rollup.Batch.EthBlockNum
// - blocks[].Rollup.Batch.ForgerAddr
// - blocks[].Rollup.Batch.ForgeL1TxsNum

Loading…
Cancel
Save