Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop etrog #319

Merged
merged 171 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
171 commits
Select commit Hold shift + click to select a range
d694c3f
Merge pull request #42 from 0xPolygonHermez/fix/ecrecover-point-at-in…
krlosMata Oct 31, 2023
f0b0c9d
Running all tests even if one was failed
MCJOHN974 Sep 25, 2023
927ecd0
Exit code handling
MCJOHN974 Sep 25, 2023
0cc962b
switch to bool flag instead exit code
MCJOHN974 Sep 26, 2023
52c68ea
Fork etrog implementation
ignasirv Aug 21, 2023
380d906
add l1InfoTree
krlosMata Oct 18, 2023
6f8d137
update package.json to l1-info-tree branches
krlosMata Nov 3, 2023
f3ecf36
add label to skip first changeL2Block transaction
krlosMata Nov 8, 2023
993e876
fix comment
krlosMata Nov 10, 2023
891dfe7
add pre-sha2
laisolizq Oct 20, 2023
bc4e8d2
update pre-sha256
laisolizq Nov 8, 2023
b9cbc23
fix return & add comments
laisolizq Nov 9, 2023
ca5c7b1
update cnt sha256
laisolizq Nov 10, 2023
9025d8c
update main PR
laisolizq Nov 17, 2023
894b2eb
fix
laisolizq Nov 17, 2023
67757a6
fix modexp
laisolizq Nov 6, 2023
6a4e8b8
add edge cases
laisolizq Nov 6, 2023
04c258c
fix package proverjs
laisolizq Nov 7, 2023
6815c6b
fix edge cases & comments
laisolizq Nov 7, 2023
4ece98c
update pre-sha256
laisolizq Nov 8, 2023
7ba53da
update counters
laisolizq Nov 10, 2023
6c3652d
fix merge
laisolizq Nov 21, 2023
0b12c56
Merge pull request #50 from 0xPolygonHermez/feature/fix-modexp-sha256
laisolizq Nov 21, 2023
663f984
Merge pull request #51 from 0xPolygonHermez/feature/sha256-l1-info-tree
krlosMata Nov 21, 2023
1ff2743
Merge pull request #44 from 0xPolygonHermez/feature/l1-info-tree
krlosMata Nov 21, 2023
346f404
The input length was found to be 1818
hecmas Nov 22, 2023
f8578b3
Fixing some counters
hecmas Nov 22, 2023
30c5b72
Modexp input length restricted to 16
hecmas Nov 22, 2023
4625194
Modexp input length finally restricted to 32
hecmas Nov 23, 2023
11c39c2
Merge pull request #53 from 0xPolygonHermez/feature/modexp-input-length
hecmas Nov 23, 2023
5c19a21
Minor optimizations to pre-modexp, adding the new limit of 1024 bytes…
hecmas Nov 23, 2023
9422c6a
Minor bug found by Laia
hecmas Nov 23, 2023
f4d7534
fix premodexp save0out
laisolizq Nov 23, 2023
a5c679c
Merge pull request #54 from 0xPolygonHermez/feature/revert-modexp
hecmas Nov 24, 2023
ec1a2bd
fix sha counters
krlosMata Nov 23, 2023
5dc4c52
Fix sha256 counters and typo
ignasirv Nov 24, 2023
386168b
Merge pull request #55 from 0xPolygonHermez/feature/fix-sha256
ignasirv Nov 24, 2023
b46718a
Fixing the number of inputs of BN254_ADDFP2 and BN254_SUBFP2
hecmas Nov 24, 2023
d08bf94
Merge branch 'feature/fork-etrog' into fix/js-in-rom-fp2
hecmas Nov 24, 2023
63193c2
update sample parallel tests
laisolizq Nov 24, 2023
cfd95fc
Merge pull request #57 from 0xPolygonHermez/fix/js-in-rom-fp2
hecmas Nov 24, 2023
134fb3e
LT4 sanity check on initial and final root
krlosMata Nov 24, 2023
9bef8d0
Bug fixing issues 37 and 38
ignasirv Nov 27, 2023
615d22f
PR review
krlosMata Nov 27, 2023
64075be
Merge pull request #58 from 0xPolygonHermez/feature/lt4
krlosMata Nov 27, 2023
7ece1f3
Merge pull request #59 from 0xPolygonHermez/feature/bugfix_37_38
krlosMata Nov 27, 2023
6bbe7d9
Adding constants as array input size
hecmas Nov 27, 2023
87d26d9
add label writeBlockInfoRoot
krlosMata Nov 28, 2023
4b1be37
Added constraints for the free iinputs
hecmas Nov 28, 2023
db4f00b
Added the constants
hecmas Nov 28, 2023
8242ab9
Merge pull request #62 from 0xPolygonHermez/fix/modexp-freeinputs
hecmas Nov 29, 2023
294ed17
Merge pull request #61 from 0xPolygonHermez/feature/add-label
krlosMata Nov 29, 2023
414ed5b
Merge branch 'feature/fork-etrog' into feature/fix-sample-tests
krlosMata Nov 29, 2023
6dced5f
Merge pull request #56 from 0xPolygonHermez/feature/fix-sample-tests
krlosMata Nov 29, 2023
331b36a
Add effective percentage at l2 tx hash
ignasirv Nov 27, 2023
dea225e
Refactor effective percentage: secure in block info tree
ignasirv Nov 28, 2023
12e49fb
Update package.json
krlosMata Nov 29, 2023
93984c7
Merge pull request #60 from 0xPolygonHermez/feature/ep-l2txhash
krlosMata Nov 29, 2023
db93ed5
optimize arrays
krlosMata Nov 29, 2023
3d8d880
Fixed the optimization. Moved an unused folder
hecmas Nov 29, 2023
fbed9b3
Update package.json
hecmas Nov 29, 2023
623f2cb
Merge pull request #63 from 0xPolygonHermez/feature/optimize-arrays
hecmas Nov 30, 2023
6de849d
Small fixes, typos, optimizations, renamings...
ignasirv Nov 30, 2023
6d9d5af
Typos at comments + 1 typo at a constant
ignasirv Nov 30, 2023
2cfef0d
Cleanup and some bugs fixed
hecmas Nov 30, 2023
48de92b
Merge pull request #64 from 0xPolygonHermez/feature/pr-review
krlosMata Dec 1, 2023
28e907f
Merge pull request #65 from 0xPolygonHermez/feature/spell-check
krlosMata Dec 1, 2023
138e8df
More bugs fixed and comments added
hecmas Dec 1, 2023
59b10ab
Remove unused depth var
ignasirv Dec 1, 2023
1972bef
Merge pull request #67 from 0xPolygonHermez/feature/remove-depth
krlosMata Dec 1, 2023
35af14b
Fixing the tests...
hecmas Dec 1, 2023
0e2f810
All tests fixed!!!!
hecmas Dec 1, 2023
2b16007
Minor fixes
hecmas Dec 4, 2023
b115099
comments & spaces
krlosMata Dec 4, 2023
2cacb20
update sample invalid-batch
laisolizq Dec 4, 2023
fa7e65b
Merge pull request #66 from 0xPolygonHermez/feature/pairing-cleanup
krlosMata Dec 5, 2023
1457d5b
Merge pull request #68 from 0xPolygonHermez/feature/comments-spaces
krlosMata Dec 5, 2023
4944971
update package json
laisolizq Dec 5, 2023
5b18ce1
Merge pull request #69 from 0xPolygonHermez/feature/update-sample-ooc
krlosMata Dec 5, 2023
7371c37
update packages
krlosMata Dec 5, 2023
bf050ce
Merge pull request #70 from 0xPolygonHermez/feature/update-packages
krlosMata Dec 6, 2023
067ea9a
Add on step for unsigned transactions
ignasirv Dec 7, 2023
8dc3f61
Merge pull request #74 from 0xPolygonHermez/feature/fix-unsigned
krlosMata Dec 10, 2023
fa84642
Fixing a bug in modexp
hecmas Dec 11, 2023
934c82f
Removing redundancy on array utils
hecmas Dec 11, 2023
6963fc9
Array arith coverage completed
hecmas Dec 12, 2023
ad40b95
ecAdd, ecMul and ecPairing coverage completed
hecmas Dec 13, 2023
cca8f66
array_div_mod renamed to array_div for correctness
hecmas Dec 13, 2023
4c1965f
improve error and events
krlosMata Dec 15, 2023
9f68f48
array_square minor bug fixed
hecmas Dec 15, 2023
1dfb815
optimization for verifyMerkleProof
zkronos73 Dec 13, 2023
4d08a4e
optimitzation verify merkle tree v2
krlosMata Dec 15, 2023
00c431e
array_square coverage completed
hecmas Dec 15, 2023
d98a858
Starting the refactor with array add
hecmas Dec 18, 2023
9d1ab72
fix sha256 retcalllength > 32
laisolizq Dec 18, 2023
4e22a2d
fix pre-modexp memory
laisolizq Dec 14, 2023
ec8a2c2
WIP
hecmas Dec 18, 2023
e3269a8
PR review
krlosMata Dec 18, 2023
98798b3
update package proverjs
krlosMata Dec 19, 2023
a8bf136
Merge pull request #81 from 0xPolygonHermez/feature/improve-errors-an…
krlosMata Dec 19, 2023
4a2ccb6
Fix multiple free inputs
ignasirv Dec 12, 2023
f57d079
Fix finalize batch for empty batchL2Data
ignasirv Dec 19, 2023
3bc929a
comments
ignasirv Dec 19, 2023
87426e4
Two bugs fixed in array_mul_long/short
hecmas Dec 19, 2023
b99c96b
A first full refactor done
hecmas Dec 19, 2023
0d41b5b
Utils refactor done
hecmas Dec 20, 2023
c51fd31
Counters corrected
hecmas Dec 20, 2023
8c49833
add test modexp memory
laisolizq Dec 20, 2023
2f779d5
Link added to ecPairing
hecmas Dec 20, 2023
8a0a1c9
update MAX_CNT_SHA256_F_LIMIT
zkronos73 Dec 20, 2023
452db45
Renaming constant
ignasirv Dec 20, 2023
9d05172
Merge pull request #76 from 0xPolygonHermez/feature/fix-freeinput
krlosMata Dec 20, 2023
b5ee9f9
Merge pull request #78 from 0xPolygonHermez/feature/precompiled-coverage
krlosMata Dec 20, 2023
e8a69bf
Merge pull request #80 from 0xPolygonHermez/feature/fix-audit-pre
krlosMata Dec 20, 2023
5ac0301
fix modexp length gas
laisolizq Dec 15, 2023
1c9e515
Fix modexp error handling
ignasirv Dec 18, 2023
e6a5f87
Fix mul arith overflow at modexp
ignasirv Dec 19, 2023
6e3675d
Fix add arith overflow at modexp
ignasirv Dec 19, 2023
b23f8aa
Merge pull request #83 from 0xPolygonHermez/feature/verify-smt-opt-v2
krlosMata Dec 20, 2023
84c07d6
Merge pull request #85 from 0xPolygonHermez/feature/fix-sha256-retcall
krlosMata Dec 20, 2023
7f3b956
Merge pull request #87 from 0xPolygonHermez/fix/update-sha256-counter…
krlosMata Dec 20, 2023
57d7f1d
Implement batch data length at change l2 block parsing
ignasirv Dec 19, 2023
1803a50
add comments
krlosMata Dec 20, 2023
cb679f6
comments
ignasirv Dec 20, 2023
261fd15
Merge pull request #84 from 0xPolygonHermez/feature/array-lib-refactor
krlosMata Dec 20, 2023
8e4469d
Merge pull request #86 from 0xPolygonHermez/feature/fix-batch-length
krlosMata Dec 20, 2023
0a6721d
Merge pull request #82 from 0xPolygonHermez/feature/fix-gas-length-mo…
krlosMata Dec 20, 2023
d50d0da
fix label preFailLength
krlosMata Dec 20, 2023
318b30e
update packages
krlosMata Dec 20, 2023
c627e64
fix array_mul_short_carry_check
laisolizq Dec 20, 2023
037afed
Merge pull request #91 from 0xPolygonHermez/feature/fix-array-mul-short
krlosMata Dec 20, 2023
b99317c
update packages
krlosMata Dec 20, 2023
9167a4f
Merge pull request #92 from 0xPolygonHermez/feature/packages-v2
krlosMata Dec 21, 2023
101d7fb
Solving a soundness bug in invFp2
hecmas Jan 9, 2024
714cda1
Merge pull request #102 from 0xPolygonHermez/fix/fp2inv-alias
hecmas Jan 11, 2024
582c3a4
Fix binaries check at SSTORE operations
ignasirv Jan 8, 2024
ca9eb0a
PR review
ignasirv Jan 9, 2024
6621279
Remove unnecessary binaries from rlp parsing
ignasirv Jan 15, 2024
6445f23
Merge pull request #100 from 0xPolygonHermez/feature/binaries-fix
krlosMata Jan 16, 2024
e194c55
fix argsLengthCall pre-ecPairing
laisolizq Jan 16, 2024
4bdb492
Reset carry fix in array add AGTB
hecmas Jan 17, 2024
4bc9d53
Initialization fix in array mul long
hecmas Jan 17, 2024
80fb62f
Initialization fix in array square
hecmas Jan 17, 2024
e83a9ef
Cumulative gas used fix
ignasirv Jan 12, 2024
bc57552
Soundness issus fixed in array div long
hecmas Jan 17, 2024
8107714
Soundness issus fixed in array div short
hecmas Jan 17, 2024
bbfa28f
add fixes to wrong comments
krlosMata Jan 17, 2024
54d3e70
PR review
krlosMata Jan 17, 2024
64fec5c
Merge pull request #104 from 0xPolygonHermez/feature/fix-pre-args
krlosMata Jan 17, 2024
bc5211d
Merge pull request #105 from 0xPolygonHermez/fix/initialization-issues
krlosMata Jan 17, 2024
77f7107
Merge pull request #108 from 0xPolygonHermez/feature/fix-comments
krlosMata Jan 17, 2024
4b84e6c
Soundness issus fixed in counters of array div long
hecmas Jan 17, 2024
f5e50a7
Soundness issus fixed in counters of array div short
hecmas Jan 17, 2024
89f6782
Minor issues solved in coutners computation
hecmas Jan 17, 2024
3879dae
Merge pull request #107 from 0xPolygonHermez/fix/freeinput-array-div
krlosMata Jan 17, 2024
4fabf75
Merge pull request #109 from 0xPolygonHermez/fix/bad-counters-array-lib
krlosMata Jan 17, 2024
82fadfd
Merge pull request #106 from 0xPolygonHermez/feature/cumulative-gas-fix
krlosMata Jan 17, 2024
77c255e
update commonjs & testvectors cumulative-gas-fix
laisolizq Jan 17, 2024
70dd647
update tags
laisolizq Jan 22, 2024
cbf4dd1
Merge pull request #110 from 0xPolygonHermez/feature/update-packages-fix
krlosMata Jan 22, 2024
d7e0cf9
new l2 hash
krlosMata Jan 24, 2024
b59f375
Update package
ignasirv Jan 24, 2024
ba28b60
Fix ecrecover test
ignasirv Jan 24, 2024
6a0ae43
final version
krlosMata Jan 24, 2024
9739803
back ecrecover test & update package
krlosMata Jan 24, 2024
941ef60
remove unnecessary file & fix wrong comment
krlosMata Jan 25, 2024
e0bf830
update packages to last version
krlosMata Jan 25, 2024
b43d21f
Merge pull request #113 from 0xPolygonHermez/feature/new-l2hash
krlosMata Jan 25, 2024
487ac3d
Merge pull request #40 from 0xPolygonHermez/feature/fork-etrog
krlosMata Jan 26, 2024
1813bda
remove internal dependencies
krlosMata Jan 26, 2024
51241fe
Merge branch 'develop' into develop-etrog
krlosMata Jan 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name: Test executor inputs
on:
workflow_dispatch:
pull_request:
branches: [main, develop]
branches: [main, develop, develop-etrog, feature/fork-etrog, feature/l1-info-tree]

