Skip to content

Extract StateManager from ExecutionManager#132

Merged
karlfloersch merged 16 commits intomasterfrom
YAS-345/GoVM/ExtractStateManager
Jun 9, 2020
Merged

Extract StateManager from ExecutionManager#132
karlfloersch merged 16 commits intomasterfrom
YAS-345/GoVM/ExtractStateManager

Conversation

@masonforest
Copy link
Copy Markdown

Description

In order to intercept calls to the State Manager, we have to first pull it out into a separate contract. This will allow us to easily replace the State Manager functionality with low level calls to Geth.

Metadata

Fixes

Contributing Agreement

Copy link
Copy Markdown
Contributor

@karlfloersch karlfloersch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made one note but otherwise this looks great! That said, we probably also want to be careful with merging this immediately because we've been merging Synthetix changes into master & definitely don't want to make a change like this to our Synthetix node. Tomorrow we can just decide that we'll push Synthetix changes to a synthetix branch or vice versa.

Anyway exciting progress!

* @param _ovmContractInitcode The bytecode of the contract to be deployed
* @return the codeContractAddress.
*/
function deployCodeContract(bytes memory _ovmContractInitcode) public returns(address codeContractAddress) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooo so this function unfortunately needs to be a little more complex. Instead of deployCodeContract(_ovmContractInitcode) what we really need is deployContract(_ovmContractAddress, _ovmContractInitcode)

This function will also need to inherit the logic from here: https://github.com/ethereum-optimism/optimism-monorepo/blob/c5263562d165495e3437d25e83f3a808d1f395e3/packages/ovm/src/contracts/ExecutionManager.sol#L586-L595 where we associate a code contract with it.

The reason is we want to be able to intercept this call and actually deploy a contract (with the initcode) to the Geth state at the address which the ExecutionManager wants us to deploy it to.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yep! Done!

Copy link
Copy Markdown
Collaborator

@ben-chain ben-chain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM 🚢

Left some small comments here and there, but everything seems in order. Pleasantly shocked by how little an effect this had on things like tests and the full node!!!

Comment on lines +270 to +276
const stateManagerAddress = await executionManager.getStateManagerAddress()
const stateManager = new Contract(
stateManagerAddress,
StateManager.abi,
wallet
)
const nonce = await stateManager.getOvmContractNonce(wallet.address)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I count 5 of this exact same code block--might be worth pulling into a getStateManager helper or before if doable.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe it's getNonce, not getStateManager

Comment on lines +108 to +114
const stateManagerAddress = await executionManager.getStateManagerAddress()
const stateManager = new Contract(
stateManagerAddress,
StateManager.abi,
wallet
)
const nonce = await stateManager.getOvmContractNonce(wallet.address)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting this is the same code block as above

Comment on lines +76 to +82
const stateManagerAddress = await executionManager.getStateManagerAddress()
const stateManager = new Contract(
stateManagerAddress,
StateManager.abi,
wallet
)
const nonce = await stateManager.getOvmContractNonce(wallet.address)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same code block

// Safety check the runtime bytecode -- unless the overrideSafetyChecker flag is set to true
if (!overrideSafetyChecker && !safetyChecker.isBytecodeSafe(codeContractBytecode)) {
// Contract runtime bytecode is not safe.
address codeContractAddress = stateManager.deployContract(_newOvmContractAddress, _ovmInitcode);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm I'm still weirded out by doing purity checking in the SM as it feels much more "execution-ey". However we have recorded the need to revisit this for pre-deployment of code contracts so probably fine for now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh I have the opposite feeling wrt purity checking lol but will of course see what happens as the partial state manager is implemented


address ZERO_ADDRESS = 0x0000000000000000000000000000000000000000;

// bitwise right shift 28 * 8 bits so the 4 method ID bytes are in the right-most bytes
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure where this came from, would delete or move if you know off the top where it originally was

constructor(uint256 _opcodeWhitelistMask, bool _overrideSafetyChecker) public {
// Set override safety checker flag
overrideSafetyChecker = _overrideSafetyChecker;
// Set the safety checker address -- NOTE: we assume this contract is deployed by the ExecutionManager
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this NOTE is outdated as we appear to be deploying it right below.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry this is just a bad comment. "this" refers to the FullStateManager not the SafetyChecker -- updating to:

        // Set the safety checker address -- NOTE: `msg.sender` is used as EM address because we assume
        // the FullStateManager is deployed by the ExecutionManager

Note I'm not going to do this BS for the partial state manager. We really gotta refactor these contracts so they don't deploy their dependences & I'ma make sure to do that.

* @return The bytes32 value stored at the particular slot.
*/
function getStorage(address _ovmContractAddress, bytes32 _slot) internal view returns(bytes32) {
function getStorage(address _ovmContractAddress, bytes32 _slot) public view returns(bytes32) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be able to limit some of these functions to being external which would be a small performance improvement that might add up. external is cheaper because it uses the calldata directly instead of loading into memory (which it needs to do if it can be called internally)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice catch

// Storage
function getStorage(address _ovmContractAddress, bytes32 _slot) internal view returns(bytes32);
function setStorage(address _ovmContractAddress, bytes32 _slot, bytes32 _value) internal;
function getStorage(address _ovmContractAddress, bytes32 _slot) public view returns(bytes32);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above on all of these methods WRT making external when possible.

bytes memory _ovmContractInitcode
) public returns(address codeContractAddress) {
// Safety check the initcode, unless the overrideSafetyChecker flag is set to true
if (!overrideSafetyChecker && !safetyChecker.isBytecodeSafe(_ovmContractInitcode)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not within the scope of this PR, but at some point, think we'll need to pull out the safety checking into a separate step since the gas cost of safety checking is in the 5-10m range for large contracts

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah 100%. This'll have to be added into the partial state manager

Copy link
Copy Markdown
Contributor

@karlfloersch karlfloersch Jun 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am looking to deprecate this full state manager once we get to a point where we can deprecate the rollup-full-node cuz we won't need it anymore for L2 once we're in Geth

Comment on lines +181 to +184
if (!overrideSafetyChecker && !safetyChecker.isBytecodeSafe(codeContractBytecode)) {
// Contract runtime bytecode is not pure.
return ZERO_ADDRESS;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^same comment as above

@karlfloersch karlfloersch merged commit 4075556 into master Jun 9, 2020
@karlfloersch karlfloersch deleted the YAS-345/GoVM/ExtractStateManager branch November 3, 2020 15:47
snario pushed a commit that referenced this pull request Apr 14, 2021
protolambda added a commit to protolambda/optimism that referenced this pull request May 1, 2022
…node

ref impl: main node process (connect with RPC, start drivers, handle shutdown)
ClaytonNorthey92 added a commit to hemilabs/optimism that referenced this pull request Jun 27, 2024
b5b564702 popm/wasm: add wasm-opt target to optimise wasm binary (ethereum-optimism#146)
27a5081e3 tbc: allow seeds to be overwritten (ethereum-optimism#158)
18afbc403 Fix missing panic (ethereum-optimism#156)
05cee0afb tbc: remove height as the terminal condition for indexers (ethereum-optimism#152)
4402060d6 Use hemilabs/websocket fork of nhooyr.io/websocket (ethereum-optimism#153)
3df5001c4 Add initial CODEOWNERS file (ethereum-optimism#149)
a4685a57f popm/wasm: improve and tidy up Go code (ethereum-optimism#144)
41a0009c1 Add forking detection to TBC (ethereum-optimism#101)
bbeed8bac ignore ulimits in tbc when on localnet (ethereum-optimism#142)
4e1914cc6 Stopgap to re-fetch blocks with no children (ethereum-optimism#131)
12eefff06 e2e: fix issues detected by staticcheck (ethereum-optimism#134)
80153372f Add more documentation for TBC and related RPC protocol (ethereum-optimism#86)
723b63704 bfg: fix issues reported by staticcheck (ethereum-optimism#132)
509fb1be6 electrumx: fix unhandled error in NewJSONRPCRequest (ethereum-optimism#133)
b19af1e1f hemictl: use sort.Strings(...) instead of sort.Sort(sort.StringSlice(...)) (S1032) (ethereum-optimism#123)
cf7c570f9 popmd: remove unused 'handle' func and return err in connectBFG (ethereum-optimism#124)
fa2a4c4de ci: fix bug that makes version type always 'unstable' (ethereum-optimism#125)
ddc39655a ci: use org DOCKERHUB_TOKEN secret (ethereum-optimism#128)
6457d16f5 bfgd: drop btc_blocks_can refresh triggers for l2_keystones/pop_basis (ethereum-optimism#120)
2b3c096bd popm: simplify receivedKeystones variable in tests (ethereum-optimism#116)
6140bbf24 tbc: move RPC tests to a separate test file (ethereum-optimism#114)
c76571ff0 Add configuration option for static fees to web PoP miner (ethereum-optimism#119)
233817e65 popm: use simple conversion instead of unnecessary fmt.Sprintf (S1025) (ethereum-optimism#115)
2879f5fa7 e2e: improve name for variable with type `time.Duration` (ST1011) (ethereum-optimism#117)
4f31965e6 database,e2e: remove use of deprecated io/ioutil (SA1019) (ethereum-optimism#118)
e9e090696 tbc: do not recreate outpoint for ScriptHashByOutpoint. (ethereum-optimism#109)
52eefb136 ignore l2 keystones notifications in tests (ethereum-optimism#112)
eb607994c Sync Docker image environment variables with daemon configs (ethereum-optimism#111)
57281bc5d added a way to monitor and sanity-test localnet (ethereum-optimism#106)
ea1a1c94c bfgd: fix loops unconditionally exited after one interation (SA4004) (ethereum-optimism#108)
29f116fb4 Add pprof http server to daemons (ethereum-optimism#105)
18a315d7e Added README for generating forks in BTC regtest for TBC fork resolution testing (ethereum-optimism#100)
55b8f52cb more robust nextPort (ethereum-optimism#103)
48f8b293f tbcapi: use reverse byte order for hashes in serialised, tidy up (ethereum-optimism#104)
b7e9f5ecb restart initialblocks on-failure (ethereum-optimism#102)
f9d52d423 Update required Go version to v1.22.2 (ethereum-optimism#96)
f6808aa5b Fix op-proposer op-node dependency condition (fixes ethereum-optimism#98) (ethereum-optimism#99)
a882529e8 Kill all pending block downloads if a peer fails (ethereum-optimism#95)
eb66345e1 e2e: tidy up docker-compose file (ethereum-optimism#81)
34766f725 Track pending blocks with ttl package (ethereum-optimism#90)
6ed3eb88b Added configurable fee-per-vB to PoP Miner (ethereum-optimism#91)
509e31fbc Replace os.Kill with syscall.SIGTERM in signal.Notify calls (ethereum-optimism#87)

git-subtree-dir: heminetwork
git-subtree-split: b5b564702e8d3bedcdf0e0a52c22e383d7fd4dbe
OptimismBot pushed a commit that referenced this pull request Nov 21, 2024
blockchaindevsh pushed a commit to blockchaindevsh/optimism that referenced this pull request Dec 19, 2024
ClaytonNorthey92 added a commit to hemilabs/optimism that referenced this pull request Apr 4, 2025
b5b564702 popm/wasm: add wasm-opt target to optimise wasm binary (ethereum-optimism#146)
27a5081e3 tbc: allow seeds to be overwritten (ethereum-optimism#158)
18afbc403 Fix missing panic (ethereum-optimism#156)
05cee0afb tbc: remove height as the terminal condition for indexers (ethereum-optimism#152)
4402060d6 Use hemilabs/websocket fork of nhooyr.io/websocket (ethereum-optimism#153)
3df5001c4 Add initial CODEOWNERS file (ethereum-optimism#149)
a4685a57f popm/wasm: improve and tidy up Go code (ethereum-optimism#144)
41a0009c1 Add forking detection to TBC (ethereum-optimism#101)
bbeed8bac ignore ulimits in tbc when on localnet (ethereum-optimism#142)
4e1914cc6 Stopgap to re-fetch blocks with no children (ethereum-optimism#131)
12eefff06 e2e: fix issues detected by staticcheck (ethereum-optimism#134)
80153372f Add more documentation for TBC and related RPC protocol (ethereum-optimism#86)
723b63704 bfg: fix issues reported by staticcheck (ethereum-optimism#132)
509fb1be6 electrumx: fix unhandled error in NewJSONRPCRequest (ethereum-optimism#133)
b19af1e1f hemictl: use sort.Strings(...) instead of sort.Sort(sort.StringSlice(...)) (S1032) (ethereum-optimism#123)
cf7c570f9 popmd: remove unused 'handle' func and return err in connectBFG (ethereum-optimism#124)
fa2a4c4de ci: fix bug that makes version type always 'unstable' (ethereum-optimism#125)
ddc39655a ci: use org DOCKERHUB_TOKEN secret (ethereum-optimism#128)
6457d16f5 bfgd: drop btc_blocks_can refresh triggers for l2_keystones/pop_basis (ethereum-optimism#120)
2b3c096bd popm: simplify receivedKeystones variable in tests (ethereum-optimism#116)
6140bbf24 tbc: move RPC tests to a separate test file (ethereum-optimism#114)
c76571ff0 Add configuration option for static fees to web PoP miner (ethereum-optimism#119)
233817e65 popm: use simple conversion instead of unnecessary fmt.Sprintf (S1025) (ethereum-optimism#115)
2879f5fa7 e2e: improve name for variable with type `time.Duration` (ST1011) (ethereum-optimism#117)
4f31965e6 database,e2e: remove use of deprecated io/ioutil (SA1019) (ethereum-optimism#118)
e9e090696 tbc: do not recreate outpoint for ScriptHashByOutpoint. (ethereum-optimism#109)
52eefb136 ignore l2 keystones notifications in tests (ethereum-optimism#112)
eb607994c Sync Docker image environment variables with daemon configs (ethereum-optimism#111)
57281bc5d added a way to monitor and sanity-test localnet (ethereum-optimism#106)
ea1a1c94c bfgd: fix loops unconditionally exited after one interation (SA4004) (ethereum-optimism#108)
29f116fb4 Add pprof http server to daemons (ethereum-optimism#105)
18a315d7e Added README for generating forks in BTC regtest for TBC fork resolution testing (ethereum-optimism#100)
55b8f52cb more robust nextPort (ethereum-optimism#103)
48f8b293f tbcapi: use reverse byte order for hashes in serialised, tidy up (ethereum-optimism#104)
b7e9f5ecb restart initialblocks on-failure (ethereum-optimism#102)
f9d52d423 Update required Go version to v1.22.2 (ethereum-optimism#96)
f6808aa5b Fix op-proposer op-node dependency condition (fixes ethereum-optimism#98) (ethereum-optimism#99)
a882529e8 Kill all pending block downloads if a peer fails (ethereum-optimism#95)
eb66345e1 e2e: tidy up docker-compose file (ethereum-optimism#81)
34766f725 Track pending blocks with ttl package (ethereum-optimism#90)
6ed3eb88b Added configurable fee-per-vB to PoP Miner (ethereum-optimism#91)
509e31fbc Replace os.Kill with syscall.SIGTERM in signal.Notify calls (ethereum-optimism#87)

git-subtree-dir: heminetwork
git-subtree-split: b5b564702e8d3bedcdf0e0a52c22e383d7fd4dbe
ClaytonNorthey92 added a commit to hemilabs/optimism that referenced this pull request Apr 7, 2025
b5b564702 popm/wasm: add wasm-opt target to optimise wasm binary (ethereum-optimism#146)
27a5081e3 tbc: allow seeds to be overwritten (ethereum-optimism#158)
18afbc403 Fix missing panic (ethereum-optimism#156)
05cee0afb tbc: remove height as the terminal condition for indexers (ethereum-optimism#152)
4402060d6 Use hemilabs/websocket fork of nhooyr.io/websocket (ethereum-optimism#153)
3df5001c4 Add initial CODEOWNERS file (ethereum-optimism#149)
a4685a57f popm/wasm: improve and tidy up Go code (ethereum-optimism#144)
41a0009c1 Add forking detection to TBC (ethereum-optimism#101)
bbeed8bac ignore ulimits in tbc when on localnet (ethereum-optimism#142)
4e1914cc6 Stopgap to re-fetch blocks with no children (ethereum-optimism#131)
12eefff06 e2e: fix issues detected by staticcheck (ethereum-optimism#134)
80153372f Add more documentation for TBC and related RPC protocol (ethereum-optimism#86)
723b63704 bfg: fix issues reported by staticcheck (ethereum-optimism#132)
509fb1be6 electrumx: fix unhandled error in NewJSONRPCRequest (ethereum-optimism#133)
b19af1e1f hemictl: use sort.Strings(...) instead of sort.Sort(sort.StringSlice(...)) (S1032) (ethereum-optimism#123)
cf7c570f9 popmd: remove unused 'handle' func and return err in connectBFG (ethereum-optimism#124)
fa2a4c4de ci: fix bug that makes version type always 'unstable' (ethereum-optimism#125)
ddc39655a ci: use org DOCKERHUB_TOKEN secret (ethereum-optimism#128)
6457d16f5 bfgd: drop btc_blocks_can refresh triggers for l2_keystones/pop_basis (ethereum-optimism#120)
2b3c096bd popm: simplify receivedKeystones variable in tests (ethereum-optimism#116)
6140bbf24 tbc: move RPC tests to a separate test file (ethereum-optimism#114)
c76571ff0 Add configuration option for static fees to web PoP miner (ethereum-optimism#119)
233817e65 popm: use simple conversion instead of unnecessary fmt.Sprintf (S1025) (ethereum-optimism#115)
2879f5fa7 e2e: improve name for variable with type `time.Duration` (ST1011) (ethereum-optimism#117)
4f31965e6 database,e2e: remove use of deprecated io/ioutil (SA1019) (ethereum-optimism#118)
e9e090696 tbc: do not recreate outpoint for ScriptHashByOutpoint. (ethereum-optimism#109)
52eefb136 ignore l2 keystones notifications in tests (ethereum-optimism#112)
eb607994c Sync Docker image environment variables with daemon configs (ethereum-optimism#111)
57281bc5d added a way to monitor and sanity-test localnet (ethereum-optimism#106)
ea1a1c94c bfgd: fix loops unconditionally exited after one interation (SA4004) (ethereum-optimism#108)
29f116fb4 Add pprof http server to daemons (ethereum-optimism#105)
18a315d7e Added README for generating forks in BTC regtest for TBC fork resolution testing (ethereum-optimism#100)
55b8f52cb more robust nextPort (ethereum-optimism#103)
48f8b293f tbcapi: use reverse byte order for hashes in serialised, tidy up (ethereum-optimism#104)
b7e9f5ecb restart initialblocks on-failure (ethereum-optimism#102)
f9d52d423 Update required Go version to v1.22.2 (ethereum-optimism#96)
f6808aa5b Fix op-proposer op-node dependency condition (fixes ethereum-optimism#98) (ethereum-optimism#99)
a882529e8 Kill all pending block downloads if a peer fails (ethereum-optimism#95)
eb66345e1 e2e: tidy up docker-compose file (ethereum-optimism#81)
34766f725 Track pending blocks with ttl package (ethereum-optimism#90)
6ed3eb88b Added configurable fee-per-vB to PoP Miner (ethereum-optimism#91)
509e31fbc Replace os.Kill with syscall.SIGTERM in signal.Notify calls (ethereum-optimism#87)

git-subtree-dir: heminetwork
git-subtree-split: b5b564702e8d3bedcdf0e0a52c22e383d7fd4dbe
gd-0 pushed a commit to gattaca-com/based-optimism that referenced this pull request May 19, 2025
gd-0 pushed a commit to gattaca-com/based-optimism that referenced this pull request May 19, 2025
BrycePy added a commit to gattaca-com/based-optimism that referenced this pull request Oct 10, 2025
Zena-park added a commit to tokamak-network/optimism that referenced this pull request Dec 30, 2025
Zena-park added a commit to tokamak-network/optimism that referenced this pull request Dec 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants