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.

146 lines
6.2 KiB

  1. // Package common contains all the common data structures used at the
  2. // hermez-node, zk.go contains the zkSnark inputs used to generate the proof
  3. //nolint:deadcode,structcheck, unused
  4. package common
  5. import "math/big"
  6. // circuit parameters
  7. // absolute maximum of L1 or L2 transactions allowed
  8. type nTx uint32
  9. // merkle tree depth
  10. type nLevels uint32
  11. // absolute maximum of L1 transaction allowed
  12. type maxL1Tx uint32
  13. //absolute maximum of fee transactions allowed
  14. type maxFeeTx uint32
  15. // ZKInputs represents the inputs that will be used to generate the zkSNARK proof
  16. type ZKInputs struct {
  17. // inputs for final `hashGlobalInputs`
  18. // oldLastIdx is the last index assigned to an account
  19. oldLastIdx *big.Int // uint64 (max nLevels bits)
  20. // oldStateRoot is the current state merkle tree root
  21. oldStateRoot *big.Int // Hash
  22. // globalChainID is the blockchain ID (0 for Ethereum mainnet). This value can be get from the smart contract.
  23. globalChainID *big.Int // uint16
  24. // feeIdxs is an array of merkle tree indexes where the coordinator will receive the accumulated fees
  25. feeIdxs []*big.Int // uint64 (max nLevels bits), len: [maxFeeTx]
  26. // accumulate fees
  27. // feePlanTokens contains all the tokenIDs for which the fees are being accumulated
  28. feePlanTokens []*big.Int // uint32 (max 32 bits), len: [maxFeeTx]
  29. // Intermediary States to parallelize witness computation
  30. // decode-tx
  31. // imOnChain indicates if tx is L1 (true) or L2 (false)
  32. imOnChain []*big.Int // bool, len: [nTx - 1]
  33. // imOutIdx current index account for each Tx
  34. imOutIdx []*big.Int // uint64 (max nLevels bits), len: [nTx - 1]
  35. // rollup-tx
  36. // imStateRoot root at the moment of the Tx, the state root value once the Tx is processed into the state tree
  37. imStateRoot []*big.Int // Hash, len: [nTx - 1]
  38. // imExitTree root at the moment of the Tx the value once the Tx is processed into the exit tree
  39. imExitRoot []*big.Int // Hash, len: [nTx - 1]
  40. // imAccFeeOut accumulated fees once the Tx is processed
  41. imAccFeeOut [][]*big.Int // big.Int, len: [nTx - 1][maxFeeTx]
  42. // fee-tx
  43. // imStateRootFee root at the moment of the Tx, the state root value once the Tx is processed into the state tree
  44. imStateRootFee []*big.Int // Hash, len: [maxFeeTx - 1]
  45. // imInitStateRootFee state root once all L1-L2 tx are processed (before computing the fees-tx)
  46. imInitStateRootFee *big.Int // Hash
  47. // imFinalAccFee final accumulated fees (before computing the fees-tx)
  48. imFinalAccFee []*big.Int // big.Int, len: [maxFeeTx - 1]
  49. // transaction L1-L2
  50. // txCompressedData
  51. txCompressedData []*big.Int // big.Int (max 251 bits), len: [nTx]
  52. // txCompressedDataV2
  53. txCompressedDataV2 []*big.Int // big.Int (max 193 bits), len: [nTx]
  54. // fromIdx
  55. fromIdx []*big.Int // uint64 (max nLevels bits), len: [nTx]
  56. // auxFromIdx is the Idx of the new created account which is consequence of a L1CreateAccountTx
  57. auxFromIdx []*big.Int // uint64 (max nLevels bits), len: [nTx]
  58. // toIdx
  59. toIdx []*big.Int // uint64 (max nLevels bits), len: [nTx]
  60. // 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'
  61. auxToIdx []*big.Int // uint64 (max nLevels bits), len: [nTx]
  62. // toBjjAy
  63. toBjjAy []*big.Int // big.Int, len: [nTx]
  64. // toEthAddr
  65. toEthAddr []*big.Int // ethCommon.Address, len: [nTx]
  66. // onChain determines if is L1 (1/true) or L2 (0/false)
  67. onChain []*big.Int // bool, len: [nTx]
  68. // newAccount boolean (0/1) flag to set L1 tx creates a new account
  69. newAccount []*big.Int // bool, len: [nTx]
  70. // rqOffset relative transaction position to be linked. Used to perform atomic transactions.
  71. rqOffset []*big.Int // uint8 (max 3 bits), len: [nTx]
  72. // transaction L2 request data
  73. // rqTxCompressedDataV2
  74. rqTxCompressedDataV2 []*big.Int // big.Int (max 251 bits), len: [nTx]
  75. // rqToEthAddr
  76. rqToEthAddr []*big.Int // ethCommon.Address, len: [nTx]
  77. // rqToBjjAy
  78. rqToBjjAy []*big.Int // big.Int, len: [nTx]
  79. // transaction L2 signature
  80. // s
  81. s []*big.Int // big.Int, len: [nTx]
  82. // r8x
  83. r8x []*big.Int // big.Int, len: [nTx]
  84. // r8y
  85. r8y []*big.Int // big.Int, len: [nTx]
  86. // transaction L1
  87. // loadAmountF encoded as float16
  88. loadAmountF []*big.Int // uint16, len: [nTx]
  89. // fromEthAddr
  90. fromEthAddr []*big.Int // ethCommon.Address, len: [nTx]
  91. // fromBjjCompressed boolean encoded where each value is a *big.Int
  92. fromBjjCompressed [][]*big.Int // bool array, len: [nTx][256]
  93. // state 1, value of the sender (from) account leaf
  94. tokenID1 []*big.Int // uint32, len: [nTx]
  95. nonce1 []*big.Int // uint64 (max 40 bits), len: [nTx]
  96. sign1 []*big.Int // bool, len: [nTx]
  97. balance1 []*big.Int // big.Int (max 192 bits), len: [nTx]
  98. ay1 []*big.Int // big.Int, len: [nTx]
  99. ethAddr1 []*big.Int // ethCommon.Address, len: [nTx]
  100. siblings1 [][]*big.Int // big.Int, len: [nTx][nLevels + 1]
  101. // Required for inserts and deletes, values of the CircomProcessorProof (smt insert proof)
  102. isOld0_1 []*big.Int // bool, len: [nTx]
  103. oldKey1 []*big.Int // uint64 (max 40 bits), len: [nTx]
  104. oldValue1 []*big.Int // Hash, len: [nTx]
  105. // state 2, value of the receiver (to) account leaf
  106. tokenID2 []*big.Int // uint32, len: [nTx]
  107. nonce2 []*big.Int // uint64 (max 40 bits), len: [nTx]
  108. sign2 []*big.Int // bool, len: [nTx]
  109. balance2 []*big.Int // big.Int (max 192 bits), len: [nTx]
  110. ay2 []*big.Int // big.Int, len: [nTx]
  111. ethAddr2 []*big.Int // ethCommon.Address, len: [nTx]
  112. siblings2 [][]*big.Int // big.Int, len: [nTx][nLevels + 1]
  113. // newExit determines if an exit transaction has to create a new leaf in the exit tree
  114. newExit []*big.Int // bool, len: [nTx]
  115. // Required for inserts and deletes, values of the CircomProcessorProof (smt insert proof)
  116. isOld0_2 []*big.Int // bool, len: [nTx]
  117. oldKey2 []*big.Int // uint64 (max 40 bits), len: [nTx]
  118. oldValue2 []*big.Int // Hash, len: [nTx]
  119. // state 3, value of the account leaf receiver of the Fees
  120. // fee tx
  121. // State fees
  122. tokenID3 []*big.Int // uint32, len: [maxFeeTx]
  123. nonce3 []*big.Int // uint64 (max 40 bits), len: [maxFeeTx]
  124. sign3 []*big.Int // bool, len: [maxFeeTx]
  125. balance3 []*big.Int // big.Int (max 192 bits), len: [maxFeeTx]
  126. ay3 []*big.Int // big.Int, len: [maxFeeTx]
  127. ethAddr3 []*big.Int // ethCommon.Address, len: [maxFeeTx]
  128. siblings3 [][]*big.Int // Hash, len: [maxFeeTx][nLevels + 1]
  129. }