This repository was archived by the owner on Nov 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
This repository was archived by the owner on Nov 20, 2024. It is now read-only.
hash batch optimization #19
Copy link
Copy link
Open
Labels
Milestone
Description
Hash batch
Perform a hash of all possible state batch variables into a single value hashBatch. This will allow to save data on-chain and reduces the gas cost of the forgeBatch function.
The trade-off is that the entire bash state has to be submitted to the forgeBatch function call.
Note that this apply every time that anydata has to be checked against
stateRootorexitRoot. For example inwithdrawfunctions and furthermassive migrationsimplementations.
Specifciation
- Reminder
txData: All data availability
txData: [ NLevels bits ] fromIdx
[ NLevels bits ] toIdx
[ 16 bits ] amountF * (1 - nullifyAmount)
[ 8 bits ] fee
// nullifyAmount = 0 for L2 transactions
txsData = txData[0] || txData[MAX_TXS - 1]
hashTxData = SHA256(txsData)
- batch hash:
dataBatch: [ uint256 ] stateRoot
[ uint256 ] exitRoot
[ uint256 ] hashTxData
hashBatch = SHA256(dataBatch)
- Contract
- new mapping:
// store hashBatch for each batch number mapping(uint32 => uint256) public hashBatchMap;- new forgeBatch call:
- function forgeBatch( uint256 lastStateRoot, // needed to check against mapping hashBatchMap uint256 lastExitRoot, // needed to check against mapping hashBatchMap uint256 lastHashTxData, // needed to check against mapping hashBatchMap uint48 newLastIdx, uint256 newStRoot, uint256 newExitRoot, bytes calldata encodedL1CoordinatorTx, bytes calldata l2TxsData, bytes calldata feeIdxCoordinator, uint8 verifierIdx, bool l1Batch, uint256[2] calldata proofA, uint256[2][2] calldata proofB, uint256[2] calldata proofC ) external virtual - new
withrdawalMerkleProof&withrdawalCircuit- adds
stateRoot,exitRoot&hashTxDataas parameters to computehashBatchto be checked against the mapping
- adds
Reactions are currently unavailable