Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

hash batch optimization #19

Open
krlosMata opened this issue Nov 16, 2020 · 0 comments
Open

hash batch optimization #19

krlosMata opened this issue Nov 16, 2020 · 0 comments

Comments

@krlosMata
Copy link
Contributor

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 stateRoot or exitRoot. For example in withdraw functions and further massive migrations implementations.

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 & hashTxData as parameters to compute hashBatch to be checked against the mapping
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant