Skip to content

l2geth: Add support for system addresses#2256

Merged
mslipper merged 1 commit intoethereum-optimism:developfrom
mslipper:feat/system-address
Mar 7, 2022
Merged

l2geth: Add support for system addresses#2256
mslipper merged 1 commit intoethereum-optimism:developfrom
mslipper:feat/system-address

Conversation

@mslipper
Copy link
Collaborator

@mslipper mslipper commented Mar 4, 2022

Adds support for system addresses.

To deploy to a system address, the deployer must either be in the list of hardcoded addresses described in SystemAddressDeployers, or be specified via the SYSTEM_ADDRESS_0_DEPLOYER/SYSTEM_ADDRESS_1_DEPLOYER environment variables. The hardcoded system addresses deployers will always override those placed in the environment, so specifying the SYSTEM_ADDRESS_* env vars on mainnet, Kovan, or Goerli is a no-op. The env vars are available primarily for testing purposes.

The contract deployment must be the first transaction from the deployment address - i.e., it must have nonce zero.

In order to make the tests work, I had to change the integration tests chain ID to no longer conflict with Goerli. The new integration tests chain ID is 987.

Co-Authored-By: @Inphi

@changeset-bot
Copy link

changeset-bot bot commented Mar 4, 2022

🦋 Changeset detected

Latest commit: 962f36e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@eth-optimism/integration-tests Patch
@eth-optimism/l2geth Patch
@eth-optimism/contracts Patch
@eth-optimism/data-transport-layer Patch
@eth-optimism/sdk Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added 2-reviewers A-integration Area: integration tests A-cannon Area: cannon A-ops Area: ops labels Mar 4, 2022
@mslipper mslipper force-pushed the feat/system-address branch from 6abd53f to 232c91c Compare March 4, 2022 05:18
@mslipper
Copy link
Collaborator Author

mslipper commented Mar 4, 2022

This is a security critical PR. Specifically, the following risks are present:

  • It modifies consensus rules.
  • There is an escape hatch that reads consensus rules from the environment.
  • System addresses are powerful, and can change the behavior of the system in profound ways. Once they are deployed, they should never be updated.

Additionally:

  • The address generation rules for the system contracts are copied into two distinct places since the logic to generate the receipt contractAddress field is in multiple places.
  • There may be additional consequences to changing contract address generation in this way. I'd like @tynes and @smartcontracts to take a look to make sure I'm not stepping on any landmines.

To try and mitigate these risks, I:

  • Added unit and integration testing.
  • Made sure that the hardcoded deployer values always override the values present in the environment.

@codecov-commenter
Copy link

codecov-commenter commented Mar 4, 2022

Codecov Report

Merging #2256 (5ab3118) into develop (1efebf1) will decrease coverage by 0.88%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2256      +/-   ##
===========================================
- Coverage    80.96%   80.08%   -0.89%     
===========================================
  Files           77       77              
  Lines         2432     2460      +28     
  Branches       434      450      +16     
===========================================
+ Hits          1969     1970       +1     
- Misses         463      490      +27     
Flag Coverage Δ
contracts 99.29% <ø> (ø)
core-utils 86.77% <ø> (ø)
data-transport-layer 49.72% <ø> (ø)
sdk 55.75% <ø> (-1.97%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/sdk/src/cross-chain-messenger.ts 64.85% <0.00%> (-5.07%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1efebf1...5ab3118. Read the comment docs.

@mslipper mslipper force-pushed the feat/system-address branch from 232c91c to 5ab3118 Compare March 4, 2022 09:22
@maurelian maurelian added the C-security-risk Category: Review for security risks label Mar 4, 2022
Copy link
Contributor

@maurelian maurelian left a comment

Choose a reason for hiding this comment

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

I reviewed this PR mostly from a meta perspective as we're implementing a new process which varies depending on the security risk.

Comments:

  1. I added a new label SR-Risk to identify these.
  2. The PR description should also provide the motivation. Presumably the reviewers are aware, but it's useful to make it explicit to ensure there is agreement on it. Of course it's also important for external readers.
  3. The risks and mitigations comment is great. (We should standardize on a template, but not necessary here.

An item for further discussion:

I think there's an argument to be made that nominating two reviewers creates a risk of
'diffusion of responsibility', where the first reviewer approaches their review with the awareness that someone else will be coming through to catch anything they might miss.

Review status:
Submitting as Request Changes. I would approve if:

  1. The motivation is added to the description.
  2. My inline comments are addressed or rejected with explanation.

Copy link
Contributor

@maurelian maurelian left a comment

Choose a reason for hiding this comment

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

Approving as my previous review has been satisfied.

In addition I thought about security considerations a bit more:

Risk considered:

This feels to me like the most consequential change.

I tried to think of a way that an existing contract could be over-written. I couldn't, but @tynes and @smartcontracts should also consider it.

sysAddress := rcfg.SystemAddressFor(config.ChainID, from)
// If nonce is zero, and the deployer is a system address deployer,
// set the provided system contract address.
if sysAddress != rcfg.ZeroSystemAddress && nonce == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will be inconsistent with the address that the contract is actually deployed at in the case len(codesize) > 0

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated to detect a contract creation transaction at this nonce by adding a check for tx[i].To() == nil. The only possible address for a contract created at nonce 0 from a system address deployer is the system address.

Copy link
Collaborator Author

@mslipper mslipper Mar 7, 2022

Choose a reason for hiding this comment

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

I took at look at the rest of evm.go - there's a check that will revert if the codesize is > 0:

	// Ensure there's no existing contract already at the designated address
	contractHash := evm.StateDB.GetCodeHash(address)
	if evm.StateDB.GetNonce(address) != 0 || (contractHash != (common.Hash{}) && contractHash != emptyCodeHash) {
		return nil, common.Address{}, 0, ErrContractAddressCollision
	}

So, I removed the additional check in the line above.

@mslipper mslipper force-pushed the feat/system-address branch 2 times, most recently from 240b1e2 to 3003855 Compare March 7, 2022 01:42
@mslipper mslipper force-pushed the feat/system-address branch from 3003855 to 41d5459 Compare March 7, 2022 02:18
Adds support for system addresses.

To deploy to a system address, the deployer must either be in the list of hardcoded addresses described in `SystemAddressDeployers`, or be specified via the `SYSTEM_ADDRESS_0_DEPLOYER`/`SYSTEM_ADDRESS_1_DEPLOYER` environment variables. The hardcoded system addresses deployers will always override those placed in the environment, so specifying the `SYSTEM_ADDRESS_*` env vars on mainnet, Kovan, or Goerli is a no-op. The env vars are available primarily for testing purposes.

The contract deployment **must** be the first transaction from the deployment address - i.e., it must have nonce zero.

In order to make the tests work, I had to change the integration tests chain ID to no longer conflict with Goerli. The new integration tests chain ID is `987`.

Co-Authored-By: @Inphi
@mslipper mslipper force-pushed the feat/system-address branch from 41d5459 to 962f36e Compare March 7, 2022 02:22
Copy link
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.

Awesome this LGTM! 🔥

Successfully ran the tests locally

@mslipper mslipper merged commit 82465db into ethereum-optimism:develop Mar 7, 2022
theochap pushed a commit that referenced this pull request Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cannon Area: cannon A-integration Area: integration tests A-ops Area: ops C-security-risk Category: Review for security risks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants