Skip to content

Commit

Permalink
Add coinbase at changeL2Block
Browse files Browse the repository at this point in the history
  • Loading branch information
ignasirv committed Apr 30, 2024
1 parent 99c17c1 commit d6fd22f
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion main/block-info.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions main/constants.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions main/load-change-l2-block.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions main/main.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)}
Expand All @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions main/process-change-l2-block.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion main/vars.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"devDependencies": {
"@0xpolygonhermez/zkevm-commonjs": "github:0xPolygonHermez/zkevm-commonjs#develop-feijoa",
"@0xpolygonhermez/zkevm-proverjs": "github:0xPolygonHermez/zkevm-proverjs#develop-feijoa",
"@0xpolygonhermez/zkevm-testvectors": "github:0xPolygonHermez/zkevm-testvectors#develop-feijoa",
"@0xpolygonhermez/zkevm-testvectors": "github:0xPolygonHermez/zkevm-testvectors#feature/block-coinbase",
"chai": "^4.3.6",
"chalk": "^3.0.0",
"eslint": "^8.25.0",
Expand Down

0 comments on commit d6fd22f

Please sign in to comment.