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

remove unnecessary checks #202

Merged
merged 1 commit into from
Dec 14, 2022
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: 2 additions & 1 deletion main/constants.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ CONST %MIN_CNT_KECCAK_BATCH = 1 ; minimum necessary keccaks to compute global ha

; ETHEREUM CONSTANTS
CONSTL %MAX_NONCE = 0xffffffffffffffffn
CONSTL %MAX_UINT_256 = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn
CONSTL %MAX_UINT_256 = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn
CONST %CODE_SIZE_LIMIT = 0x6000
6 changes: 2 additions & 4 deletions main/opcodes/block.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ opBLOCKHASH:
$ => E :SLOAD
; store result value in the stack
E :MSTORE(SP++); [hash(E) => SP]
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
; check stack overflow
; continue read bytecode
:JMP(readCode)

; Handle when is asking for the hash of a not computed batch, return 0
opBLOCKHASHzero:
0 :MSTORE(SP++); [0 => SP]
; check stack overflow
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
; continue read bytecode
:JMP(readCode)

/**
Expand Down
19 changes: 7 additions & 12 deletions main/opcodes/calldata-returndata-code.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
; recover previous stack pointer
C => SP
B :MSTORE(SP++); [data(offset) => SP]
; check stack overflow
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
; continue read bytecode
:JMP(readCode)

opCALLDATALOAD2:
Expand All @@ -58,14 +57,12 @@ opCALLDATALOAD2:
; recover SP
C => SP
B + A :MSTORE(SP++); [data(offset) => SP]
; check stack overflow
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
; continue read bytecode
:JMP(readCode)

CALLDATALOADreturn0:
0 :MSTORE(SP++); [0 => SP]
; check stack overflow
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
; continue read bytecode
:JMP(readCode)

/**
Expand Down Expand Up @@ -214,7 +211,7 @@ opCALLDATACOPYfinal:
:CALL(SHLarith); in: [A: value, D: #bytes to left shift] out: [A: shifted result]
$ => SP :MLOAD(SPw)
$ => C :MLOAD(SP); [size => C]
; point no next memoryn slot
; point to next memory slot
B + 1 => SP
C - 32 + D => D
D :JMPN(opCALLDATACOPYxor)
Expand Down Expand Up @@ -338,7 +335,6 @@ opCODECOPY:
%MAX_CNT_BINARY - CNT_BINARY - 32 :JMPN(outOfCountersBinary)
%MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)


; check out-of-gas
GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
;${3*((E+31)/32)}
Expand All @@ -364,6 +360,7 @@ opCODECOPY:
$ => B :MLOAD(bytecodeLength)
$ :LT, JMPC(opCODECOPY2)
B => A

opCODECOPY2:
; init vars for copy the code
A => HASHPOS
Expand Down Expand Up @@ -448,8 +445,7 @@ opEXTCODESIZE:
0 => C
$ => A :SLOAD
A :MSTORE(SP++); [size => SP]
; check stack overflow
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
; continue read bytecode
:JMP(readCode)

; read hash smt
Expand Down Expand Up @@ -755,6 +751,5 @@ opEXTCODEHASH:
0 => C
$ => A :SLOAD
A :MSTORE(SP++); [hash => SP]
; check stack overflow
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
; continue read bytecode
:JMP(readCode)
4 changes: 2 additions & 2 deletions main/opcodes/comparison.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ opNOT:

0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn => B ; 2**226 - 1 =>
$ => A :XOR,MSTORE(SP++) ; [ NOT a => SP]
; check stack overflow
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)

; continue read bytecode
:JMP(readCode)

/**
Expand Down
5 changes: 2 additions & 3 deletions main/opcodes/context-information.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ opBALANCE:
; balance in D
$ => D :SLOAD
D :MSTORE(SP++); [balance(D) => SP]
; check stack overflow
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
:CALL(isColdAddress); in: [A: address] out: [D: 0 if warm, 1 if cold]
; check out-of-gas
GAS - %WARM_STORGE_READ_GAS - D * %COLD_ACCOUNT_ACCESS_COST_RED => GAS :JMPN(outOfGas)
:JMP(readCode)
; continue read bytecode
:JMP(readCode)

/**
* @link [https://www.evm.codes/#32?fork=berlin]
Expand Down
22 changes: 1 addition & 21 deletions main/opcodes/create-terminate-context.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@ opSTOPend:
$ => PC :MLOAD(lastPC)
; store stack output
D :MSTORE(SP++)
; check stack overflow
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
; decrease depth
$ => A :MLOAD(depth)
A - 1 :MSTORE(depth)
:JMP(readCode)

; // TODO Check with DElEGATE CALL txDestAddr/txSrcAddr ( same as other calls)
; // TODO check revert create
/**
* @link [https://www.evm.codes/#f0?fork=berlin]
* @zk-counters
Expand Down Expand Up @@ -535,28 +531,22 @@ opRETURNend:
$ => SP :MLOAD(lastSP)
$ => PC :MLOAD(lastPC)
1 :MSTORE(SP++); [1 => SP]
; check stack overflow
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
; decrease depth
$ => A :MLOAD(depth)
A - 1 :MSTORE(depth)
:JMP(readCode)


opRETURNdeploy:
; TODO check what does return? what assures returned_code_size is correct?
; code size limit = 0x6000
0x6000 - C :JMPN(invalidCodeSize)
%CODE_SIZE_LIMIT - C :JMPN(invalidCodeSize)
;code_deposit_cost = 200 * returned_code_size
GAS - %RETURN_GAS_COST * C => GAS :JMPN(outOfGas)
; check if first context
$ => B :MLOAD(originCTX)
0 - B :JMPN(opRETURNcreate)
:JMP(endDeploy)

; TODO: not in RETURN, but in CREATE process
opRETURNcreate:

; checks zk-counters
%MAX_CNT_ARITH - CNT_ARITH - 192 :JMPN(outOfCountersArith)
%MAX_CNT_BINARY - CNT_BINARY - 192 :JMPN(outOfCountersBinary)
Expand Down Expand Up @@ -604,8 +594,6 @@ opRETURNcreateEnd:
$ => SP :MLOAD(lastSP)
$ => PC :MLOAD(lastPC)
A :MSTORE(SP++); [createContractAddress(A) => SP]
; check stack overflow
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
; decrease depth
$ => A :MLOAD(depth)
A - 1 :MSTORE(depth)
Expand Down Expand Up @@ -720,8 +708,6 @@ opDELEGATECALLend:
:CALL(checkpointTouched)
:JMP(txType)

; // TODO Check with DElEGATE CALL txDestAddr/txSrcAddr ( same as other calls)
; // TODO check revert create
/**
* @link [https://www.evm.codes/#f5?fork=berlin]
* @zk-counters
Expand Down Expand Up @@ -1040,14 +1026,11 @@ opREVERTend:
$ => SP :MLOAD(lastSP)
$ => PC :MLOAD(lastPC)
0 :MSTORE(SP++); [0 => SP]
; check stack overflow
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
; decrease depth
$ => A :MLOAD(depth)
A - 1 :MSTORE(depth)
:JMP(readCode)

; // TODO: handle if depth is over 0
; SELFDESTRUCT is deprecated and EIP-4758 is implemented: https://eips.ethereum.org/EIPS/eip-4758
; SELFDESTRUCT is now SENDALL
/**
Expand All @@ -1061,7 +1044,6 @@ opREVERTend:
* - stack output: none
*/
opSENDALL:

