l2geth: Add support for system addresses#2256
l2geth: Add support for system addresses#2256mslipper merged 1 commit intoethereum-optimism:developfrom
Conversation
🦋 Changeset detectedLatest commit: 962f36e The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
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 |
6abd53f to
232c91c
Compare
|
This is a security critical PR. Specifically, the following risks are present:
Additionally:
To try and mitigate these risks, I:
|
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
232c91c to
5ab3118
Compare
maurelian
left a comment
There was a problem hiding this comment.
I reviewed this PR mostly from a meta perspective as we're implementing a new process which varies depending on the security risk.
Comments:
- I added a new label SR-Risk to identify these.
- 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.
- 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:
- The motivation is added to the description.
- My inline comments are addressed or rejected with explanation.
maurelian
left a comment
There was a problem hiding this comment.
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.
l2geth/core/types/receipt.go
Outdated
| 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 { |
There was a problem hiding this comment.
This will be inconsistent with the address that the contract is actually deployed at in the case len(codesize) > 0
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
240b1e2 to
3003855
Compare
3003855 to
41d5459
Compare
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
41d5459 to
962f36e
Compare
…p-rs/kona#2289) Closes #2214 Closes #2215 Closes #2255 Closes #2256
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 theSYSTEM_ADDRESS_0_DEPLOYER/SYSTEM_ADDRESS_1_DEPLOYERenvironment variables. The hardcoded system addresses deployers will always override those placed in the environment, so specifying theSYSTEM_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