From ac428bda8594c738b378740c436fbe17dd1f0da1 Mon Sep 17 00:00:00 2001 From: Ignasi Date: Tue, 30 Apr 2024 17:36:32 +0200 Subject: [PATCH] Add coinbase at changeL2Block --- main/block-info.zkasm | 2 +- main/constants.zkasm | 2 ++ main/load-change-l2-block.zkasm | 6 ++++++ main/main.zkasm | 6 +----- main/process-change-l2-block.zkasm | 2 ++ main/vars.zkasm | 2 +- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/main/block-info.zkasm b/main/block-info.zkasm index 4fa3e22a..85bbeed1 100644 --- a/main/block-info.zkasm +++ b/main/block-info.zkasm @@ -44,7 +44,7 @@ setupNewBlockInfoTree: %INDEX_BLOCK_HEADER_PARAM_COINBASE => A %SMT_KEY_BLOCK_HEADER_PARAM => B 0 => C - $ => D :MLOAD(sequencerAddr) + $ => D :MLOAD(sequencerAddr) ; is 0 if forced batch $ => SR :SSTORE ; Insert block number diff --git a/main/constants.zkasm b/main/constants.zkasm index 86a1ae9b..911d3587 100644 --- a/main/constants.zkasm +++ b/main/constants.zkasm @@ -138,6 +138,8 @@ CONST %CHANGE_L2_BLOCK_TX_TYPE = 0x0b CONST %DELTA_TIMESTAMP_NUM_BYTES = 4 CONST %INDEX_L1INFOTREE_NUM_BYTES = 4 CONST %TX_TYPE_NUM_BYTES = 1 +CONST %COINBASE_NUM_BYTES = 20 + ; CONSTANTS MEM_ALIGN CONST %MEM_ALIGN_SIZE = 2**7 diff --git a/main/load-change-l2-block.zkasm b/main/load-change-l2-block.zkasm index e1e23172..81a34be7 100644 --- a/main/load-change-l2-block.zkasm +++ b/main/load-change-l2-block.zkasm @@ -19,7 +19,13 @@ decodeChangeL2BlockTx: %INDEX_L1INFOTREE_NUM_BYTES => D :CALL(getChangeL2TxBytes) C + D => C A :MSTORE(indexL1InfoTree) + + ; Decode coinbase / 20 bytes + %COINBASE_NUM_BYTES => D :CALL(getChangeL2TxBytes) + C + D => C + A :MSTORE(sequencerAddr) 1 :MSTORE(isChangeL2BlockTx) + ; update batchHashPos HASHPOS :MSTORE(batchHashPos) ; update bytes parsed diff --git a/main/main.zkasm b/main/main.zkasm index e20c8622..e016398f 100644 --- a/main/main.zkasm +++ b/main/main.zkasm @@ -33,7 +33,6 @@ start: ; main zkROM entry point RCX :MSTORE(currentL1InfoTreeIndex) GAS :MSTORE(chainID) ; chainID from GAS, assumed to be less than 32 bits - ${getSequencerAddr()} :MSTORE(sequencerAddr) ${getBatchHashData()} :MSTORE(batchHashData) ${getForcedHashData()} => A :MSTORE(forcedHashData) 0 => B @@ -57,7 +56,7 @@ start: ; main zkROM entry point ;; C - Compute newBatchAccInputHash, load blockNum and timestamp ;;;;;;;;;;;;;;;;;; computeNewBatchAccInputHash: - ; newBatchAccInputHash = LinearPoseidon(oldBatchAccInputHash, batchHashData, sequencerAddress, forcedHashData)) + ; newBatchAccInputHash = LinearPoseidon(oldBatchAccInputHash, batchHashData, forcedHashData)) $ => E :MLOAD(nextHashPId) E + 1 :MSTORE(nextHashPId) $${eventLog(onStartBatch, C)} @@ -68,9 +67,6 @@ computeNewBatchAccInputHash: ${mem.batchHashData} :HASHP32(E), MLOAD(batchHashData) - ; 20 bytes - ${mem.sequencerAddr} :HASHP20(E), MLOAD(sequencerAddr) - ; 32 bytes ${mem.forcedHashData} :HASHP32(E), MLOAD(forcedHashData) diff --git a/main/process-change-l2-block.zkasm b/main/process-change-l2-block.zkasm index d4dcfb9f..a21f7fd6 100644 --- a/main/process-change-l2-block.zkasm +++ b/main/process-change-l2-block.zkasm @@ -54,6 +54,8 @@ continueProcessChangeL2Block: ; forced batch ; - update timestamp only if currentTimestamp < forcedTimestamp ; - set blockHash to default + ; sequencerAddr is already zero but we set it anyway to remark that forced tx fees are burnt (sent to zero address) + 0 :MSTORE(sequencerAddr) $ => C :MLOAD(forcedBlockHashL1InfoTree) C :MSTORE(blockHashL1InfoTree) $ => B :MLOAD(forcedTimestamp) diff --git a/main/vars.zkasm b/main/vars.zkasm index 6dc2bb7b..8f0a1f01 100644 --- a/main/vars.zkasm +++ b/main/vars.zkasm @@ -17,7 +17,7 @@ VAR GLOBAL isForced ; Flag to determine if the batch is forced VAR GLOBAL cumulativeGasUsed ; cumulative gas used in the block VAR GLOBAL forcedHashData ; solidtykeccak256(abi.encode(GER, blockHashL1, forcedTimestamp)) ; Output variables -VAR GLOBAL newBatchAccInputHash ; Final accumulated input hash. newBatchAccInputHash = LinearPoseidon(oldBatchAccInputHash, batchHashData, sequencerAddress, forcedHashData)) +VAR GLOBAL newBatchAccInputHash ; Final accumulated input hash. newBatchAccInputHash = LinearPoseidon(oldBatchAccInputHash, batchHashData, forcedHashData)) VAR GLOBAL newLocalExitRoot ; Updated local exit tree root VAR GLOBAL batchL2DataParsed ; Number of bytes read when decoding RLP transactions. Computed during RLP loop