; checks zk-counters
%MAX_CNT_BINARY - CNT_BINARY - 10 :JMPN(outOfCountersBinary)
%MAX_CNT_POSEIDON_G - CNT_POSEIDON_G - 2040 :JMPN(outOfCountersPoseidon)
Expand Down Expand Up @@ -1145,8 +1127,6 @@ opSENDALLend:
$ => SP :MLOAD(lastSP)
$ => PC :MLOAD(lastPC)
D :MSTORE(SP++); [output => SP]
; check stack overflow
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
; decrease depth
$ => A :MLOAD(depth)
A - 1 :MSTORE(depth)
Expand Down
3 changes: 1 addition & 2 deletions main/opcodes/crypto.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,5 @@ opSHA3End:
$ => A :HASHKDIGEST(E)
; store hash
A :MSTORE(SP++); [hash(A) => SP]
; check stack overflow
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
; continue read bytecode
:JMP(readCode)
2 changes: 0 additions & 2 deletions main/opcodes/flow-control.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ opJUMPI:
; Check PC is a JUMPDEST
:JMP(checkJumpDest)

; TODO check do not overflow
checkJumpDest:
; if it is a deploy we have to check the data from the calldata (not the bytecode)
$ => A :MLOAD(isCreateContract)
Expand Down Expand Up @@ -134,7 +133,6 @@ opPC:
* - stack output: none
*/
opJUMPDEST:

