go-ethereum/core/vm/ovm_constants.go

503 lines
313 KiB
Go
Raw Normal View History

Geth OVM Integration (ExecutionManager/StateManager) (#9) * Get basic getStorage/setStorage stubs working * Clean up tests * Add state_manager * Add StateManager set & getStorage * Add state mananger create function * Add get & increment nonce * Add getCodeContractBytecode * Add GetCodeContractHash * Add getCodeContractHash to the state manager * Add associateCodeContract to state manager * Pass the tests * go fmt * Add stateTransition to test with * Fix tests * Test deploying contract with transition state * Call executeTransaction on contract deployment * Added ExecutionManager deployment * Get contract deployments working * Cleanup logging * Get stubbed ExecutionManager working * Get a simple contract to deploy through the ExecutionManager * Refactor simpleAbiEncode * Revert unnecessary changes * Remove comments * Revert changes outside of this PR * Revert changes outside of this PR * Revert changes outside of this PR * Fix broken tests * Move OVM bytecode & ABI into constants * Add crazy printlines * Remove crazy comments * Add a bunch of debug printlns * Add helper fn for applying msgs to the EVM * Update ExecutionManager bytecode * Shim CREATE for EM to use correct addr * Add SimpleStorage test * Add the EM/SM to all new states * Force all txs to be routed through the EM * Remove unused files * Remove unused comments * Increment nonce after failed tx * Add debug statements * Use evm.Time for timestamp * Change EM deployment, fix broken tests, clean up * Add an OVM test & remove printlns * Fix lint errors & remove final printlns * Final cleanup--remove some comments * Limiting Geth to one transaction per block (#3) * Limiting Geth to one transaction per block * Adding TransitionBatchBuilder to build & submit rollup blocks * Adding L1MessageSender to Transaction (#4) * Adding L1MessageSender to Transaction * Adding logic to omit L1MessageSender in encoding / decoding when nil and never use it in hash computation Co-authored-by: ben-chain <ben@pseudonym.party> * Fixing Geth Tests (#6) Fixing broken tests, skipping tests we intentionally break, and configuring CI within Github Actions * Hex Trie -> Binary Trie (#7) *** Changing Hex Trie to Binary Trie *** Note: This changes and/or comments out a bunch of tests, so if things break down the line, this is likely the cause! * Ingest Block Batches (#8) Handling BlockBatches in Geth at `SendBlockBatches` endpoint (eth_sendBlockBatches) Other: * Adding PR template * Adding ability to set timestamp and making blocks use configured timestamp * Adding ability to encode original tx nonce in calldata * Adding L1MessageSender to Contract Creation Txs * Add L1MessageSender to Message * Increment nonce on CREATE failure * Fix bug where evm.Time=0 * Use state dump with hardcoded EM & SM addrs - ExecutionMgr address should always be 0x0000...dead0000 - StateMgr address should always be 0x0000...dead0001 * Move EM deployment into genesis block maker * Update EM contracts to latest version * Update EM to remove events * Fix the OVM tests * Skip an ungodly number of tests * Fix lint errors * Clean up logging * Cleanup more logs * Use local reference to state manager * Rename applyOvmToState(..) * Remove unneeded check * Clean up logging & add EM ABI panic * Add gas metering to SM & small refactor * Update core/vm/state_manager.go Co-authored-by: Kevin Ho <kevinjho1996@gmail.com> Co-authored-by: Mason Fischer <mason@kissr.co> Co-authored-by: Will Meister <william.k.meister@gmail.com> Co-authored-by: ben-chain <ben@pseudonym.party> Co-authored-by: Kevin Ho <kevinjho1996@gmail.com>
2020-08-05 21:00:15 +00:00
package vm
import (
"github.com/ethereum/go-ethereum/common"
)
var (
ExecutionManagerAddress = common.HexToAddress("00000000000000000000000000000000dead0000")
StateManagerAddress = common.HexToAddress("00000000000000000000000000000000dead0001")
WORD_SIZE = 32
)
const ActiveContractStorageSlot = int64(6)
const RawExecutionManagerAbi = `[
{
"inputs": [
{
"internalType": "uint256",
"name": "_opcodeWhitelistMask",
"type": "uint256"
},
{
"internalType": "address",
"name": "_owner",
"type": "address"
},
{
"internalType": "uint256",
"name": "_blockGasLimit",
"type": "uint256"
},
{
"internalType": "bool",
"name": "_overridePurityChecker",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "_activeContract",
"type": "address"
}
],
"name": "ActiveContract",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "_ovmFromAddress",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "_ovmToAddress",
"type": "address"
}
],
"name": "CallingWithEOA",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "_ovmContractAddress",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "_codeContractAddress",
"type": "address"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "_codeContractHash",
"type": "bytes32"
}
],
"name": "CreatedContract",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "bytes",
"name": "_revertMessage",
"type": "bytes"
}
],
"name": "EOACallRevert",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "_ovmContractAddress",
"type": "address"
}
],
"name": "EOACreatedContract",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "_ovmContractAddress",
"type": "address"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "_slot",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "_value",
"type": "bytes32"
}
],
"name": "SetStorage",
"type": "event"
},
{
"constant": false,
"inputs": [
{
"internalType": "uint256",
"name": "_timestamp",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "_queueOrigin",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "_nonce",
"type": "uint256"
},
{
"internalType": "address",
"name": "_ovmEntrypoint",
"type": "address"
},
{
"internalType": "bytes",
"name": "_callBytes",
"type": "bytes"
},
{
"internalType": "uint8",
"name": "_v",
"type": "uint8"
},
{
"internalType": "bytes32",
"name": "_r",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "_s",
"type": "bytes32"
}
],
"name": "executeEOACall",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "uint256",
"name": "_timestamp",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "_queueOrigin",
"type": "uint256"
},
{
"internalType": "address",
"name": "_ovmEntrypoint",
"type": "address"
},
{
"internalType": "bytes",
"name": "_callBytes",
"type": "bytes"
},
{
"internalType": "address",
"name": "_fromAddress",
"type": "address"
},
{
"internalType": "address",
"name": "_l1MsgSenderAddress",
"type": "address"
},
{
"internalType": "bool",
"name": "_allowRevert",
"type": "bool"
}
],
"name": "executeTransaction",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "getL1MessageSender",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getStateManagerAddress",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "addr",
"type": "address"
}
],
"name": "incrementNonce",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "isStaticContext",
"outputs": [],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ovmADDRESS",
"outputs": [],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ovmBlockGasLimit",
"outputs": [],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "ovmCALL",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ovmCALLER",
"outputs": [],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "ovmCREATE",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "ovmCREATE2",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "ovmDELEGATECALL",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ovmEXTCODECOPY",
"outputs": [],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ovmEXTCODEHASH",
"outputs": [],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ovmEXTCODESIZE",
"outputs": [],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ovmGASLIMIT",
"outputs": [],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ovmORIGIN",
"outputs": [],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ovmQueueOrigin",
"outputs": [],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ovmSLOAD",
"outputs": [],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "ovmSSTORE",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "ovmSTATICCALL",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "ovmTIMESTAMP",
"outputs": [],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"internalType": "uint256",
"name": "_nonce",
"type": "uint256"
},
{
"internalType": "address",
"name": "_to",
"type": "address"
},
{
"internalType": "bytes",
"name": "_callData",
"type": "bytes"
},
{
"internalType": "uint8",
"name": "_v",
"type": "uint8"
},
{
"internalType": "bytes32",
"name": "_r",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "_s",
"type": "bytes32"
}
],
"name": "recoverEOAAddress",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]`
// The initial state dump which should be loaded before any new state is created.
const InitialOvmStateDump = "7b22726f6f74223a22222c226163636f756e7473223a7b22307830303030303030303030303030303030303030303030303030303030303030306465616430303030223a7b2262616c616e6365223a2230222c226e6f6e6365223a332c22726f6f74223a2264653263663962373332626233633430376161396634303761326466356162303734646231333232343235383362666363303138366363353563343738393434222c22636f646548617368223a2266653632343035396130353264616662656361666430633437653936353138626135366634353334353039393838636265313133363334623137366636633966222c22636f6465223a2236303830363034303532333438303135363130303130353736303030383066643562353036303034333631303631303138653537363030303335363065303163383036333733353039303634313136313030646535373830363362303136386261333131363130303937353738303633633836343534313631313631303037313537383036336338363435343136313436313033303535373830363364323033343130363134363130333066353738303633643831373865336431343631303332643537383036336662623066373964313436313033333735373631303138653536356238303633623031363862613331343631303265373537383036336264626638633336313436313032663135373830363363333338326430663134363130326662353736313031386535363562383036333733353039303634313436313032393935373830363337376135613632663134363130326133353738303633376165633061393231343631303262663537383036333865303362326431313436313032633935373830363339303538303235363134363130326433353738303633393936643739613531343631303264643537363130313865353635623830363332333263646565363131363130313462353738303633343964363566663931313631303132353537383036333439643635666639313436313032356635373830363334626138373436663134363130323639353738303633346336643763383431343631303237333537383036333563386530313239313436313032376435373631303138653536356238303633323332636465653631343631303231623537383036333238646362326130313436313032346235373830363334356539376464623134363130323535353736313031386535363562383036333033356132303035313436313031393335373830363331313462663261363134363130316231353738303633313233303230333031343631303165313537383036333136393032643537313436313031666435373830363332303136306633613134363130323037353738303633323039363632303831343631303231313537356236303030383066643562363130313962363130333431353635623630343035313631303161383931393036313333613035363562363034303531383039313033393066333562363130316362363030343830333630333631303163363931393038313031393036313261633535363562363130333535353635623630343035313631303164383931393036313333613035363562363034303531383039313033393066333562363130316662363030343830333630333631303166363931393038313031393036313263316335363562363130356336353635623030356236313032303536313037336335363562303035623631303230663631303831633536356230303562363130323139363130383331353635623030356236313032333536303034383033363033363130323330393139303831303139303631326135623536356236313039303535363562363034303531363130323432393139303631333361303536356236303430353138303931303339306633356236313032353336313039623835363562303035623631303235643631306162643536356230303562363130323637363130626132353635623030356236313032373136313064626635363562303035623631303237623631306464343536356230303562363130323937363030343830333630333631303239323931393038313031393036313262363635363562363130656533353635623030356236313032613136313131373335363562303035623631303262643630303438303336303336313032623839313930383130313930363132393736353635623631313235333536356230303562363130326337363131333233353635623030356236313032643136313134363335363562303035623631303264623631313532343536356230303562363130326535363131353335353635623030356236313032656636313136313535363562303035623631303266393631313632613536356230303562363130333033363131363366353635623030356236313033306436313136663335363562303035623631303331373631313732363536356236303430353136313033323439313930363133336130353635623630343035313830393130333930663335623631303333353631313932333536356230303562363130333366363131396437353635623030356236303030383036313033346336313162333135363562393035303830393135303530393035363562363030303630363036303039363034303531393038303832353238303630323030323630323030313832303136303430353238303135363130333865353738313630323030313562