-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #325 from 0xPolygonHermez/develop
fork 7
- Loading branch information
Showing
148 changed files
with
23,206 additions
and
567 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
VAR GLOBAL tmpSR | ||
VAR GLOBAL currentLogIndex | ||
|
||
initBlockInfoTree: | ||
0 :MSTORE(blockInfoSR), RETURN | ||
|
||
; @info Save blockInfo root when a new context is created | ||
checkpointBlockInfoTree: | ||
$ => B :MLOAD(currentLogIndex) | ||
B :MSTORE(initLogIndex) | ||
$ => B :MLOAD(blockInfoSR) | ||
B :MSTORE(initBlockInfoSR), RETURN | ||
|
||
; @info Back to initial blockInfo root | ||
revertBlockInfoTree: | ||
$ => A :MLOAD(initLogIndex) | ||
A :MSTORE(currentLogIndex) | ||
$ => A :MLOAD(initBlockInfoSR) | ||
A :MSTORE(blockInfoSR), RETURN | ||
|
||
; @info Fill Block Info tree with initial block values | ||
setupNewBlockInfoTree: | ||
; checks zk-counters | ||
%MAX_CNT_STEPS - STEP - 50 :JMPN(outOfCountersStep) | ||
%MAX_CNT_POSEIDON_G - CNT_POSEIDON_G - %MAX_CNT_POSEIDON_SLOAD_SSTORE*7 :JMPN(outOfCountersPoseidon) | ||
%MAX_CNT_BINARY - CNT_BINARY - 7 :JMPN(outOfCountersBinary) | ||
|
||
; save current state root & load block info root | ||
SR :MSTORE(tmpSR) | ||
$ => SR :MLOAD(blockInfoSR) | ||
|
||
; Insert previous block hash | ||
; key: H([blockHeaderParams[0:4], blockHeaderParams[4:8], blockHeaderParams[8:12], blockHeaderParams[12:16], blockHeaderParams[16:20], 0, SMT_KEY_BLOCK_HEADER_PARAM, 0], [hk0[0], hk0[1], hk0[2], hk0[3]]) | ||
; value: previousBlockHash | ||
%INDEX_BLOCK_HEADER_PARAM_BLOCK_HASH => A | ||
%SMT_KEY_BLOCK_HEADER_PARAM => B | ||
0 => C | ||
$ => D :MLOAD(previousBlockHash) | ||
$ => SR :SSTORE | ||
|
||
; Insert coinbase address | ||
; key: H([blockHeaderParams[0:4], blockHeaderParams[4:8], blockHeaderParams[8:12], blockHeaderParams[12:16], blockHeaderParams[16:20], 0, SMT_KEY_BLOCK_HEADER_PARAM, 0], [hk0[0], hk0[1], hk0[2], hk0[3]]) | ||
; value: sequencerAddr | ||
%INDEX_BLOCK_HEADER_PARAM_COINBASE => A | ||
%SMT_KEY_BLOCK_HEADER_PARAM => B | ||
0 => C | ||
$ => D :MLOAD(sequencerAddr) | ||
$ => SR :SSTORE | ||
|
||
; Insert block number | ||
; key: H([blockHeaderParams[0:4], blockHeaderParams[4:8], blockHeaderParams[8:12], blockHeaderParams[12:16], blockHeaderParams[16:20], 0, SMT_KEY_BLOCK_HEADER_PARAM, 0], [hk0[0], hk0[1], hk0[2], hk0[3]]) | ||
; value: blockNum | ||
%INDEX_BLOCK_HEADER_PARAM_NUMBER => A | ||
%SMT_KEY_BLOCK_HEADER_PARAM => B | ||
0 => C | ||
$ => D :MLOAD(blockNum) | ||
$ => SR :SSTORE | ||
|
||
; Insert block gas limit | ||
; key: H([blockHeaderParams[0:4], blockHeaderParams[4:8], blockHeaderParams[8:12], blockHeaderParams[12:16], blockHeaderParams[16:20], 0, SMT_KEY_BLOCK_HEADER_PARAM, 0], [hk0[0], hk0[1], hk0[2], hk0[3]]) | ||
; value: block gas limit | ||
%INDEX_BLOCK_HEADER_PARAM_GAS_LIMIT => A | ||
%SMT_KEY_BLOCK_HEADER_PARAM => B | ||
0 => C | ||
%BLOCK_GAS_LIMIT => D | ||
$ => SR :SSTORE | ||
|
||
; Insert block timestamp | ||
; key: H([blockHeaderParams[0:4], blockHeaderParams[4:8], blockHeaderParams[8:12], blockHeaderParams[12:16], blockHeaderParams[16:20], 0, SMT_KEY_BLOCK_HEADER_PARAM, 0], [hk0[0], hk0[1], hk0[2], hk0[3]]) | ||
; value: timestamp | ||
%INDEX_BLOCK_HEADER_PARAM_TIMESTAMP => A | ||
%SMT_KEY_BLOCK_HEADER_PARAM => B | ||
0 => C | ||
$ => D :MLOAD(timestamp) | ||
$ => SR :SSTORE | ||
|
||
; Insert block new ger | ||
; key: H([blockHeaderParams[0:4], blockHeaderParams[4:8], blockHeaderParams[8:12], blockHeaderParams[12:16], blockHeaderParams[16:20], 0, SMT_KEY_BLOCK_HEADER_PARAM, 0], [hk0[0], hk0[1], hk0[2], hk0[3]]) | ||
; value: GER | ||
%INDEX_BLOCK_HEADER_PARAM_GER => A | ||
%SMT_KEY_BLOCK_HEADER_PARAM => B | ||
0 => C | ||
$ => D :MLOAD(gerL1InfoTree) | ||
$ => SR :SSTORE | ||
|
||
; Insert block new blockHashL1 | ||
; key: H([blockHeaderParams[0:4], blockHeaderParams[4:8], blockHeaderParams[8:12], blockHeaderParams[12:16], blockHeaderParams[16:20], 0, SMT_KEY_BLOCK_HEADER_PARAM, 0], [hk0[0], hk0[1], hk0[2], hk0[3]]) | ||
; value: blockHashL1 | ||
%INDEX_BLOCK_HEADER_PARAM_BLOCK_HASH_L1 => A | ||
%SMT_KEY_BLOCK_HEADER_PARAM => B | ||
0 => C | ||
$ => D :MLOAD(blockHashL1InfoTree) | ||
$ => SR :SSTORE | ||
|
||
; Restore current SR | ||
SR :MSTORE(blockInfoSR) | ||
$ => SR :MLOAD(tmpSR), RETURN | ||
|
||
; @info Fill Block Info tree with tx receipt values | ||
fillBlockInfoTreeWithTxReceipt: | ||
; checks zk-counters | ||
%MAX_CNT_STEPS - STEP - 50 :JMPN(outOfCountersStep) | ||
%MAX_CNT_POSEIDON_G - CNT_POSEIDON_G - %MAX_CNT_POSEIDON_SLOAD_SSTORE*4 :JMPN(outOfCountersPoseidon) | ||
%MAX_CNT_BINARY - CNT_BINARY - 4 :JMPN(outOfCountersBinary) | ||
; save current state root & load block info root | ||
SR :MSTORE(tmpSR) | ||
$ => SR :MLOAD(blockInfoSR) | ||
; Insert transaction hash | ||
; key: H([txIndex[0:4], txIndex[4:8], txIndex[8:12], txIndex[12:16], txIndex[16:20], 0, SMT_KEY_BLOCK_HEADER_TRANSACTION_HASH, 0], [hk0[0], hk0[1], hk0[2], hk0[3]]) | ||
; value: txHash | ||
$ => A :MLOAD(txIndex) | ||
%SMT_KEY_BLOCK_HEADER_TRANSACTION_HASH => B | ||
0 => C | ||
$ => D :MLOAD(l2TxHash) | ||
$ => SR :SSTORE | ||
|
||
; Insert transaction status | ||
; key: H([txIndex[0:4], txIndex[4:8], txIndex[8:12], txIndex[12:16], txIndex[16:20], 0, SMT_KEY_BLOCK_HEADER_STATUS, 0], [hk0[0], hk0[1], hk0[2], hk0[3]]) | ||
; value: txStatus | ||
%SMT_KEY_BLOCK_HEADER_STATUS => B | ||
0 => C | ||
$ => D :MLOAD(txStatus) | ||
$ => SR :SSTORE | ||
|
||
; Insert transaction cumulativeGasUsed | ||
; key: H([txIndex[0:4], txIndex[4:8], txIndex[8:12], txIndex[12:16], txIndex[16:20], 0, SMT_KEY_BLOCK_HEADER_CUMULATIVE_GAS_USED, 0], [hk0[0], hk0[1], hk0[2], hk0[3]]) | ||
; value: txStatus | ||
%SMT_KEY_BLOCK_HEADER_CUMULATIVE_GAS_USED => B | ||
0 => C | ||
$ => D :MLOAD(cumulativeGasUsed) | ||
$ => SR :SSTORE | ||
|
||
; Insert transaction effectivePercentage | ||
; key: H([txIndex[0:4], txIndex[4:8], txIndex[8:12], txIndex[12:16], txIndex[16:20], 0, SMT_KEY_BLOCK_HEADER_CUMULATIVE_GAS_USED, 0], [hk0[0], hk0[1], hk0[2], hk0[3]]) | ||
; value: effectivePercentage | ||
%SMT_KEY_BLOCK_HEADER_EFFECTIVE_PERCENTAGE => B | ||
0 => C | ||
$ => D :MLOAD(effectivePercentageRLP) | ||
$ => SR :SSTORE | ||
|
||
; Restore current SR | ||
SR :MSTORE(blockInfoSR) | ||
$ => SR :MLOAD(tmpSR), RETURN | ||
|
||
; @info Fill Block Info tree with block gas used at the end of block processing and Store block Info Root in storage | ||
consolidateBlock: | ||
; checks zk-counters | ||
%MAX_CNT_STEPS - STEP - 20 :JMPN(outOfCountersStep) | ||
%MAX_CNT_POSEIDON_G - CNT_POSEIDON_G - %MAX_CNT_POSEIDON_SLOAD_SSTORE*2 :JMPN(outOfCountersPoseidon) | ||
%MAX_CNT_BINARY - CNT_BINARY - 2 :JMPN(outOfCountersBinary) | ||
; save current state root & load block info root | ||
SR :MSTORE(tmpSR) | ||
$ => SR :MLOAD(blockInfoSR) | ||
|
||
; Insert transaction cumulativeGasUsed | ||
; key: H([blockHeaderParams[0:4], blockHeaderParams[4:8], blockHeaderParams[8:12], blockHeaderParams[12:16], blockHeaderParams[16:20], 0, SMT_KEY_BLOCK_HEADER_PARAM, 0], [hk0[0], hk0[1], hk0[2], hk0[3]]) | ||
; value: txStatus | ||
%INDEX_BLOCK_HEADER_PARAM_GAS_USED => A | ||
%SMT_KEY_BLOCK_HEADER_PARAM => B | ||
0 => C | ||
$ => D :MLOAD(cumulativeGasUsed) | ||
$ => SR :SSTORE | ||
|
||
; Restore current SR | ||
SR :MSTORE(blockInfoSR) | ||
$ => SR :MLOAD(tmpSR) | ||
|
||
finalConsolidateBlockInfoTree: | ||
; Store block Info Root in storage | ||
%ADDRESS_SYSTEM => A | ||
%SMT_KEY_SC_STORAGE => B | ||
%BLOCK_INFO_ROOT_STORAGE_POS => C | ||
writeBlockInfoRoot: | ||
$ => D :MLOAD(blockInfoSR) | ||
$ => SR :SSTORE | ||
$${eventLog(onFinishBlock)} | ||
:RETURN | ||
|
||
; @info add new log hash to block info tree | ||
; @in D => Value to store (linearPoseidon(log_data + log_topics)) | ||
fillBlockInfoTreeWithLog: | ||
; checks zk-counters | ||
%MAX_CNT_STEPS - STEP - 20 :JMPN(outOfCountersStep) | ||
%MAX_CNT_POSEIDON_G - CNT_POSEIDON_G - %MAX_CNT_POSEIDON_SLOAD_SSTORE :JMPN(outOfCountersPoseidon) | ||
%MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary) | ||
; save current state root & load block info root | ||
SR :MSTORE(tmpSR) | ||
$ => SR :MLOAD(blockInfoSR) | ||
|
||
; Retrieve and update currentLogIndex | ||
$ => C :MLOAD(currentLogIndex) | ||
C + 1 :MSTORE(currentLogIndex) | ||
|
||
; Insert new log to block info tree | ||
; key: H([logIndexKey[0:4], logIndexKey[4:8], logIndexKey[8:12], logIndexKey[12:16], logIndexKey[16:20], 0, SMT_KEY_BLOCK_HEADER_LOGS, 0], [hk0[0], hk0[1], hk0[2], hk0[3]]) | ||
; hk0: H([logIndex[0:4], logIndex[4:8], logIndex[8:12], logIndex[12:16], logIndex[16:20], logIndex[20:24], logIndex[24:28], logIndex[28:32], [0, 0, 0, 0]) | ||
; value: linearPoseidon(log_data + log_topics) | ||
$ => A :MLOAD(txIndex) | ||
%SMT_KEY_BLOCK_HEADER_LOGS => B | ||
$ => SR :SSTORE | ||
|
||
; Restore current SR | ||
SR :MSTORE(blockInfoSR) | ||
$ => SR :MLOAD(tmpSR), RETURN |
Oops, something went wrong.