Browse Source

Update to last Poseidon & go-merkletree versions

Update to last Poseidon (go-iden3-crypto) & go-merkletree versions,
update the affected test vectors, and check ZKInputs compatibility with
last version of circuits.

Update to last Poseidon version (which includes the changes of the
reference implementation from
26ddaa91db)

Compatible with update at circomlib
(cf853c1cc9)
tmp/txsel-fix
arnaucube 3 years ago
parent
commit
a39d880fd4
11 changed files with 118 additions and 119 deletions
  1. +5
    -5
      common/account_test.go
  2. +3
    -3
      common/pooll2tx_test.go
  3. +1
    -1
      coordinator/pipeline_test.go
  4. +1
    -1
      db/statedb/statedb_test.go
  5. +2
    -2
      go.mod
  6. +4
    -5
      go.sum
  7. +6
    -6
      synchronizer/synchronizer_test.go
  8. +1
    -1
      test/debugapi/debugapi_test.go
  9. +12
    -12
      test/zkproof/flows_test.go
  10. +12
    -12
      txprocessor/txprocessor_test.go
  11. +71
    -71
      txprocessor/zkinputsgen_test.go

+ 5
- 5
common/account_test.go

@ -216,7 +216,7 @@ func TestAccountHashValue(t *testing.T) {
v, err := account.HashValue()
assert.NoError(t, err)
assert.Equal(t,
"16297758255249203915951182296472515138555043617458222397753168518282206850764",
"447675324273474410516096114710387312413478475468606444107594732044698919451",
v.String())
}
@ -250,13 +250,13 @@ func TestAccountHashValueTestVectors(t *testing.T) {
h, err := poseidon.Hash(e[:])
assert.NoError(t, err)
assert.Equal(t,
"4550823210217540218403400309533329186487982452461145263910122718498735057257",
"13265203488631320682117942952393454767418777767637549409684833552016769103047",
h.String())
v, err := account.HashValue()
assert.NoError(t, err)
assert.Equal(t,
"4550823210217540218403400309533329186487982452461145263910122718498735057257",
"13265203488631320682117942952393454767418777767637549409684833552016769103047",
v.String())
// second account
@ -274,7 +274,7 @@ func TestAccountHashValueTestVectors(t *testing.T) {
v, err = account.HashValue()
assert.NoError(t, err)
assert.Equal(t,
"7750253361301235345986002241352365187241910378619330147114280396816709365657",
"2351654555892372227640888372176282444150254868378439619268573230312091195718",
v.String())
// third account
@ -300,7 +300,7 @@ func TestAccountHashValueTestVectors(t *testing.T) {
v, err = account.HashValue()
assert.NoError(t, err)
assert.Equal(t,
"10565754214047872850889045989683221123564392137456000481397520902594455245517",
"15036148928138382129196903417666258171042923749783835283230591475172197254845",
v.String())
}

+ 3
- 3
common/pooll2tx_test.go

@ -162,7 +162,7 @@ func TestHashToSign(t *testing.T) {
}
toSign, err := tx.HashToSign(chainID)
assert.NoError(t, err)
assert.Equal(t, "2d49ce1d4136e06f64e3eb1f79a346e6ee3e93ceeac909a57806a8d87005c263",
assert.Equal(t, "0b8abaf6b7933464e4450df2514da8b72606c02bf7f89bf6e54816fbda9d9d57",
hex.EncodeToString(toSign.Bytes()))
}
@ -185,7 +185,7 @@ func TestVerifyTxSignature(t *testing.T) {
toSign, err := tx.HashToSign(chainID)
assert.NoError(t, err)
assert.Equal(t,
"1571327027383224465388301747239444557034990637650927918405777653988509342917",
"3144939470626721092564692894890580265754250231349521601298746071096761507003",
toSign.String())
sig := sk.SignPoseidon(toSign)
@ -213,7 +213,7 @@ func TestVerifyTxSignatureEthAddrWith0(t *testing.T) {
sig := sk.SignPoseidon(toSign)
assert.Equal(t,
"93ce988ecac87908513648d0d021d8ad56d3b504eb38204200f07a8f6c20551de9951397d3051143d4c71203205f8849cd7382d2bcf4bd10092c1e052bb40d01",
"f208b8298d5f37148ac3c0c03703272ea47b9f836851bcf8dd5f7e4e3b336ca1d2f6e92ad85dc25f174daf7a0abfd5f71dead3f059b783f4c4b2f56a18a47000",
sig.Compress().String(),
)
tx.Signature = sig.Compress()

+ 1
- 1
coordinator/pipeline_test.go

@ -140,7 +140,7 @@ func preloadSync(t *testing.T, ethClient *test.Client, sync *synchronizer.Synchr
blocks[0].Rollup.Batches[0].Batch.StateRoot =
newBigInt("0")
blocks[0].Rollup.Batches[1].Batch.StateRoot =
newBigInt("10941365282189107056349764238909072001483688090878331371699519307087372995595")
newBigInt("6860514559199319426609623120853503165917774887908204288119245630904770452486")
ethAddTokens(blocks, ethClient)
err = ethClient.CtlAddBlocks(blocks)

+ 1
- 1
db/statedb/statedb_test.go

@ -535,7 +535,7 @@ func TestCheckAccountsTreeTestVectors(t *testing.T) {
}
// root value generated by js version:
assert.Equal(t,
"17298264051379321456969039521810887093935433569451713402227686942080129181291",
"13174362770971232417413036794215823584762073355951212910715422236001731746065",
sdb.MT.Root().BigInt().String())
}

+ 2
- 2
go.mod

@ -11,8 +11,8 @@ require (
github.com/gin-gonic/gin v1.5.0
github.com/gobuffalo/packr/v2 v2.8.1
github.com/hermeznetwork/tracerr v0.3.1-0.20210120162744-5da60b576169
github.com/iden3/go-iden3-crypto v0.0.6-0.20201221160344-58e589b6eb4c
github.com/iden3/go-merkletree v0.0.0-20210119155851-bb53e6ad1a12
github.com/iden3/go-iden3-crypto v0.0.6-0.20210308142348-8f85683b2cef
github.com/iden3/go-merkletree v0.0.0-20210308143313-8b63ca866189
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

+ 4
- 5
go.sum

@ -336,11 +336,10 @@ github.com/huin/goupnp v1.0.0 h1:wg75sLpL6DZqwHQN6E1Cfk6mtfzS45z8OV+ic+DtHRo=
github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc=
github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o=
github.com/hydrogen18/memlistener v0.0.0-20141126152155-54553eb933fb/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE=
github.com/iden3/go-iden3-crypto v0.0.6-0.20201218111145-a2015adb2f1b/go.mod h1:oBgthFLboAWi9feaBUFy7OxEcyn9vA1khHSL/WwWFyg=
github.com/iden3/go-iden3-crypto v0.0.6-0.20201221160344-58e589b6eb4c h1:D2u8FFYey6iFXLsqqJZ8R7ch8gZum+/b98whvoSDbyg=
github.com/iden3/go-iden3-crypto v0.0.6-0.20201221160344-58e589b6eb4c/go.mod h1:oBgthFLboAWi9feaBUFy7OxEcyn9vA1khHSL/WwWFyg=
github.com/iden3/go-merkletree v0.0.0-20210119155851-bb53e6ad1a12 h1:DXWT0BLCSm7cJmTMQy7+iOlxkA1/5ADglufhLK52e10=
github.com/iden3/go-merkletree v0.0.0-20210119155851-bb53e6ad1a12/go.mod h1:FdUFTW2qJiwHyy5R70uErwq7Kaq1uskyFdTfodcUJqA=
github.com/iden3/go-iden3-crypto v0.0.6-0.20210308142348-8f85683b2cef h1:72PG9b2eDlLqKszJVLrsoJbpt4CtgJLhKOjH1MJqCVY=
github.com/iden3/go-iden3-crypto v0.0.6-0.20210308142348-8f85683b2cef/go.mod h1:oBgthFLboAWi9feaBUFy7OxEcyn9vA1khHSL/WwWFyg=
github.com/iden3/go-merkletree v0.0.0-20210308143313-8b63ca866189 h1:hoarWk/SwNwnMXE0kiskcZULW0XBLQIUGYK4C39ozfs=
github.com/iden3/go-merkletree v0.0.0-20210308143313-8b63ca866189/go.mod h1:56abMeBKD4BIFe346rk+yuJ4MQgfMHe28sRx4o2gOpk=
github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA=
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
- 6
synchronizer/synchronizer_test.go

@ -446,9 +446,9 @@ func TestSyncGeneral(t *testing.T) {
require.Equal(t, 2, len(blocks[i].Rollup.Batches[0].L1CoordinatorTxs))
// Set StateRoots for batches manually (til doesn't set it)
blocks[i].Rollup.Batches[0].Batch.StateRoot =
newBigInt("18906357591508007884273218035694076596537737437965299189312069102730480717391")
newBigInt("11432094872416618651837327395264042968926668786266585816625577088890451620254")
blocks[i].Rollup.Batches[1].Batch.StateRoot =
newBigInt("9513185123401321669660637227182204000277156839501731093239187625486561933297")
newBigInt("16914212635847451457076355431350059348585556180740555407203882688922702410093")
// blocks 1 (blockNum=3)
i = 1
require.Equal(t, 3, int(blocks[i].Block.Num))
@ -457,9 +457,9 @@ func TestSyncGeneral(t *testing.T) {
require.Equal(t, 3, len(blocks[i].Rollup.Batches[0].L2Txs))
// Set StateRoots for batches manually (til doesn't set it)
blocks[i].Rollup.Batches[0].Batch.StateRoot =
newBigInt("13060270878200012606074130020925677466793317216609491464427188889005039616594")
newBigInt("13535760140937349829640752733057594576151546047374619177689224612061148090678")
blocks[i].Rollup.Batches[1].Batch.StateRoot =
newBigInt("21427104994652624302859637783375978708867165042357535792408500519060088086054")
newBigInt("19413739476363469870744893742469056615496274423228302914851564791727474664804")
// Generate extra required data
ethAddTokens(blocks, client)
@ -638,9 +638,9 @@ func TestSyncGeneral(t *testing.T) {
// Set StateRoots for batches manually (til doesn't set it)
blocks[0].Rollup.Batches[0].Batch.StateRoot =
newBigInt("11218510534825843475100588932060366395781087435899915642332104464234485046683")
newBigInt("14095767774967159269372103336737817266053275274769794195030162905513860477094")
blocks[0].Rollup.Batches[1].Batch.StateRoot =
newBigInt("20283020730369146334077598087403837297563965802277806438205710455191646998983")
newBigInt("2095674348545184674850951945506660952512376416769035169971006930847780339914")
for i := 0; i < 4; i++ {
client.CtlRollback()

+ 1
- 1
test/debugapi/debugapi_test.go

@ -85,7 +85,7 @@ func TestDebugAPI(t *testing.T) {
require.Nil(t, err)
// Testing against a hardcoded value obtained by running the test and
// printing the value previously.
assert.Equal(t, "21765339739823365993496282904432398015268846626944509989242908567129545640185",
assert.Equal(t, "5705124827515775272209811244650636195377535115082365089650934878384850534213",
mtroot.String())
var accountAPI common.Account

+ 12
- 12
test/zkproof/flows_test.go

@ -144,10 +144,10 @@ func TestTxSelectorBatchBuilderZKInputsMinimumFlow0(t *testing.T) {
// loop over the first 6 batches
expectedRoots := []string{"0", "0",
"13644148972047617726265275926674266298636745191961029124811988256139761111521",
"12433441613247342495680642890662773367605896324555599297255745922589338651261",
"12433441613247342495680642890662773367605896324555599297255745922589338651261",
"4191361650490017591061467288209836928064232431729236465872209988325272262963"}
"10303926118213025243660668481827257778714122989909761705455084995854999537039",
"8530501758307821623834726627056947648600328521261384179220598288701741436285",
"8530501758307821623834726627056947648600328521261384179220598288701741436285",
"9061858435528794221929846392270405504056106238451760714188625065949729889651"}
for i := 0; i < 6; i++ {
log.Debugf("block:0 batch:%d", i+1)
var l1UserTxs []common.L1Tx
@ -186,7 +186,7 @@ func TestTxSelectorBatchBuilderZKInputsMinimumFlow0(t *testing.T) {
zki, err := bb.BuildBatch(coordIdxs, configBatch, oL1UserTxs, oL1CoordTxs, oL2Txs)
require.NoError(t, err)
assert.Equal(t,
"7614010373759339299470010949167613050707822522530721724565424494781010548240",
"3844339393304253264418296322137281996442345663805792718218845145754742722151",
bb.LocalStateDB().MT.Root().BigInt().String())
sendProofAndCheckResp(t, zki)
err = l2DBTxSel.StartForging(common.TxIDsFromPoolL2Txs(oL2Txs),
@ -215,7 +215,7 @@ func TestTxSelectorBatchBuilderZKInputsMinimumFlow0(t *testing.T) {
zki, err = bb.BuildBatch(coordIdxs, configBatch, oL1UserTxs, oL1CoordTxs, oL2Txs)
require.NoError(t, err)
assert.Equal(t,
"21231789250434471575486264439945776732824482207853465397552873521865656677689",
"2537294203394018451170116789946369404362093672592091326351037700505720139801",
bb.LocalStateDB().MT.Root().BigInt().String())
sendProofAndCheckResp(t, zki)
err = l2DBTxSel.StartForging(common.TxIDsFromPoolL2Txs(l2Txs),
@ -242,7 +242,7 @@ func TestTxSelectorBatchBuilderZKInputsMinimumFlow0(t *testing.T) {
zki, err = bb.BuildBatch(coordIdxs, configBatch, oL1UserTxs, oL1CoordTxs, oL2Txs)
require.NoError(t, err)
assert.Equal(t,
"11289313644810782435120113035387729451095637380468777086895109386127538554246",
"13463929859122729344499006353544877221550995454069650137270994940730475267399",
bb.LocalStateDB().MT.Root().BigInt().String())
sendProofAndCheckResp(t, zki)
err = l2DBTxSel.StartForging(common.TxIDsFromPoolL2Txs(l2Txs),
@ -264,7 +264,7 @@ func TestTxSelectorBatchBuilderZKInputsMinimumFlow0(t *testing.T) {
// same root as previous batch, as the L1CoordinatorTxs created by the
// Til set is not created by the TxSelector in this test
assert.Equal(t,
"11289313644810782435120113035387729451095637380468777086895109386127538554246",
"13463929859122729344499006353544877221550995454069650137270994940730475267399",
bb.LocalStateDB().MT.Root().BigInt().String())
sendProofAndCheckResp(t, zki)
err = l2DBTxSel.StartForging(common.TxIDsFromPoolL2Txs(l2Txs),
@ -325,12 +325,12 @@ func TestZKInputsExitWithFee0(t *testing.T) {
zki, err := bb.BuildBatch(coordIdxs, configBatch, oL1UserTxs, oL1CoordTxs, oL2Txs)
require.NoError(t, err)
assert.Equal(t,
"8737171572459172806192626402462788826264011087579491137542380589998149683116",
"3050252508378236752695438107925920517579600844238792454632938959089837319058",
bb.LocalStateDB().MT.Root().BigInt().String())
h, err := zki.HashGlobalData()
require.NoError(t, err)
assert.Equal(t,
"18608843755023673022528019960628191162333429206359207449879743919826610006009",
"136173330006576039857485697813777018179965431269591881328654192642028135989",
h.String())
sendProofAndCheckResp(t, zki)
@ -353,12 +353,12 @@ func TestZKInputsExitWithFee0(t *testing.T) {
zki, err = bb.BuildBatch(coordIdxs, configBatch, oL1UserTxs, oL1CoordTxs, oL2Txs)
require.NoError(t, err)
assert.Equal(t,
"18306761925365215381387147754881756804475668085493847010988306480531520370130",
"2941150582529643425331223235752941075548157545257982041291886277157404095484",
bb.LocalStateDB().MT.Root().BigInt().String())
h, err = zki.HashGlobalData()
require.NoError(t, err)
assert.Equal(t,
"6651837443119278772088559395433504719862425648816904171510845286897104469889",
"11526955144859107275861838429358092025337347677758832533226842081116224550335",
h.String())
assert.Equal(t, common.EthAddrToBigInt(tc.Users["Coord"].Addr), zki.EthAddr3[0])
assert.Equal(t, "0", zki.EthAddr3[1].String())

+ 12
- 12
txprocessor/txprocessor_test.go

@ -251,7 +251,7 @@ func TestProcessTxsBalances(t *testing.T) {
require.NoError(t, err)
checkBalance(t, tc, sdb, "A", 0, "500")
assert.Equal(t,
"13644148972047617726265275926674266298636745191961029124811988256139761111521",
"10303926118213025243660668481827257778714122989909761705455084995854999537039",
tp.s.MT.Root().BigInt().String())
log.Debug("block:0 batch:4")
@ -262,7 +262,7 @@ func TestProcessTxsBalances(t *testing.T) {
checkBalance(t, tc, sdb, "A", 0, "500")
checkBalance(t, tc, sdb, "A", 1, "500")
assert.Equal(t,
"12433441613247342495680642890662773367605896324555599297255745922589338651261",
"8530501758307821623834726627056947648600328521261384179220598288701741436285",
tp.s.MT.Root().BigInt().String())
log.Debug("block:0 batch:5")
@ -273,7 +273,7 @@ func TestProcessTxsBalances(t *testing.T) {
checkBalance(t, tc, sdb, "A", 0, "500")
checkBalance(t, tc, sdb, "A", 1, "500")
assert.Equal(t,
"12433441613247342495680642890662773367605896324555599297255745922589338651261",
"8530501758307821623834726627056947648600328521261384179220598288701741436285",
tp.s.MT.Root().BigInt().String())
log.Debug("block:0 batch:6")
@ -285,7 +285,7 @@ func TestProcessTxsBalances(t *testing.T) {
checkBalance(t, tc, sdb, "A", 1, "500")
checkBalance(t, tc, sdb, "B", 0, "400")
assert.Equal(t,
"4191361650490017591061467288209836928064232431729236465872209988325272262963",
"9061858435528794221929846392270405504056106238451760714188625065949729889651",
tp.s.MT.Root().BigInt().String())
coordIdxs := []common.Idx{261, 262}
@ -303,7 +303,7 @@ func TestProcessTxsBalances(t *testing.T) {
checkBalance(t, tc, sdb, "C", 0, "100")
checkBalance(t, tc, sdb, "D", 0, "800")
assert.Equal(t,
"7614010373759339299470010949167613050707822522530721724565424494781010548240",
"3844339393304253264418296322137281996442345663805792718218845145754742722151",
tp.s.MT.Root().BigInt().String())
log.Debug("block:0 batch:8")
@ -321,7 +321,7 @@ func TestProcessTxsBalances(t *testing.T) {
checkBalance(t, tc, sdb, "C", 1, "100")
checkBalance(t, tc, sdb, "D", 0, "800")
assert.Equal(t,
"21231789250434471575486264439945776732824482207853465397552873521865656677689",
"2537294203394018451170116789946369404362093672592091326351037700505720139801",
tp.s.MT.Root().BigInt().String())
coordIdxs = []common.Idx{262}
@ -340,7 +340,7 @@ func TestProcessTxsBalances(t *testing.T) {
checkBalance(t, tc, sdb, "C", 1, "100")
checkBalance(t, tc, sdb, "D", 0, "470")
assert.Equal(t,
"11289313644810782435120113035387729451095637380468777086895109386127538554246",
"13463929859122729344499006353544877221550995454069650137270994940730475267399",
tp.s.MT.Root().BigInt().String())
coordIdxs = []common.Idx{}
@ -350,7 +350,7 @@ func TestProcessTxsBalances(t *testing.T) {
_, err = tp.ProcessTxs(coordIdxs, l1UserTxs, blocks[1].Rollup.Batches[1].L1CoordinatorTxs, l2Txs)
require.NoError(t, err)
assert.Equal(t,
"10342681351319338354912862547249967104198317571995055517008223832276478908482",
"21058792089669864857092637997959333050678445584244682889041632034478049099916",
tp.s.MT.Root().BigInt().String())
// use Set of PoolL2 txs
@ -597,7 +597,7 @@ func TestProcessTxsBatchBuilder(t *testing.T) {
assert.Equal(t, "2", acc.Balance.String())
assert.Equal(t,
"18894163991492573893706613133132363559300580460789469708968288074813925659539",
"18702154359941252155463263732782081721632595649781775986280568467618682348921",
sdb.MT.Root().BigInt().String())
}
@ -651,7 +651,7 @@ func TestProcessTxsRootTestVectors(t *testing.T) {
_, err = tp.ProcessTxs(nil, l1Txs, nil, l2Txs)
require.NoError(t, err)
assert.Equal(t,
"9827704113668630072730115158977131501210702363656902211840117643154933433410",
"16181420716631932805604732887923905079487577323947343079740042260791593140221",
sdb.MT.Root().BigInt().String())
}
@ -1077,7 +1077,7 @@ func TestExitOf0Amount(t *testing.T) {
ptOut, err := tp.ProcessTxs(nil, blocks[0].Rollup.Batches[3].L1UserTxs, nil, nil)
require.NoError(t, err)
assert.Equal(t,
"14329759303391468223438874789317921522067594445474390443816827472846339238908",
"17688031540912620894848983912708704736922099609001460827147265569563156468242",
ptOut.ZKInputs.Metadata.NewExitRootRaw.BigInt().String())
exitRootBatch4 := ptOut.ZKInputs.Metadata.NewExitRootRaw.BigInt().String()
@ -1085,7 +1085,7 @@ func TestExitOf0Amount(t *testing.T) {
ptOut, err = tp.ProcessTxs(nil, blocks[0].Rollup.Batches[5].L1UserTxs, nil, nil)
require.NoError(t, err)
assert.Equal(t,
"14329759303391468223438874789317921522067594445474390443816827472846339238908",
"17688031540912620894848983912708704736922099609001460827147265569563156468242",
ptOut.ZKInputs.Metadata.NewExitRootRaw.BigInt().String())
// Expect that the ExitRoot for the Batch6 will be equal than for the
// Batch4, as the Batch4 & Batch6 have the same tx with Exit Amount=10,

+ 71
- 71
txprocessor/zkinputsgen_test.go
File diff suppressed because it is too large
View File


Loading…
Cancel
Save