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

endContractAddress label can be re-used with create2 #168

Merged
merged 2 commits into from
Nov 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
16 changes: 3 additions & 13 deletions main/process-tx.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,7 @@ nonce1byte:

nonceIs0:
0x80 :HASHK(E)

endContractAddress:
; end contract address hash and get the 20 first bytes
HASHPOS :HASHKLEN(E)
$ => A :MLOAD(cntKeccakPreProcess)
%MAX_CNT_KECCAK_F - CNT_KECCAK_F - A - 1 :JMPN(outOfCountersKeccak)
$ => A :HASHKDIGEST(E)
:CALL(maskAddress) ; Mask address to 20 bytes
A :MSTORE(createContractAddress)
A :MSTORE(txDestAddr)
A :MSTORE(storageAddr)
; TODO: Add check CREATE or deployment with constructor reverted
:JMP(deploy)
:JMP(endContractAddress)

;; compute new contract address as CREATE2 spec: keccak256(0xff ++ address ++ salt ++ keccak256(init_code))[12:] (https://eips.ethereum.org/EIPS/eip-1014)
create2:
Expand Down Expand Up @@ -341,6 +329,8 @@ create2end:
B :HASHK(E)
32 => D
C :HASHK(E)

endContractAddress:
HASHPOS :HASHKLEN(E)

; Check keccak counters
Expand Down
12 changes: 6 additions & 6 deletions main/vars.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ VAR GLOBAL batchSR ; State root before processing any transaction
VAR GLOBAL txCount ; Current transaction count

VAR GLOBAL touchedSR ; touched tree root
VAR GLOBAL numTopics ; number of topics depending on LOG opcode call
VAR GLOBAL SPw ; aux variable to store Stack poimnter 'SP'
VAR GLOBAL hashContractTxDestAddr ; state-tree hash bytecode leaf value of the 'to' address
VAR GLOBAL auxSR ; auxiliaty variable. Temporary state root
VAR GLOBAL txRLPLength ; transaction RLP list length
VAR GLOBAL txDataRead ; aux varible to check transaction 'data' left that needs to be read

VAR CTX txRLPLength ; transaction RLP list length
VAR CTX txGasLimit ; transaction parameter: 'gas limit'
VAR CTX txDestAddr ; transaction parameter: 'to'
VAR CTX storageAddr ; address which the storage will be modified
Expand All @@ -62,24 +67,20 @@ VAR CTX createContractAddress ; address computed of a new contract
VAR CTX lengthNonce ; 'nonce' length used when computing a new contract address
VAR CTX gasRefund ; keeps track of the transaction gas refund
VAR CTX initSR ; state-tree once the initial upfront cost is substracted and nonce is increased
VAR CTX txDataRead ; aux varible to check transaction 'data' left that needs to be read
VAR CTX memLength ; current memory size
VAR CTX lastMemLength ; length of bytes to copy to memory
VAR CTX lastMemOffset ; offset to copy to memory
VAR CTX auxSR ; auxiliaty variable. Temporary state root
VAR CTX retCallOffset ; initial pointer to begin store the return data
VAR CTX retCallLength ; size of the return data
VAR CTX retDataOffset ; pointer to previous context return data offset
VAR CTX retDataLength ; pointer to previous context return data length
VAR CTX retDataCTX ; pointer to context where the return data is stored
VAR CTX argsOffsetCall ; pointer to the init slot where the calldata begins
VAR CTX hashContractTxDestAddr ; state-tree hash bytecode leaf value of the 'to' address
VAR CTX bytecodeLength ; state-tree length bytecode leaf value of the 'to' address
VAR CTX contractHashId ; hashP address used to store contract bytecode
VAR CTX originCTX ; The source context of the current context
VAR CTX lastSP ; Last stack pointer used of the previous context
VAR CTX lastPC ; Last program counter used of the previous context
VAR CTX numTopics ; number of topics depending on LOG opcode call
VAR CTX isStaticCall ; flag to determine if a new context comes from a STATICCALL opcode
VAR CTX isCreate ; flag to determine if a new context comes from a CREATE opcode
VAR CTX isDelegateCall ; flag to determine if a new context comes from a DELEGATECALL opcode
Expand All @@ -88,6 +89,5 @@ VAR CTX salt ; CREATE2 parameter 'salt' used to compute new contract address
VAR CTX gasCTX ; remaining gas in the origin CTX when a new context is created
VAR CTX sigDataSize ; hash position for the ethereum transaction hash
VAR CTX dataStarts; hash position where de transaction 'data' starts in the batchHashData
VAR CTX SPw ; aux variable to store Stack poimnter 'SP'
VAR CTX isPreEIP155 ; flag to check if the current tx is legacy, previous to Spurious Dragon (EIP-155)
VAR CTX initTouchedSR ; touched root once a new context begins