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