You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

575 lines
56 KiB

  1. package statedb
  2. import (
  3. "encoding/hex"
  4. "encoding/json"
  5. "fmt"
  6. "io/ioutil"
  7. "math/big"
  8. "os"
  9. "strconv"
  10. "testing"
  11. ethCommon "github.com/ethereum/go-ethereum/common"
  12. "github.com/hermeznetwork/hermez-node/common"
  13. "github.com/hermeznetwork/hermez-node/test/til"
  14. "github.com/iden3/go-iden3-crypto/babyjub"
  15. "github.com/stretchr/testify/assert"
  16. "github.com/stretchr/testify/require"
  17. )
  18. //nolint:deadcode,unused
  19. func printZKInputs(t *testing.T, zki *common.ZKInputs) {
  20. s, err := json.Marshal(zki)
  21. require.Nil(t, err)
  22. h, err := zki.HashGlobalData()
  23. require.Nil(t, err)
  24. fmt.Println("\nCopy&Paste into js circom test:\n let zkInput = JSON.parse(`" + string(s) + "`);")
  25. // fmt.Println("\nZKInputs json:\n echo '" + string(s) + "' | jq")
  26. fmt.Printf(`
  27. const output={
  28. hashGlobalInputs: "%s",
  29. };
  30. await circuit.assertOut(w, output);
  31. `, h.String())
  32. fmt.Println("")
  33. }
  34. func generateJsUsers(t *testing.T) []til.User {
  35. // same values than in the js test
  36. // skJsHex is equivalent to the 0000...000i js private key in commonjs
  37. skJsHex := []string{"7eb258e61862aae75c6c1d1f7efae5006ffc9e4d5596a6ff95f3df4ea209ea7f", "c005700f76f4b4cec710805c21595688648524df0a9d467afae537b7a7118819", "b373d14c67fb2a517bf4ac831c93341eec8e1b38dbc14e7d725b292a7cf84707", "2064b68d04a7aaae0ac3b36bf6f1850b380f1423be94a506c531940bd4a48b76"}
  38. addrHex := []string{"0x7e5f4552091a69125d5dfcb7b8c2659029395bdf", "0x2b5ad5c4795c026514f8317c7a215e218dccd6cf", "0x6813eb9362372eef6200f3b1dbc3f819671cba69", "0x1eff47bc3a10a45d4b230b5d10e37751fe6aa718"}
  39. var users []til.User
  40. for i := 0; i < len(skJsHex); i++ {
  41. skJs, err := hex.DecodeString(skJsHex[i])
  42. require.Nil(t, err)
  43. var sk babyjub.PrivateKey
  44. copy(sk[:], skJs)
  45. // bjj := sk.Public()
  46. user := til.User{
  47. Name: strconv.Itoa(i),
  48. BJJ: &sk,
  49. Addr: ethCommon.HexToAddress(addrHex[i]),
  50. }
  51. users = append(users, user)
  52. }
  53. assert.Equal(t, "d746824f7d0ac5044a573f51b278acb56d823bec39551d1d7bf7378b68a1b021", users[0].BJJ.Public().String())
  54. assert.Equal(t, "4d05c307400c65795f02db96b1b81c60386fd53e947d9d3f749f3d99b1853909", users[1].BJJ.Public().String())
  55. assert.Equal(t, "38ffa002724562eb2a952a2503e206248962406cf16392ff32759b6f2a41fe11", users[2].BJJ.Public().String())
  56. assert.Equal(t, "c719e6401190be7fa7fbfcd3448fe2755233c01575341a3b09edadf5454f760b", users[3].BJJ.Public().String())
  57. return users
  58. }
  59. func signL2Tx(t *testing.T, user til.User, l2Tx common.PoolL2Tx) common.PoolL2Tx {
  60. toSign, err := l2Tx.HashToSign()
  61. require.Nil(t, err)
  62. sig := user.BJJ.SignPoseidon(toSign)
  63. l2Tx.Signature = sig.Compress()
  64. return l2Tx
  65. }
  66. func TestZKInputsHashTestVector0(t *testing.T) {
  67. dir, err := ioutil.TempDir("", "tmpdb")
  68. require.Nil(t, err)
  69. defer assert.Nil(t, os.RemoveAll(dir))
  70. sdb, err := NewStateDB(dir, TypeBatchBuilder, 32)
  71. assert.Nil(t, err)
  72. // same values than in the js test
  73. users := generateJsUsers(t)
  74. l1Txs := []common.L1Tx{
  75. {
  76. FromIdx: 0,
  77. DepositAmount: big.NewInt(16000000),
  78. Amount: big.NewInt(0),
  79. TokenID: 1,
  80. FromBJJ: users[0].BJJ.Public(),
  81. FromEthAddr: users[0].Addr,
  82. ToIdx: 0,
  83. Type: common.TxTypeCreateAccountDeposit,
  84. UserOrigin: true,
  85. },
  86. }
  87. l2Txs := []common.PoolL2Tx{
  88. {
  89. FromIdx: 256,
  90. ToIdx: 256,
  91. TokenID: 1,
  92. Amount: big.NewInt(1000),
  93. Nonce: 0,
  94. Fee: 126,
  95. Type: common.TxTypeTransfer,
  96. },
  97. }
  98. ptc := ProcessTxsConfig{
  99. NLevels: 32,
  100. MaxFeeTx: 8,
  101. MaxTx: 32,
  102. MaxL1Tx: 16,
  103. }
  104. // skip first batch to do the test with BatchNum=1
  105. _, err = sdb.ProcessTxs(ptc, nil, nil, nil, nil)
  106. require.Nil(t, err)
  107. ptOut, err := sdb.ProcessTxs(ptc, nil, l1Txs, nil, l2Txs)
  108. require.Nil(t, err)
  109. // check expected account keys values from tx inputs
  110. acc, err := sdb.GetAccount(common.Idx(256))
  111. require.Nil(t, err)
  112. assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.PublicKey.Compress().String())
  113. assert.Equal(t, users[0].Addr.Hex(), acc.EthAddr.Hex())
  114. // check that there no exist more accounts
  115. _, err = sdb.GetAccount(common.Idx(257))
  116. require.NotNil(t, err)
  117. ptOut.ZKInputs.FeeIdxs[0] = common.Idx(256).BigInt()
  118. toHash, err := ptOut.ZKInputs.ToHashGlobalData()
  119. assert.Nil(t, err)
  120. // value from js test vector
  121. expectedToHash := "0000000000ff000000000100000000000000000000000000000000000000000000000000000000000000000015ba488d749f6b891d29d0bf3a72481ec812e4d4ecef2bf7a3fc64f3c010444200000000000000000000000000000000000000000000000000000000000000007e5f4552091a69125d5dfcb7b8c2659029395bdf21b0a1688b37f77b1d1d5539ec3b826db5ac78b2513f574a04c50a7d4f8246d700000000000028a00000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000010003e87e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000001"
  122. // checks are splitted to find the difference easier
  123. assert.Equal(t, expectedToHash[:1000], hex.EncodeToString(toHash)[:1000])
  124. assert.Equal(t, expectedToHash[1000:2000], hex.EncodeToString(toHash)[1000:2000])
  125. assert.Equal(t, expectedToHash[2000:], hex.EncodeToString(toHash)[2000:])
  126. h, err := ptOut.ZKInputs.HashGlobalData()
  127. require.Nil(t, err)
  128. // value from js test vector
  129. assert.Equal(t, "4356692423721763303547321618014315464040324829724049399065961225345730555597", h.String())
  130. }
  131. func TestZKInputsHashTestVector1(t *testing.T) {
  132. dir, err := ioutil.TempDir("", "tmpdb")
  133. require.Nil(t, err)
  134. defer assert.Nil(t, os.RemoveAll(dir))
  135. sdb, err := NewStateDB(dir, TypeBatchBuilder, 32)
  136. assert.Nil(t, err)
  137. // same values than in the js test
  138. users := generateJsUsers(t)
  139. // bjj0, err := common.BJJFromStringWithChecksum("21b0a1688b37f77b1d1d5539ec3b826db5ac78b2513f574a04c50a7d4f8246d7")
  140. // assert.Nil(t, err)
  141. // bjj1, err := common.BJJFromStringWithChecksum("093985b1993d9f743f9d7d943ed56f38601cb8b196db025f79650c4007c3054d")
  142. // assert.Nil(t, err)
  143. l1Txs := []common.L1Tx{
  144. {
  145. FromIdx: 0,
  146. DepositAmount: big.NewInt(16000000),
  147. Amount: big.NewInt(0),
  148. TokenID: 1,
  149. FromBJJ: users[0].BJJ.Public(),
  150. FromEthAddr: users[0].Addr,
  151. ToIdx: 0,
  152. Type: common.TxTypeCreateAccountDeposit,
  153. UserOrigin: true,
  154. },
  155. {
  156. FromIdx: 0,
  157. DepositAmount: big.NewInt(16000000),
  158. Amount: big.NewInt(0),
  159. TokenID: 1,
  160. FromBJJ: users[1].BJJ.Public(),
  161. FromEthAddr: users[1].Addr,
  162. ToIdx: 0,
  163. Type: common.TxTypeCreateAccountDeposit,
  164. UserOrigin: true,
  165. },
  166. }
  167. l2Txs := []common.PoolL2Tx{
  168. {
  169. FromIdx: 257,
  170. ToIdx: 256,
  171. TokenID: 1,
  172. Amount: big.NewInt(1000),
  173. Nonce: 0,
  174. Fee: 137,
  175. Type: common.TxTypeTransfer,
  176. },
  177. }
  178. ptc := ProcessTxsConfig{
  179. NLevels: 32,
  180. MaxFeeTx: 8,
  181. MaxTx: 32,
  182. MaxL1Tx: 16,
  183. }
  184. // skip first batch to do the test with BatchNum=1
  185. _, err = sdb.ProcessTxs(ptc, nil, nil, nil, nil)
  186. require.Nil(t, err)
  187. ptOut, err := sdb.ProcessTxs(ptc, nil, l1Txs, nil, l2Txs)
  188. require.Nil(t, err)
  189. // check expected account keys values from tx inputs
  190. acc, err := sdb.GetAccount(common.Idx(256))
  191. require.Nil(t, err)
  192. assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.PublicKey.Compress().String())
  193. assert.Equal(t, users[0].Addr.Hex(), acc.EthAddr.Hex())
  194. acc, err = sdb.GetAccount(common.Idx(257))
  195. require.Nil(t, err)
  196. assert.Equal(t, users[1].BJJ.Public().Compress().String(), acc.PublicKey.Compress().String())
  197. assert.Equal(t, users[1].Addr.Hex(), acc.EthAddr.Hex())
  198. // check that there no exist more accounts
  199. _, err = sdb.GetAccount(common.Idx(258))
  200. require.NotNil(t, err)
  201. ptOut.ZKInputs.FeeIdxs[0] = common.Idx(257).BigInt()
  202. toHash, err := ptOut.ZKInputs.ToHashGlobalData()
  203. assert.Nil(t, err)
  204. // value from js test vector
  205. expectedToHash := "0000000000ff0000000001010000000000000000000000000000000000000000000000000000000000000000304a3f3aef4f416cca887aab7265227449077627138345c2eb25bf8ff946b09500000000000000000000000000000000000000000000000000000000000000007e5f4552091a69125d5dfcb7b8c2659029395bdf21b0a1688b37f77b1d1d5539ec3b826db5ac78b2513f574a04c50a7d4f8246d700000000000028a00000000000010000000000002b5ad5c4795c026514f8317c7a215e218dccd6cf093985b1993d9f743f9d7d943ed56f38601cb8b196db025f79650c4007c3054d00000000000028a000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001010000010003e889000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010100000000000000000000000000000000000000000000000000000000000000000001"
  206. // checks are splitted to find the difference easier
  207. assert.Equal(t, expectedToHash[:1000], hex.EncodeToString(toHash)[:1000])
  208. assert.Equal(t, expectedToHash[1000:2000], hex.EncodeToString(toHash)[1000:2000])
  209. assert.Equal(t, expectedToHash[2000:], hex.EncodeToString(toHash)[2000:])
  210. h, err := ptOut.ZKInputs.HashGlobalData()
  211. require.Nil(t, err)
  212. // value from js test vector
  213. assert.Equal(t, "20293112365009290386650039345314592436395562810005523677125576447132206192598", h.String())
  214. }
  215. // TestZKInputs0:
  216. // - 1 L1Tx
  217. // - 1 L2Tx without fees
  218. // no Coordinator Idxs defined to receive the fees
  219. func TestZKInputs0(t *testing.T) {
  220. dir, err := ioutil.TempDir("", "tmpdb")
  221. require.Nil(t, err)
  222. defer assert.Nil(t, os.RemoveAll(dir))
  223. nLevels := 16
  224. sdb, err := NewStateDB(dir, TypeBatchBuilder, nLevels)
  225. assert.Nil(t, err)
  226. // same values than in the js test
  227. users := generateJsUsers(t)
  228. l1Txs := []common.L1Tx{
  229. {
  230. FromIdx: 0,
  231. DepositAmount: big.NewInt(16000000),
  232. Amount: big.NewInt(0),
  233. TokenID: 1,
  234. FromBJJ: users[0].BJJ.Public(),
  235. FromEthAddr: users[0].Addr,
  236. ToIdx: 0,
  237. Type: common.TxTypeCreateAccountDeposit,
  238. UserOrigin: true,
  239. },
  240. }
  241. l2Txs := []common.PoolL2Tx{
  242. {
  243. FromIdx: 256,
  244. ToIdx: 256,
  245. TokenID: 1,
  246. Amount: big.NewInt(1000),
  247. Nonce: 0,
  248. Fee: 0,
  249. Type: common.TxTypeTransfer,
  250. },
  251. }
  252. toSign, err := l2Txs[0].HashToSign()
  253. require.Nil(t, err)
  254. sig := users[0].BJJ.SignPoseidon(toSign)
  255. l2Txs[0].Signature = sig.Compress()
  256. ptc := ProcessTxsConfig{
  257. NLevels: uint32(nLevels),
  258. MaxTx: 3,
  259. MaxL1Tx: 2,
  260. MaxFeeTx: 2,
  261. }
  262. // skip first batch to do the test with BatchNum=1
  263. _, err = sdb.ProcessTxs(ptc, nil, nil, nil, nil)
  264. require.Nil(t, err)
  265. ptOut, err := sdb.ProcessTxs(ptc, nil, l1Txs, nil, l2Txs)
  266. require.Nil(t, err)
  267. // check expected account keys values from tx inputs
  268. acc, err := sdb.GetAccount(common.Idx(256))
  269. require.Nil(t, err)
  270. assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.PublicKey.Compress().String())
  271. assert.Equal(t, users[0].Addr.Hex(), acc.EthAddr.Hex())
  272. // check that there no exist more accounts
  273. _, err = sdb.GetAccount(common.Idx(257))
  274. require.NotNil(t, err)
  275. // printZKInputs(t, ptOut.ZKInputs)
  276. toHash, err := ptOut.ZKInputs.ToHashGlobalData()
  277. require.Nil(t, err)
  278. assert.Equal(t, "0000000000ff0000000001000000000000000000000000000000000000000000000000000000000000000000071a61ed5a1ac052b0d1086a330c540b55318a07f6b7989573b9bbbb5380d1a900000000000000000000000000000000000000000000000000000000000000007e5f4552091a69125d5dfcb7b8c2659029395bdf21b0a1688b37f77b1d1d5539ec3b826db5ac78b2513f574a04c50a7d4f8246d700000000000028a0000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100010003e8000000000000000000000000000000000001", hex.EncodeToString(toHash))
  279. h, err := ptOut.ZKInputs.HashGlobalData()
  280. require.Nil(t, err)
  281. assert.Equal(t, "10273997725311869157325593477103834352520120955255334791164183491223442653056", h.String())
  282. s, err := json.Marshal(ptOut.ZKInputs)
  283. require.Nil(t, err)
  284. // the 'expected' data has been checked with the circom circuits
  285. expected := `{"auxFromIdx":["256","0","0"],"auxToIdx":["0","0","0"],"ay1":["15238403086306505038849621710779816852318505119327426213168494964113886299863","15238403086306505038849621710779816852318505119327426213168494964113886299863","0"],"ay2":["0","15238403086306505038849621710779816852318505119327426213168494964113886299863","0"],"ay3":["0","0"],"balance1":["16000000","16000000","0"],"balance2":["0","15999000","0"],"balance3":["0","0"],"currentNumBatch":"1","ethAddr1":["721457446580647751014191829380889690493307935711","721457446580647751014191829380889690493307935711","0"],"ethAddr2":["0","721457446580647751014191829380889690493307935711","0"],"ethAddr3":["0","0"],"feeIdxs":["0","0"],"feePlanTokens":["0","0"],"fromBjjCompressed":[["1","1","1","0","1","0","1","1","0","1","1","0","0","0","1","0","0","1","0","0","0","0","0","1","1","1","1","1","0","0","1","0","1","0","1","1","1","1","1","0","0","1","0","1","0","0","0","0","1","0","1","0","0","0","1","1","0","0","1","0","0","0","0","0","0","1","0","1","0","0","1","0","1","1","1","0","1","0","1","0","1","1","1","1","1","1","0","0","1","0","0","0","1","0","1","0","0","1","0","0","1","1","0","1","0","0","0","1","1","1","1","0","0","0","1","1","0","1","0","1","1","0","1","0","1","1","0","1","1","0","1","1","0","1","1","0","0","1","0","0","0","0","0","1","1","1","0","1","1","1","0","0","0","0","1","1","0","1","1","1","1","0","0","1","1","1","0","0","1","0","1","0","1","0","1","0","1","0","1","1","1","0","0","0","1","0","1","1","1","0","0","0","1","1","0","1","1","1","1","0","1","1","1","0","1","1","1","1","1","1","1","0","1","1","0","0","1","1","0","1","0","0","0","1","0","0","0","1","0","1","1","0","1","0","0","0","0","1","0","1","0","0","0","0","1","1","0","1","1","0","0","0","0","1","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]],"fromEthAddr":["721457446580647751014191829380889690493307935711","0","0"],"fromIdx":["0","256","0"],"globalChainID":"0","imAccFeeOut":[["0","0"],["0","0"]],"imExitRoot":["0","0"],"imFinalAccFee":["0","0"],"imInitStateRootFee":"3212803832159212591526550848126062808026208063555125878245901046146545013161","imOnChain":["1","0"],"imOutIdx":["256","256"],"imStateRoot":["2999178063326948609414231200730958862089790119006655219527433501846141543551","3212803832159212591526550848126062808026208063555125878245901046146545013161"],"imStateRootFee":["3212803832159212591526550848126062808026208063555125878245901046146545013161"],"isOld0_1":["1","0","0"],"isOld0_2":["0","0","0"],"loadAmountF":["10400","0","0"],"maxNumBatch":["0","0","0"],"newAccount":["1","0","0"],"newExit":["0","0","0"],"nonce1":["0","0","0"],"nonce2":["0","1","0"],"nonce3":["0","0"],"oldKey1":["0","0","0"],"oldKey2":["0","0","0"],"oldLastIdx":"255","oldStateRoot":"0","oldValue1":["0","0","0"],"oldValue2":["0","0","0"],"onChain":["1","0","0"],"r8x":["0","13339118088097183560380359255316479838355724395928453439485234854234470298884","0"],"r8y":["0","12062876403986777372637801733000285846673058725183957648593976028822138986587","0"],"rqOffset":["0","0","0"],"rqToBjjAy":["0","0","0"],"rqToEthAddr":["0","0","0"],"rqTxCompressedDataV2":["0","0","0"],"s":["0","1429292460142966038093363510339656828866419125109324886747095533117015974779","0"],"siblings1":[["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]],"siblings2":[["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]],"siblings3":[["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]],"sign1":["0","0","0"],"sign2":["0","0","0"],"sign3":["0","0"],"toBjjAy":["0","0","0"],"toEthAddr":["0","0","0"],"toIdx":["0","256","0"],"tokenID1":["1","1","0"],"tokenID2":["0","1","0"],"tokenID3":["0","0"],"txCompressedData":["1461501637330902918203684832716283019659255211535","1483802382529433561627630154640673862706524841487","3322668559"],"txCompressedDataV2":["0","5271525021049092038181634317484288","0"]}`
  286. assert.Equal(t, expected, string(s))
  287. }
  288. // TestZKInputs1:
  289. // - 2 L1Tx of CreateAccountDeposit
  290. // - 1 L2Tx with fees
  291. func TestZKInputs1(t *testing.T) {
  292. dir, err := ioutil.TempDir("", "tmpdb")
  293. require.Nil(t, err)
  294. defer assert.Nil(t, os.RemoveAll(dir))
  295. nLevels := 16
  296. sdb, err := NewStateDB(dir, TypeBatchBuilder, nLevels)
  297. assert.Nil(t, err)
  298. // same values than in the js test
  299. users := generateJsUsers(t)
  300. l1Txs := []common.L1Tx{
  301. {
  302. FromIdx: 0,
  303. DepositAmount: big.NewInt(16000000),
  304. Amount: big.NewInt(0),
  305. TokenID: 1,
  306. FromBJJ: users[0].BJJ.Public(),
  307. FromEthAddr: users[0].Addr,
  308. ToIdx: 0,
  309. Type: common.TxTypeCreateAccountDeposit,
  310. UserOrigin: true,
  311. },
  312. {
  313. FromIdx: 0,
  314. DepositAmount: big.NewInt(16000000),
  315. Amount: big.NewInt(0),
  316. TokenID: 1,
  317. FromBJJ: users[1].BJJ.Public(),
  318. FromEthAddr: users[1].Addr,
  319. ToIdx: 0,
  320. Type: common.TxTypeCreateAccountDeposit,
  321. UserOrigin: true,
  322. },
  323. }
  324. l2Txs := []common.PoolL2Tx{
  325. {
  326. FromIdx: 256,
  327. ToIdx: 256,
  328. TokenID: 1,
  329. Amount: big.NewInt(1000),
  330. Nonce: 0,
  331. Fee: 126,
  332. Type: common.TxTypeTransfer,
  333. },
  334. }
  335. toSign, err := l2Txs[0].HashToSign()
  336. require.Nil(t, err)
  337. sig := users[0].BJJ.SignPoseidon(toSign)
  338. l2Txs[0].Signature = sig.Compress()
  339. ptc := ProcessTxsConfig{
  340. NLevels: uint32(nLevels),
  341. MaxTx: 3,
  342. MaxL1Tx: 2,
  343. MaxFeeTx: 2,
  344. }
  345. // skip first batch to do the test with BatchNum=1
  346. _, err = sdb.ProcessTxs(ptc, nil, nil, nil, nil)
  347. require.Nil(t, err)
  348. coordIdxs := []common.Idx{257}
  349. ptOut, err := sdb.ProcessTxs(ptc, coordIdxs, l1Txs, nil, l2Txs)
  350. require.Nil(t, err)
  351. // check expected account keys values from tx inputs
  352. acc, err := sdb.GetAccount(common.Idx(256))
  353. require.Nil(t, err)
  354. assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.PublicKey.Compress().String())
  355. assert.Equal(t, users[0].Addr.Hex(), acc.EthAddr.Hex())
  356. assert.Equal(t, "15999899", acc.Balance.String())
  357. acc, err = sdb.GetAccount(common.Idx(257))
  358. require.Nil(t, err)
  359. assert.Equal(t, users[1].BJJ.Public().Compress().String(), acc.PublicKey.Compress().String())
  360. assert.Equal(t, users[1].Addr.Hex(), acc.EthAddr.Hex())
  361. assert.Equal(t, "16000101", acc.Balance.String())
  362. // check that there no exist more accounts
  363. _, err = sdb.GetAccount(common.Idx(258))
  364. require.NotNil(t, err)
  365. // printZKInputs(t, ptOut.ZKInputs)
  366. toHash, err := ptOut.ZKInputs.ToHashGlobalData()
  367. require.Nil(t, err)
  368. assert.Equal(t, "0000000000ff0000000001010000000000000000000000000000000000000000000000000000000000000000036d607b790b93bb1768d5390803b5a4a1f77e46755f57900930b14454faf95c00000000000000000000000000000000000000000000000000000000000000007e5f4552091a69125d5dfcb7b8c2659029395bdf21b0a1688b37f77b1d1d5539ec3b826db5ac78b2513f574a04c50a7d4f8246d700000000000028a00000000000010000000000002b5ad5c4795c026514f8317c7a215e218dccd6cf093985b1993d9f743f9d7d943ed56f38601cb8b196db025f79650c4007c3054d00000000000028a000000000000100000000000000000000000000000000000000000100010003e87e01010000000000000001", hex.EncodeToString(toHash))
  369. h, err := ptOut.ZKInputs.HashGlobalData()
  370. require.Nil(t, err)
  371. assert.Equal(t, "11039366437749764484706691779656824178800407917434257418748834397596260744468", h.String())
  372. s, err := json.Marshal(ptOut.ZKInputs)
  373. require.Nil(t, err)
  374. // the 'expected' data has been checked with the circom circuits
  375. expected := `{"auxFromIdx":["256","257","0"],"auxToIdx":["0","0","0"],"ay1":["15238403086306505038849621710779816852318505119327426213168494964113886299863","4172448640254579435434214421479401747968866348490029667576411173067925161293","15238403086306505038849621710779816852318505119327426213168494964113886299863"],"ay2":["0","0","15238403086306505038849621710779816852318505119327426213168494964113886299863"],"ay3":["4172448640254579435434214421479401747968866348490029667576411173067925161293","0"],"balance1":["16000000","16000000","16000000"],"balance2":["0","0","15998899"],"balance3":["16000000","0"],"currentNumBatch":"1","ethAddr1":["721457446580647751014191829380889690493307935711","247512291986854564435551364600938690683113101007","721457446580647751014191829380889690493307935711"],"ethAddr2":["0","0","721457446580647751014191829380889690493307935711"],"ethAddr3":["247512291986854564435551364600938690683113101007","0"],"feeIdxs":["257","0"],"feePlanTokens":["1","0"],"fromBjjCompressed":[["1","1","1","0","1","0","1","1","0","1","1","0","0","0","1","0","0","1","0","0","0","0","0","1","1","1","1","1","0","0","1","0","1","0","1","1","1","1","1","0","0","1","0","1","0","0","0","0","1","0","1","0","0","0","1","1","0","0","1","0","0","0","0","0","0","1","0","1","0","0","1","0","1","1","1","0","1","0","1","0","1","1","1","1","1","1","0","0","1","0","0","0","1","0","1","0","0","1","0","0","1","1","0","1","0","0","0","1","1","1","1","0","0","0","1","1","0","1","0","1","1","0","1","0","1","1","0","1","1","0","1","1","0","1","1","0","0","1","0","0","0","0","0","1","1","1","0","1","1","1","0","0","0","0","1","1","0","1","1","1","1","0","0","1","1","1","0","0","1","0","1","0","1","0","1","0","1","0","1","1","1","0","0","0","1","0","1","1","1","0","0","0","1","1","0","1","1","1","1","0","1","1","1","0","1","1","1","1","1","1","1","0","1","1","0","0","1","1","0","1","0","0","0","1","0","0","0","1","0","1","1","0","1","0","0","0","0","1","0","1","0","0","0","0","1","1","0","1","1","0","0","0","0","1","0","0"],["1","0","1","1","0","0","1","0","1","0","1","0","0","0","0","0","1","1","0","0","0","0","1","1","1","1","1","0","0","0","0","0","0","0","0","0","0","0","1","0","0","0","1","1","0","0","0","0","1","0","1","0","0","1","1","0","1","0","0","1","1","1","1","0","1","1","1","1","1","0","1","0","0","1","0","0","0","0","0","0","1","1","0","1","1","0","1","1","0","1","1","0","1","0","0","1","1","0","0","0","1","1","0","1","0","0","0","1","1","1","0","1","0","0","1","1","1","0","0","0","0","0","0","0","0","1","1","0","0","0","0","1","1","1","0","0","1","1","1","1","0","1","1","0","1","0","1","0","1","0","1","1","0","1","1","1","1","1","0","0","0","0","1","0","1","0","0","1","1","0","1","1","1","1","1","0","1","0","1","1","1","0","0","1","1","1","1","1","1","1","0","0","0","0","1","0","1","1","1","0","1","1","1","1","1","0","0","1","1","0","1","1","1","1","0","0","1","0","0","1","1","0","0","1","1","0","0","0","1","1","0","1","1","0","1","0","0","0","0","1","1","0","0","1","1","1","0","0","1","0","0","1","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]],"fromEthAddr":["721457446580647751014191829380889690493307935711","247512291986854564435551364600938690683113101007","0"],"fromIdx":["0","0","256"],"globalChainID":"0","imAccFeeOut":[["0","0"],["0","0"]],"imExitRoot":["0","0"],"imFinalAccFee":["101","0"],"imInitStateRootFee":"10660728613879129016661596154319504485937170756181586060561759832613498905432","imOnChain":["1","1"],"imOutIdx":["256","257"],"imStateRoot":["2999178063326948609414231200730958862089790119006655219527433501846141543551","13160175861809095962915811919507877524206523306071085047160493107056995190544"],"imStateRootFee":["1550190772280924834409423240867892593473592863918771212295716656664630983004"],"isOld0_1":["1","0","0"],"isOld0_2":["0","0","0"],"loadAmountF":["10400","10400","0"],"maxNumBatch":["0","0","0"],"newAccount":["1","1","0"],"newExit":["0","0","0"],"nonce1":["0","0","0"],"nonce2":["0","0","1"],"nonce3":["0","0"],"oldKey1":["0","256","0"],"oldKey2":["0","0","0"],"oldLastIdx":"255","oldStateRoot":"0","oldValue1":["0","9733782510199048326382833205201407219982604211594942097825192094127807440165","0"],"oldValue2":["0","0","0"],"onChain":["1","1","0"],"r8x":["0","0","16795818329006817411605347777151783287113601795569690834743955502344582990059"],"r8y":["0","0","21153110871938011270027204820675751452345817312713349225139208384264949654114"],"rqOffset":["0","0","0"],"rqToBjjAy":["0","0","0"],"rqToEthAddr":["0","0","0"],"rqTxCompressedDataV2":["0","0","0"],"s":["0","0","1550352334297856444344240780544275542131334387040150478134835458055364079268"],"siblings1":[["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["6975841694765113541634698345295957238501610055097872059913911260522365532165","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]],"siblings2":[["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["6975841694765113541634698345295957238501610055097872059913911260522365532165","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]],"siblings3":[["9827704113668630072730115158977131501210702363656902211840117643154933433410","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]],"sign1":["0","0","0"],"sign2":["0","0","0"],"sign3":["0","0"],"toBjjAy":["0","0","0"],"toEthAddr":["0","0","0"],"toIdx":["0","0","256"],"tokenID1":["1","1","1"],"tokenID2":["0","0","1"],"tokenID3":["1","0"],"txCompressedData":["1461501637330902918203684832716283019659255211535","1461501637330902918203684832716283019659255211535","869620039695611037216780722449287736442401358123623346624340758723552783"],"txCompressedDataV2":["0","0","3089511010385631938450432878260044363267416251956459471104"]}`
  376. assert.Equal(t, expected, string(s))
  377. }
  378. // TestZKInputs2:
  379. // - 4 L1Tx of CreateAccountDeposit
  380. // - 2 L2Tx with fees
  381. func TestZKInputs2(t *testing.T) {
  382. dir, err := ioutil.TempDir("", "tmpdb")
  383. require.Nil(t, err)
  384. defer assert.Nil(t, os.RemoveAll(dir))
  385. nLevels := 16
  386. sdb, err := NewStateDB(dir, TypeBatchBuilder, nLevels)
  387. assert.Nil(t, err)
  388. // same values than in the js test
  389. users := generateJsUsers(t)
  390. l1Txs := []common.L1Tx{
  391. {
  392. FromIdx: 0,
  393. DepositAmount: big.NewInt(16000000),
  394. Amount: big.NewInt(0),
  395. TokenID: 1,
  396. FromBJJ: users[0].BJJ.Public(),
  397. FromEthAddr: users[0].Addr,
  398. ToIdx: 0,
  399. Type: common.TxTypeCreateAccountDeposit,
  400. UserOrigin: true,
  401. },
  402. {
  403. FromIdx: 0,
  404. DepositAmount: big.NewInt(16000000),
  405. Amount: big.NewInt(0),
  406. TokenID: 1,
  407. FromBJJ: users[1].BJJ.Public(),
  408. FromEthAddr: users[1].Addr,
  409. ToIdx: 0,
  410. Type: common.TxTypeCreateAccountDeposit,
  411. UserOrigin: true,
  412. },
  413. {
  414. FromIdx: 0,
  415. DepositAmount: big.NewInt(16000000),
  416. Amount: big.NewInt(0),
  417. TokenID: 1,
  418. FromBJJ: users[2].BJJ.Public(),
  419. FromEthAddr: users[2].Addr,
  420. ToIdx: 0,
  421. Type: common.TxTypeCreateAccountDeposit,
  422. UserOrigin: true,
  423. },
  424. {
  425. FromIdx: 0,
  426. DepositAmount: big.NewInt(16000000),
  427. Amount: big.NewInt(0),
  428. TokenID: 1,
  429. FromBJJ: users[3].BJJ.Public(),
  430. FromEthAddr: users[3].Addr,
  431. ToIdx: 0,
  432. Type: common.TxTypeCreateAccountDeposit,
  433. UserOrigin: true,
  434. },
  435. }
  436. l2Txs := []common.PoolL2Tx{
  437. {
  438. FromIdx: 256,
  439. ToIdx: 258,
  440. TokenID: 1,
  441. Amount: big.NewInt(1000),
  442. Nonce: 0,
  443. Fee: 126,
  444. Type: common.TxTypeTransfer,
  445. },
  446. {
  447. FromIdx: 256,
  448. ToIdx: 259,
  449. TokenID: 1,
  450. Amount: big.NewInt(1000),
  451. Nonce: 1,
  452. Fee: 126,
  453. Type: common.TxTypeTransfer,
  454. },
  455. }
  456. l2Txs[0] = signL2Tx(t, users[0], l2Txs[0])
  457. l2Txs[1] = signL2Tx(t, users[0], l2Txs[1])
  458. ptc := ProcessTxsConfig{
  459. NLevels: uint32(nLevels),
  460. MaxTx: 10,
  461. MaxL1Tx: 4,
  462. MaxFeeTx: 2,
  463. }
  464. // skip first batch to do the test with BatchNum=1
  465. _, err = sdb.ProcessTxs(ptc, nil, nil, nil, nil)
  466. require.Nil(t, err)
  467. coordIdxs := []common.Idx{257}
  468. ptOut, err := sdb.ProcessTxs(ptc, coordIdxs, l1Txs, nil, l2Txs)
  469. require.Nil(t, err)
  470. // check expected account keys values from tx inputs
  471. acc, err := sdb.GetAccount(common.Idx(256))
  472. require.Nil(t, err)
  473. assert.Equal(t, users[0].BJJ.Public().Compress().String(), acc.PublicKey.Compress().String())
  474. assert.Equal(t, users[0].Addr.Hex(), acc.EthAddr.Hex())
  475. assert.Equal(t, "15997798", acc.Balance.String())
  476. acc, err = sdb.GetAccount(common.Idx(257))
  477. require.Nil(t, err)
  478. assert.Equal(t, users[1].BJJ.Public().Compress().String(), acc.PublicKey.Compress().String())
  479. assert.Equal(t, users[1].Addr.Hex(), acc.EthAddr.Hex())
  480. assert.Equal(t, "16000202", acc.Balance.String())
  481. acc, err = sdb.GetAccount(common.Idx(258))
  482. require.Nil(t, err)
  483. assert.Equal(t, users[2].BJJ.Public().Compress().String(), acc.PublicKey.Compress().String())
  484. assert.Equal(t, users[2].Addr.Hex(), acc.EthAddr.Hex())
  485. assert.Equal(t, "16001000", acc.Balance.String())
  486. acc, err = sdb.GetAccount(common.Idx(259))
  487. require.Nil(t, err)
  488. assert.Equal(t, users[3].BJJ.Public().Compress().String(), acc.PublicKey.Compress().String())
  489. assert.Equal(t, users[3].Addr.Hex(), acc.EthAddr.Hex())
  490. assert.Equal(t, "16001000", acc.Balance.String())
  491. // check that there no exist more accounts
  492. _, err = sdb.GetAccount(common.Idx(260))
  493. require.NotNil(t, err)
  494. // printZKInputs(t, ptOut.ZKInputs)
  495. toHash, err := ptOut.ZKInputs.ToHashGlobalData()
  496. require.Nil(t, err)
  497. assert.Equal(t, "0000000000ff00000000010300000000000000000000000000000000000000000000000000000000000000000916786f85a645e04f50cb0304768196730037209eebf2625661f060a9b2496800000000000000000000000000000000000000000000000000000000000000007e5f4552091a69125d5dfcb7b8c2659029395bdf21b0a1688b37f77b1d1d5539ec3b826db5ac78b2513f574a04c50a7d4f8246d700000000000028a00000000000010000000000002b5ad5c4795c026514f8317c7a215e218dccd6cf093985b1993d9f743f9d7d943ed56f38601cb8b196db025f79650c4007c3054d00000000000028a00000000000010000000000006813eb9362372eef6200f3b1dbc3f819671cba6911fe412a6f9b7532ff9263f16c4062892406e203252a952aeb62457202a0ff3800000000000028a00000000000010000000000001eff47bc3a10a45d4b230b5d10e37751fe6aa7180b764f45f5aded093b1a347515c0335275e28f44d3fcfba77fbe901140e619c700000000000028a0000000000001000000000000000000000000000000000000000000000000000000000000000000000100010203e87e0100010303e87e0000000000000000000000000000000000000000000000000000000001010000000000000001", hex.EncodeToString(toHash))
  498. h, err := ptOut.ZKInputs.HashGlobalData()
  499. require.Nil(t, err)
  500. assert.Equal(t, "12526925720009671154604304301604163669184748177914925908444300255027382653822", h.String())
  501. s, err := json.Marshal(ptOut.ZKInputs)
  502. require.Nil(t, err)
  503. // the 'expected' data has been checked with the circom circuits
  504. expected := `{"auxFromIdx":["256","257","258","259","0","0","0","0","0","0"],"auxToIdx":["0","0","0","0","0","0","0","0","0","0"],"ay1":["15238403086306505038849621710779816852318505119327426213168494964113886299863","4172448640254579435434214421479401747968866348490029667576411173067925161293","8138547337953155637712635674046872799144091023272207542905444721067900862264","5184476412130556544090991668866402222418200486089222951317185404775371774407","15238403086306505038849621710779816852318505119327426213168494964113886299863","15238403086306505038849621710779816852318505119327426213168494964113886299863","0","0","0","0"],"ay2":["0","0","0","0","8138547337953155637712635674046872799144091023272207542905444721067900862264","5184476412130556544090991668866402222418200486089222951317185404775371774407","0","0","0","0"],"ay3":["4172448640254579435434214421479401747968866348490029667576411173067925161293","0"],"balance1":["16000000","16000000","16000000","16000000","16000000","15998899","0","0","0","0"],"balance2":["0","0","0","0","16000000","16000000","0","0","0","0"],"balance3":["16000000","0"],"currentNumBatch":"1","ethAddr1":["721457446580647751014191829380889690493307935711","247512291986854564435551364600938690683113101007","594179275863704165266696689399235767493667371625","176962662172908264953938498278848696642639144728","721457446580647751014191829380889690493307935711","721457446580647751014191829380889690493307935711","0","0","0","0"],"ethAddr2":["0","0","0","0","594179275863704165266696689399235767493667371625","176962662172908264953938498278848696642639144728","0","0","0","0"],"ethAddr3":["247512291986854564435551364600938690683113101007","0"],"feeIdxs":["257","0"],"feePlanTokens":["1","0"],"fromBjjCompressed":[["1","1","1","0","1","0","1","1","0","1","1","0","0","0","1","0","0","1","0","0","0","0","0","1","1","1","1","1","0","0","1","0","1","0","1","1","1","1","1","0","0","1","0","1","0","0","0","0","1","0","1","0","0","0","1","1","0","0","1","0","0","0","0","0","0","1","0","1","0","0","1","0","1","1","1","0","1","0","1","0","1","1","1","1","1","1","0","0","1","0","0","0","1","0","1","0","0","1","0","0","1","1","0","1","0","0","0","1","1","1","1","0","0","0","1","1","0","1","0","1","1","0","1","0","1","1","0","1","1","0","1","1","0","1","1","0","0","1","0","0","0","0","0","1","1","1","0","1","1","1","0","0","0","0","1","1","0","1","1","1","1","0","0","1","1","1","0","0","1","0","1","0","1","0","1","0","1","0","1","1","1","0","0","0","1","0","1","1","1","0","0","0","1","1","0","1","1","1","1","0","1","1","1","0","1","1","1","1","1","1","1","0","1","1","0","0","1","1","0","1","0","0","0","1","0","0","0","1","0","1","1","0","1","0","0","0","0","1","0","1","0","0","0","0","1","1","0","1","1","0","0","0","0","1","0","0"],["1","0","1","1","0","0","1","0","1","0","1","0","0","0","0","0","1","1","0","0","0","0","1","1","1","1","1","0","0","0","0","0","0","0","0","0","0","0","1","0","0","0","1","1","0","0","0","0","1","0","1","0","0","1","1","0","1","0","0","1","1","1","1","0","1","1","1","1","1","0","1","0","0","1","0","0","0","0","0","0","1","1","0","1","1","0","1","1","0","1","1","0","1","0","0","1","1","0","0","0","1","1","0","1","0","0","0","1","1","1","0","1","0","0","1","1","1","0","0","0","0","0","0","0","0","1","1","0","0","0","0","1","1","1","0","0","1","1","1","1","0","1","1","0","1","0","1","0","1","0","1","1","0","1","1","1","1","1","0","0","0","0","1","0","1","0","0","1","1","0","1","1","1","1","1","0","1","0","1","1","1","0","0","1","1","1","1","1","1","1","0","0","0","0","1","0","1","1","1","0","1","1","1","1","1","0","0","1","1","0","1","1","1","1","0","0","1","0","0","1","1","0","0","1","1","0","0","0","1","1","0","1","1","0","1","0","0","0","0","1","1","0","0","1","1","1","0","0","1","0","0","1","0","0","0","0"],["0","0","0","1","1","1","0","0","1","1","1","1","1","1","1","1","0","0","0","0","0","1","0","1","0","1","0","0","0","0","0","0","0","1","0","0","1","1","1","0","1","0","1","0","0","0","1","0","0","1","0","0","0","1","1","0","1","1","0","1","0","1","1","1","0","1","0","1","0","1","0","0","1","0","1","0","1","0","0","1","0","1","0","1","0","1","0","0","1","0","1","0","0","1","0","0","1","1","0","0","0","0","0","0","0","1","0","0","0","1","1","1","0","1","1","0","0","0","0","0","0","0","1","0","0","1","0","0","1","0","0","1","0","0","0","1","0","1","0","0","0","1","1","0","0","0","0","0","0","0","1","0","0","0","1","1","0","1","1","0","1","0","0","0","1","1","1","1","1","1","0","0","0","1","1","0","0","1","0","0","1","0","0","1","1","1","1","1","1","1","1","1","0","1","0","0","1","1","0","0","1","0","1","0","1","1","1","0","1","1","0","1","1","0","0","1","1","1","1","1","0","1","1","0","0","1","0","1","0","1","0","0","1","0","0","0","0","0","1","0","0","1","1","1","1","1","1","1","1","0","0","0","1","0","0","0"],["1","1","1","0","0","0","1","1","1","0","0","1","1","0","0","0","0","1","1","0","0","1","1","1","0","0","0","0","0","0","1","0","1","0","0","0","1","0","0","0","0","0","0","0","1","0","0","1","0","1","1","1","1","1","0","1","1","1","1","1","1","1","1","0","1","1","1","0","0","1","0","1","1","1","0","1","1","1","1","1","0","0","1","1","1","1","1","1","1","1","0","0","1","0","1","1","0","0","1","0","0","0","1","0","1","1","1","1","0","0","0","1","0","1","0","0","0","1","1","1","1","0","1","0","1","1","1","0","0","1","0","0","1","0","1","0","1","1","0","0","1","1","0","0","0","0","0","0","0","0","1","1","1","0","1","0","1","0","0","0","1","0","1","0","1","1","1","0","0","0","1","0","1","1","0","0","0","1","0","1","1","0","0","0","1","1","0","1","1","1","0","0","1","0","0","1","0","0","0","0","1","0","1","1","0","1","1","1","1","0","1","1","0","1","0","1","1","0","1","0","1","1","1","1","1","0","1","0","0","0","1","0","1","1","1","1","0","0","1","0","0","1","1","0","1","1","1","0","1","1","0","1","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]],"fromEthAddr":["721457446580647751014191829380889690493307935711","247512291986854564435551364600938690683113101007","594179275863704165266696689399235767493667371625","176962662172908264953938498278848696642639144728","0","0","0","0","0","0"],"fromIdx":["0","0","0","0","256","256","0","0","0","0"],"globalChainID":"0","imAccFeeOut":[["0","0"],["0","0"],["0","0"],["0","0"],["101","0"],["202","0"],["202","0"],["202","0"],["202","0"]],"imExitRoot":["0","0","0","0","0","0","0","0","0"],"imFinalAccFee":["202","0"],"imInitStateRootFee":"11102416505971276127293972570397361714598994868311229974249826487060684688197","imOnChain":["1","1","1","1","0","0","0","0","0"],"imOutIdx":["256","257","258","259","259","259","259","259","259"],"imStateRoot":["2999178063326948609414231200730958862089790119006655219527433501846141543551","13160175861809095962915811919507877524206523306071085047160493107056995190544","6981081575125964439064848745251852976562872673661163359815312764236115200222","12287200745694319621025881114682538954756900570406181328753188227270350941803","10250910571353243150359059549936965649098556707015028714542118863411160731635","11102416505971276127293972570397361714598994868311229974249826487060684688197","11102416505971276127293972570397361714598994868311229974249826487060684688197","11102416505971276127293972570397361714598994868311229974249826487060684688197","11102416505971276127293972570397361714598994868311229974249826487060684688197"],"imStateRootFee":["4110517488865152389773850641074094192962655219669746287253968903130252986728"],"isOld0_1":["1","0","0","0","0","0","0","0","0","0"],"isOld0_2":["0","0","0","0","0","0","0","0","0","0"],"loadAmountF":["10400","10400","10400","10400","0","0","0","0","0","0"],"maxNumBatch":["0","0","0","0","0","0","0","0","0","0"],"newAccount":["1","1","1","1","0","0","0","0","0","0"],"newExit":["0","0","0","0","0","0","0","0","0","0"],"nonce1":["0","0","0","0","0","1","0","0","0","0"],"nonce2":["0","0","0","0","0","0","0","0","0","0"],"nonce3":["0","0"],"oldKey1":["0","256","256","257","0","0","0","0","0","0"],"oldKey2":["0","0","0","0","0","0","0","0","0","0"],"oldLastIdx":"255","oldStateRoot":"0","oldValue1":["0","9733782510199048326382833205201407219982604211594942097825192094127807440165","9733782510199048326382833205201407219982604211594942097825192094127807440165","17760137544353091380819593442189011627672167337464348873007461140156851422987","0","0","0","0","0","0"],"oldValue2":["0","0","0","0","0","0","0","0","0","0"],"onChain":["1","1","1","1","0","0","0","0","0","0"],"r8x":["0","0","0","0","5214090684236684851573641059575591118676476987573336170365486786637312665141","17818752874555175254292826108469784891786151976165952117435881323396526148981","0","0","0","0"],"r8y":["0","0","0","0","3568441662719387930655444674281943536423464418783443425289988425360036364264","7870851773538784486620881929410103548804126936780372631545590676485414360508","0","0","0","0"],"rqOffset":["0","0","0","0","0","0","0","0","0","0"],"rqToBjjAy":["0","0","0","0","0","0","0","0","0","0"],"rqToEthAddr":["0","0","0","0","0","0","0","0","0","0"],"rqTxCompressedDataV2":["0","0","0","0","0","0","0","0","0","0"],"s":["0","0","0","0","974535875596637445705358386750029200510091659451458393452031111972389260285","383599574514235269420771702006588662767158113271594446015439990815783784544","0","0","0","0"],"siblings1":[["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["6975841694765113541634698345295957238501610055097872059913911260522365532165","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["16340650608214686026509819657637793341613276710241727968165631912246770201551","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["20096881635736058727699182872953735227378445790497970658442161994753383780529","16179075207476077480163273158757030768504935550886919319708484674028389406807","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["20096881635736058727699182872953735227378445790497970658442161994753383780529","9666104145689704191764010810632978949926547298995332970899083004213180315751","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]],"siblings2":[["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["20096881635736058727699182872953735227378445790497970658442161994753383780529","18206494837933532633746175540777421367331523385545468990813257189787137445167","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["9141974547200611535034738074275487715083927494193481815706633586422651686652","6975841694765113541634698345295957238501610055097872059913911260522365532165","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]],"siblings3":[["9141974547200611535034738074275487715083927494193481815706633586422651686652","3300045819699360541652863975392028819717279937342922306336031453914844695187","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]],"sign1":["0","0","0","0","0","0","0","0","0","0"],"sign2":["0","0","0","0","0","0","0","0","0","0"],"sign3":["0","0"],"toBjjAy":["0","0","0","0","0","0","0","0","0","0"],"toEthAddr":["0","0","0","0","0","0","0","0","0","0"],"toIdx":["0","0","0","0","258","259","0","0","0","0"],"tokenID1":["1","1","1","1","1","1","0","0","0","0"],"tokenID2":["0","0","0","0","1","1","0","0","0","0"],"tokenID3":["1","0"],"txCompressedData":["1461501637330902918203684832716283019659255211535","1461501637330902918203684832716283019659255211535","1461501637330902918203684832716283019659255211535","1461501637330902918203684832716283019659255211535","869620039695611037216780722449287736442401516579948375153015945811453455","869620039695617314318516109130051572231824803474526991772798003389916687","3322668559","3322668559","3322668559","3322668559"],"txCompressedDataV2":["0","0","0","0","3089511010385631938450432878260044363267416814906412892416","3089511010385654239195631408883185898985689744742895583488","0","0","0","0"]}`
  505. assert.Equal(t, expected, string(s))
  506. }