arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
Merge pull request #500 from hermeznetwork/fix/exitnonces1

Fix exit tree nonces
arnau 17317030+arnaucube@users.noreply.github.com
Fri, 22 Jan 2021 10:10:32 +0100
commit

733ffb639993d5ef943d0aad080aa3d8808e5555

parent

3801d0bee6f26983e24a0a8dd9e23c94f317b914

2 files changed, 52 insertions(+), 1 deletions(-)

jump to
M txprocessor/txprocessor.go → txprocessor/txprocessor.go

@@ -1134,7 +1134,6 @@ return exitAccount, true, nil

} else if err != nil { return exitAccount, false, tracerr.Wrap(err) } - exitAccount.Nonce = exitAccount.Nonce + 1 // 1b. if idx already exist in exitTree: if tp.zki != nil {
M txprocessor/txprocessor_test.go → txprocessor/txprocessor_test.go

@@ -791,6 +791,9 @@ checkBalanceByIdx(t, tp.s, 259, "0") // Coord0

} func TestTwoExits(t *testing.T) { + // In the first part we generate a batch with two force exits for the + // same account of 20 each. The txprocessor output should be a single + // exitInfo with balance of 40. dir, err := ioutil.TempDir("", "tmpdb") require.NoError(t, err) defer assert.NoError(t, os.RemoveAll(dir))

@@ -852,4 +855,53 @@ assert.Equal(t, big.NewInt(40), ptOuts[3].ExitInfos[0].Balance)

acc, err := sdb.GetAccount(256) require.NoError(t, err) assert.Equal(t, big.NewInt(60), acc.Balance) + + // In the second part we start a fresh statedb and generate a batch + // with one force exit for the same account as before. The txprocessor + // output should be a single exitInfo with balance of 40, and the exit + // merkle tree proof should be equal to the previous one. + + dir2, err := ioutil.TempDir("", "tmpdb") + require.NoError(t, err) + defer assert.NoError(t, os.RemoveAll(dir2)) + + sdb2, err := statedb.NewStateDB(dir2, 128, statedb.TypeSynchronizer, 32) + assert.NoError(t, err) + + tc = til.NewContext(chainID, common.RollupConstMaxL1UserTx) + + // Single exit with balance of both exits in previous set. The exit + // root should match. + set2 := ` + Type: Blockchain + + CreateAccountDeposit(0) A: 100 + + > batchL1 // freeze L1User{1} + > batchL1 // forge L1User{1} + + ForceExit(0) A: 40 + + > batchL1 // freeze L1User{2} + > batchL1 // forge L1User{2} + > block + ` + blocks, err = tc.GenerateBlocks(set2) + require.NoError(t, err) + err = tc.FillBlocksExtra(blocks, &til.ConfigExtra{}) + require.NoError(t, err) + err = tc.FillBlocksForgedL1UserTxs(blocks) + require.NoError(t, err) + + tp = NewTxProcessor(sdb2, config) + ptOuts2 := []*ProcessTxOutput{} + for _, block := range blocks { + for _, batch := range block.Rollup.Batches { + ptOut, err := tp.ProcessTxs(nil, batch.L1UserTxs, nil, nil) + require.NoError(t, err) + ptOuts2 = append(ptOuts2, ptOut) + } + } + + assert.Equal(t, ptOuts[3].ExitInfos[0].MerkleProof, ptOuts2[3].ExitInfos[0].MerkleProof) }