Skip to content

Commit

Permalink
safe range max counters
Browse files Browse the repository at this point in the history
  • Loading branch information
krlosMata committed Jan 13, 2023
1 parent 38fe011 commit 08ceb9c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
23 changes: 17 additions & 6 deletions main/constants.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,28 @@ CONST %SSTORE_SET_GAS_REDUCED = 19900 ; sstore gas cost reduced base_dynamic_gas
CONST %SSTORE_RESET_GAS = 2900
CONST %SSTORE_RESET_GAS_REDUCED = 2800 ; sstore update gas cost reduced base_dynamic_gas(original_value == 0) - base_dynamic_gas(100)
CONST %SSTORE_CLEARS_SCHEDULE = 15000

; COUNTERS
CONST %MIN_STEPS_FINISH_BATCH = 200 ; min steps to finish tx
CONST %TOTAL_STEPS = 2**23
CONST %MAX_CNT_STEPS = %TOTAL_STEPS - %MIN_STEPS_FINISH_BATCH

CONST %MAX_CNT_ARITH = %TOTAL_STEPS / 32
CONST %MAX_CNT_BINARY = %TOTAL_STEPS / 16
CONST %MAX_CNT_MEM_ALIGN = %TOTAL_STEPS / 32
CONST %MAX_CNT_KECCAK_F = (%TOTAL_STEPS / 155286) * 44
CONST %MAX_CNT_PADDING_PG = (%TOTAL_STEPS / 56)
CONST %MAX_CNT_POSEIDON_G = (%TOTAL_STEPS / 30)
CONST %MAX_CNT_ARITH_LIMIT = %TOTAL_STEPS / 32
CONST %MAX_CNT_BINARY_LIMIT = %TOTAL_STEPS / 16
CONST %MAX_CNT_MEM_ALIGN_LIMIT = %TOTAL_STEPS / 32
CONST %MAX_CNT_KECCAK_F_LIMIT = (%TOTAL_STEPS / 155286) * 44
CONST %MAX_CNT_PADDING_PG_LIMIT = (%TOTAL_STEPS / 56)
CONST %MAX_CNT_POSEIDON_G_LIMIT = (%TOTAL_STEPS / 30)

CONST %SAFE_RANGE = 20 ; safe guard counters to not take into account (%RANGE = 1 / SAFE_RANGE)

CONST %MAX_CNT_ARITH = %MAX_CNT_ARITH_LIMIT - (%MAX_CNT_ARITH_LIMIT / %SAFE_RANGE)
CONST %MAX_CNT_BINARY = %MAX_CNT_BINARY_LIMIT - (%MAX_CNT_BINARY_LIMIT / %SAFE_RANGE)
CONST %MAX_CNT_MEM_ALIGN = %MAX_CNT_MEM_ALIGN_LIMIT - (%MAX_CNT_MEM_ALIGN_LIMIT / %SAFE_RANGE)
CONST %MAX_CNT_KECCAK_F = %MAX_CNT_KECCAK_F_LIMIT - (%MAX_CNT_KECCAK_F_LIMIT / %SAFE_RANGE)
CONST %MAX_CNT_PADDING_PG = %MAX_CNT_PADDING_PG_LIMIT - (%MAX_CNT_PADDING_PG_LIMIT / %SAFE_RANGE)
CONST %MAX_CNT_POSEIDON_G = %MAX_CNT_POSEIDON_G_LIMIT - (%MAX_CNT_POSEIDON_G_LIMIT / %SAFE_RANGE)

CONST %MIN_CNT_KECCAK_BATCH = 1 ; minimum necessary keccaks to compute global hash

; ETHEREUM CONSTANTS
Expand Down
5 changes: 2 additions & 3 deletions main/opcodes/arithmetic.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @link [Link EVM behaviour --> evm.codes?]
* @zk-counters
* - 1 binary
* - 100 steps
* - 20 steps
* @process-opcode
* - stack input: [a, b]
* - stack output: [a + b]
Expand All @@ -30,8 +30,7 @@ opADD:
/**
* @link [https://www.evm.codes/#02?fork=berlin]
* @zk-counters
* - 1 arith
* - 100 steps
* - 20 steps
* @process-opcode
* - stack input: [a, b]
* - stack output: [a * b]
Expand Down

0 comments on commit 08ceb9c

Please sign in to comment.