jobs:
build:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,5 @@ tools/parallel-tests


.vscode/launch.json

.vscode/settings.json
39 changes: 23 additions & 16 deletions counters/counters-executor.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable no-use-before-define */
/* eslint-disable no-restricted-syntax */
const path = require('path');
const fs = require('fs');
const smMain = require('@0xpolygonhermez/zkevm-proverjs/src/sm/sm_main/sm_main');

const fileCachePil = path.join(__dirname, '../node_modules/@0xpolygonhermez/zkevm-proverjs/cache-main-pil.json');
const empty_input = require('@0xpolygonhermez/zkevm-proverjs/test/inputs/empty_input.json')
const emptyInput = require('@0xpolygonhermez/zkevm-proverjs/test/inputs/empty_input.json');
const buildPoseidon = require('@0xpolygonhermez/zkevm-commonjs').getPoseidon;

const pathMainPil = path.join(__dirname, '../node_modules/@0xpolygonhermez/zkevm-proverjs/pil/main.pil');
const { newCommitPolsArray } = require('pilcom');
const { compile } = require('pilcom');
const zkasm = require("@0xpolygonhermez/zkasmcom");
const zkasm = require('@0xpolygonhermez/zkasmcom');

const testFilesDir = path.join(__dirname, './tests');
const { argv } = require('yargs');

