ZKInputs update:

- Add ZKInputs parser to JSON
- Update ProcessTxs to last go-merkletree version changes
- Add StateDB test to generate ZKInputs to check inside a circom circuit
- Small fix at Til CoordinatorTx.LoadAmount=0
This commit is contained in:
arnaucube
2020-11-04 13:04:17 +01:00
parent 11dbf67377
commit 7af6371f1d
7 changed files with 166 additions and 77 deletions

View File

@@ -87,7 +87,8 @@ func (s *StateDB) ProcessTxs(coordIdxs []common.Idx, l1usertxs, l1coordinatortxs
}
if s.typ == TypeBatchBuilder {
s.zki = common.NewZKInputs(nTx, 24, 32) // TODO this values will be parameters of the function, taken from config file/coordinator call
maxFeeTx := 2 // TODO this value will be a parameter
s.zki = common.NewZKInputs(nTx, maxFeeTx, s.mt.MaxLevels())
s.zki.OldLastIdx = (s.idx - 1).BigInt()
s.zki.OldStateRoot = s.mt.Root().BigInt()
}
@@ -202,7 +203,9 @@ func (s *StateDB) ProcessTxs(coordIdxs []common.Idx, l1usertxs, l1coordinatortxs
s.zki.Ay2[i] = exitAccount.PublicKey.Y
s.zki.Balance2[i] = exitAccount.Balance
s.zki.EthAddr2[i] = common.EthAddrToBigInt(exitAccount.EthAddr)
s.zki.Siblings2[i] = p.Siblings
for j := 0; j < len(p.Siblings); j++ {
s.zki.Siblings2[i][j] = p.Siblings[j].BigInt()
}
if exits[i].newExit {
s.zki.NewExit[i] = big.NewInt(1)
}

View File

@@ -352,25 +352,46 @@ func TestZKInputsGeneration(t *testing.T) {
require.Nil(t, err)
defer assert.Nil(t, os.RemoveAll(dir))
sdb, err := NewStateDB(dir, TypeBatchBuilder, 32)
sdb, err := NewStateDB(dir, TypeBatchBuilder, 4)
assert.Nil(t, err)
set := `
Type: Blockchain
AddToken(1)
CreateAccountDeposit(1) A: 10
> batchL1
CreateAccountCoordinator(1) B
CreateAccountCoordinator(1) C
> batchL1
// idxs: A:258, B:256, C:257
Transfer(1) A-B: 6 (1)
Transfer(1) A-C: 2 (1)
> batch
> block
`
// generate test transactions from test.SetBlockchain0 code
tc := til.NewContext(common.RollupConstMaxL1UserTx)
blocks, err := tc.GenerateBlocks(til.SetBlockchain0)
blocks, err := tc.GenerateBlocks(set)
require.Nil(t, err)
// Coordinator Idx where to send the fees
coordIdxs := []common.Idx{256, 257, 258, 259}
coordIdxs := []common.Idx{256}
log.Debug("block:0 batch:0, only L1CoordinatorTxs")
_, err = sdb.ProcessTxs(nil, nil, blocks[0].Rollup.Batches[0].L1CoordinatorTxs, nil)
log.Debug("block:0 batch:0, only L1UserTx")
_, err = sdb.ProcessTxs(nil, blocks[0].Rollup.L1UserTxs, nil, nil)
require.Nil(t, err)
l2Txs := common.L2TxsToPoolL2Txs(blocks[0].Rollup.Batches[1].L2Txs)
ptOut, err := sdb.ProcessTxs(coordIdxs, blocks[0].Rollup.L1UserTxs, blocks[0].Rollup.Batches[1].L1CoordinatorTxs, l2Txs)
log.Debug("block:0 batch:1, only L1CoordinatorTxs")
_, err = sdb.ProcessTxs(nil, nil, blocks[0].Rollup.Batches[1].L1CoordinatorTxs, nil)
require.Nil(t, err)
log.Debug("block:0 batch:2, only L2Txs")
l2Txs := common.L2TxsToPoolL2Txs(blocks[0].Rollup.Batches[2].L2Txs)
ptOut, err := sdb.ProcessTxs(coordIdxs, nil, nil, l2Txs)
require.Nil(t, err)
checkBalance(t, tc, sdb, "A", 1, "2")
s, err := json.Marshal(ptOut.ZKInputs)
require.Nil(t, err)
debug := false