; checks zk-counters
%MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)

Expand Down
2 changes: 1 addition & 1 deletion main/opcodes/logs.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ opSaveTopicsLoop:

A - 1 :JMPN(readCode)
; check stack underflow
SP - 1 => SP :JMPN(stackUnderflow)
SP - 1 => SP
; check out-of-gas
GAS - %LOG_TOPIC_GAS => GAS :JMPN(outOfGas)
$ => C :MLOAD(SP) ; [topic => C]
Expand Down
20 changes: 1 addition & 19 deletions main/opcodes/stack-operations.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,9 @@ opSWAP1:
$ => B :MLOAD(SP); [value_to_swap_b => B]
; store swapped value a
A :MSTORE(SP++); [swapped_value_a => SP]
; check stack overflow
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
; store swapped value b
B :MSTORE(SP++); [swapped_value_b => SP]
; check stack overflow
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
; continue read bytecode
:JMP(readCode)

opSWAP2:
Expand All @@ -546,7 +543,6 @@ opSWAP2:
A :MSTORE(SP)
SP + 2 => SP
B :MSTORE(SP++)
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
:JMP(readCode)

opSWAP3:
Expand All @@ -562,7 +558,6 @@ opSWAP3:
A :MSTORE(SP)
SP + 3 => SP
B :MSTORE(SP++)
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
:JMP(readCode)

opSWAP4:
Expand All @@ -578,7 +573,6 @@ opSWAP4:
A :MSTORE(SP)
SP + 4 => SP
B :MSTORE(SP++)
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
:JMP(readCode)

opSWAP5:
Expand All @@ -594,7 +588,6 @@ opSWAP5:
A :MSTORE(SP)
SP + 5 => SP
B :MSTORE(SP++)
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
:JMP(readCode)

opSWAP6:
Expand All @@ -610,7 +603,6 @@ opSWAP6:
A :MSTORE(SP)
SP + 6 => SP
B :MSTORE(SP++)
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
:JMP(readCode)

opSWAP7:
Expand All @@ -626,7 +618,6 @@ opSWAP7:
A :MSTORE(SP)
SP + 7 => SP
B :MSTORE(SP++)
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
:JMP(readCode)

opSWAP8:
Expand All @@ -642,7 +633,6 @@ opSWAP8:
A :MSTORE(SP)
SP + 8 => SP
B :MSTORE(SP++)
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
:JMP(readCode)

opSWAP9:
Expand All @@ -658,7 +648,6 @@ opSWAP9:
A :MSTORE(SP)
SP + 9 => SP
B :MSTORE(SP++)
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
:JMP(readCode)

opSWAP10:
Expand All @@ -674,7 +663,6 @@ opSWAP10:
A :MSTORE(SP)
SP + 10 => SP
B :MSTORE(SP++)
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
:JMP(readCode)

opSWAP11:
Expand All @@ -690,7 +678,6 @@ opSWAP11:
A :MSTORE(SP)
SP + 11 => SP
B :MSTORE(SP++)
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
:JMP(readCode)

opSWAP12:
Expand All @@ -706,7 +693,6 @@ opSWAP12:
A :MSTORE(SP)
SP + 12 => SP
B :MSTORE(SP++)
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
:JMP(readCode)

opSWAP13:
Expand All @@ -722,7 +708,6 @@ opSWAP13:
A :MSTORE(SP)
SP + 13 => SP
B :MSTORE(SP++)
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
:JMP(readCode)

opSWAP14:
Expand All @@ -738,7 +723,6 @@ opSWAP14:
A :MSTORE(SP)
SP + 14 => SP
B :MSTORE(SP++)
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
:JMP(readCode)

opSWAP15:
Expand All @@ -754,7 +738,6 @@ opSWAP15:
A :MSTORE(SP)
SP + 15 => SP
B :MSTORE(SP++)
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
:JMP(readCode)

opSWAP16:
Expand All @@ -770,7 +753,6 @@ opSWAP16:
A :MSTORE(SP)
SP + 16 => SP
B :MSTORE(SP++)
%CALLDATA_OFFSET - SP :JMPN(stackOverflow)
:JMP(readCode)

/**
Expand Down
Loading