async function main() {

// Compile pil
const cmPols = await compilePil();

// Get all zkasm files
const files = getTestFiles();

// Run all zkasm files
for (let file of files) {
await runTest(file, cmPols)
for (const file of files) {
await runTest(file, cmPols);
}
}

Expand All @@ -30,27 +35,28 @@ async function runTest(testName, cmPols) {
// Compile rom
const configZkasm = {
defines: [],
allowUndefinedLabels: true
allowUndefinedLabels: true,
};

const rom = await zkasm.compile(zkasmFile, null, configZkasm);
const config = {
debug: true,
stepsN: 8388608,
}
console.log(`Running ${testName}`)
};
console.log(`Running ${testName}`);
// Execute test
const res = await smMain.execute(cmPols.Main, empty_input, rom, config);
console.log(res.counters)
const res = await smMain.execute(cmPols.Main, emptyInput, rom, config);
console.log(res.counters);
}

// Get all zkasm counter test files
function getTestFiles() {
if(argv.test){
return [`${argv.test}.zkasm`]
if (argv.test) {
return [`${argv.test}.zkasm`];
}
const files = fs.readdirSync(testFilesDir).filter(name => name.endsWith('.zkasm'))
return files
const files = fs.readdirSync(testFilesDir).filter((name) => name.endsWith('.zkasm'));

return files;
}

async function compilePil() {
Expand All @@ -60,14 +66,15 @@ async function compilePil() {
const pilConfig = {
defines: { N: 4096 },
namespaces: ['Main', 'Global'],
disableUnusedError: true
disableUnusedError: true,
};
const p = await compile(F, pathMainPil, null, pilConfig);
fs.writeFileSync(fileCachePil, `${JSON.stringify(p, null, 1)}\n`, 'utf8');
}

const pil = JSON.parse(fs.readFileSync(fileCachePil));

return newCommitPolsArray(pil);
}

main()
main();
6 changes: 3 additions & 3 deletions counters/countersConstants.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ CONST %OPCODECOPY_CNT_PADDING_PG = 0
CONST %OPCODECOPY_CNT_POSEIDON_G = 0
; opEXTCODECOPY - COMPLEX - hardcoded values at test
CONST %OPEXTCODECOPY_STEP = 2000
CONST %OPEXTCODECOPY_CNT_BINARY = 105
CONST %OPEXTCODECOPY_CNT_BINARY = 104
CONST %OPEXTCODECOPY_CNT_ARITH = 4
CONST %OPEXTCODECOPY_CNT_KECCAK_F = 0
CONST %OPEXTCODECOPY_CNT_MEM_ALIGN = 43
Expand All @@ -248,8 +248,8 @@ CONST %OPCREATE_CNT_MEM_ALIGN = 0
CONST %OPCREATE_CNT_PADDING_PG = 0
CONST %OPCREATE_CNT_POSEIDON_G = 23
; opCREATE2 - COMPLEX - hardcoded values at test
CONST %OPCREATE2_STEP = 500
CONST %OPCREATE2_CNT_BINARY = 22
CONST %OPCREATE2_STEP = 400
CONST %OPCREATE2_CNT_BINARY = 21
CONST %OPCREATE2_CNT_ARITH = 2
CONST %OPCREATE2_CNT_KECCAK_F = 0
CONST %OPCREATE2_CNT_MEM_ALIGN = 0
Expand Down
5 changes: 3 additions & 2 deletions counters/endIncludes.zkasm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
INCLUDE "../main/load-tx-rlp-utils.zkasm"
INCLUDE "../main/2-exp.zkasm"
INCLUDE "../main/tables/2-exp.zkasm"
INCLUDE "../main/vars.zkasm"
INCLUDE "../main/utils.zkasm"
INCLUDE "../main/opcodes/calldata-returndata-code.zkasm"
Expand All @@ -14,4 +14,5 @@ INCLUDE "../main/opcodes/logs.zkasm"
INCLUDE "../main/opcodes/stack-operations.zkasm"
INCLUDE "../main/opcodes/storage-memory.zkasm"
INCLUDE "../main/touched.zkasm"
INCLUDE "../main/end.zkasm"
INCLUDE "../main/end.zkasm"
INCLUDE "../main/block-info.zkasm"
2 changes: 1 addition & 1 deletion counters/tests/opBLOCKHASH.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ start:

operation:
2 :HASHK1(0)
10 :MSTORE(txCount)
10 :MSTORE(blockNum)
1 :MSTORE(SP++)
:JMP(opBLOCKHASH)
checkCounters:
Expand Down
204 changes: 204 additions & 0 deletions main/block-info.zkasm
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
Loading
Loading