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

update tests vectors & add run scripts ooc/30m #243

Merged
merged 4 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
run: |
npm i
npm run build
npm run test:build:gasLimit:v1
npm run test:build:gasLimit:v2
npm run test:build:gasLimit:v3
- name: run counters tests
run: |
npm run test:counters
Expand Down
22 changes: 13 additions & 9 deletions main/opcodes/calldata-returndata-code.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,8 @@ opCODECOPY:
; store lastMemOffset for memory expansion gas cost
C :MSTORE(lastMemOffset)
; store lastMemLength for memory expansion gas cost
E :MSTORE(lastMemLength)
; compute memory expansion gas cost
:CALL(saveMem); in: [lastMemOffset, lastMemLength]
E :MSTORE(lastMemLength), CALL(saveMem); in: [lastMemOffset, lastMemLength]
; check out-of-gas
GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
;${3*((E+31)/32)}
Expand Down Expand Up @@ -403,7 +402,8 @@ VAR GLOBAL tmpContractLength
*/
opEXTCODECOPY:
; checks zk-counters
%MAX_CNT_STEPS - STEP - 300 :JMPN(outOfCountersStep)
%MAX_CNT_STEPS - STEP - 300 :JMPN(outOfCountersStep)
%MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary)

; check stack underflow
SP - 4 => SP :JMPN(stackUnderflow)
Expand All @@ -421,7 +421,8 @@ opEXTCODECOPY:
C :MSTORE(lastMemOffset)

; store lastMemLength for memory expansion gas cost
E :MSTORE(lastMemLength)
; compute memory expansion gas cost
E :MSTORE(lastMemLength), CALL(saveMem); in: [lastMemOffset, lastMemLength]

; check out-of-gas
;${3*((E+31)/32)}
Expand All @@ -438,9 +439,6 @@ opEXTCODECOPY:
$ => A :MLOAD(arithRes1)
; check out-of-gas
GAS - A => GAS :JMPN(outOfGas)

; compute memory expansion gas cost
:CALL(saveMem); in: [lastMemOffset, lastMemLength]
; if offset is above data len, length => offset
D => A
$ => B :MLOAD(tmpContractLength)
Expand Down Expand Up @@ -558,15 +556,21 @@ opRETURNDATACOPY:
; Load ret data length from last ctx
B => CTX
E => B

; check offset is lower than max memory
%MAX_MEM_EXPANSION_BYTES => A
$ :LT,JMPC(outOfGas)

$ => A :MLOAD(retDataLength)
$ => E :MLOAD(retDataOffset)
$ => CTX :MLOAD(currentCTX)
; E ret data offset (memory pointer) of last context, B offset in return data that want to retrive
E + B => E
; if retDataSize <= retdataOffset + dataLen -> OOG
;A retDataSize
; A retDataSize
B + C => B ; total offset (retdataOffset + dataLen)
$ :LT, JMPC(outOfGas)
A - B :JMPN(outOfGas)

E => B ; memory pointer where start to copy memory
;${3*((C+31)/32)}
C+31 => A
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"scripts": {
"build": "mkdir -p build && npx zkasm main/main.zkasm -o build/rom.json && npm run build:metadata",
"build:metadata": "echo \"COMMIT=$(git rev-parse HEAD)\nSHA256SUM=$(sha256sum ./build/rom.json)\" > build/metadata-rom.txt",
"test:build:gasLimit:v1": "mkdir -p build && npx zkasm main/main.zkasm -o build/rom-89128960.test.json -D TX_GAS_LIMIT=89128960",
"test:build:gasLimit:v2": "mkdir -p build && npx zkasm main/main.zkasm -o build/rom-100000000.test.json -D TX_GAS_LIMIT=100000000",
"test:build:gasLimit:v3": "mkdir -p build && npx zkasm main/main.zkasm -o build/rom-2147483647.test.json -D TX_GAS_LIMIT=2147483647",
"test:bitwise": "mkdir -p build && npx zkasm test/bitwise.zkasm -o build/rom-bitwise.test.json",
"test:comp": "mkdir -p build && npx zkasm test/comp.zkasm -o build/rom-comp.test.json",
"test:utils": "mkdir -p build && npx zkasm test/utils-getLenBytes.zkasm -o build/rom-utils.test.json",
Expand Down
14 changes: 12 additions & 2 deletions tools/parallel-tests-sample/sample.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const path = require('path');
const { newCommitPolsArray } = require('pilcom');
const smMain = require('@0xpolygonhermez/zkevm-proverjs/src/sm/sm_main/sm_main');

const rom = require('../../build/rom.json');
let rom = require('../../build/rom.json');
let stepsN = 2 ** 23;
let counters = false;

const fileCachePil = path.join(__dirname, '../../node_modules/@0xpolygonhermez/zkevm-proverjs/cache-main-pil.json');

Expand All @@ -24,13 +26,21 @@ it(`${nameFile}`, async () => {
}
const pil = JSON.parse(fs.readFileSync(fileCachePil));
const cmPols = newCommitPolsArray(pil);
if (input.gasLimit) {
rom = require(`../../build/rom-${input.gasLimit}.test.json`)
}
if (input.stepsN) {
stepsN = input.stepsN
counters = true;
}
try {
const config = {
debug: true,
debugInfo: {
inputName: path.basename(inputPath),
},
stepsN: 2 ** 23,
stepsN: stepsN,
counters,
};
await smMain.execute(cmPols.Main, input, rom, config);
} catch (err) {
Expand Down