Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.

specs: add predeploys#379

Closed
tynes wants to merge 4 commits intomainfrom
spec/predeploys
Closed

specs: add predeploys#379
tynes wants to merge 4 commits intomainfrom
spec/predeploys

Conversation

@tynes
Copy link
Contributor

@tynes tynes commented Apr 18, 2022

Description
PR to add specs for the predeploys. These need to be upgraded in a backwards compatible way for bedrock, its worth specifying their interfaces since they will always be in the state.

@tynes tynes force-pushed the spec/predeploys branch 4 times, most recently from b86d5cf to 4b5c5d9 Compare April 18, 2022 21:43
@tynes tynes marked this pull request as ready for review April 18, 2022 21:54
@codecov-commenter
Copy link

codecov-commenter commented Apr 18, 2022

Codecov Report

Merging #379 (d52bb18) into main (92fccc2) will increase coverage by 0.15%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main     #379      +/-   ##
==========================================
+ Coverage   51.50%   51.66%   +0.15%     
==========================================
  Files          70       70              
  Lines        7582     7582              
==========================================
+ Hits         3905     3917      +12     
+ Misses       3154     3145       -9     
+ Partials      523      520       -3     
Impacted Files Coverage Δ
opnode/node/api.go 60.74% <0.00%> (+1.48%) ⬆️
opnode/l2/source.go 52.00% <0.00%> (+1.77%) ⬆️
bss/sequencer/driver.go 77.20% <0.00%> (+2.20%) ⬆️
l2os/service.go 94.73% <0.00%> (+3.94%) ⬆️

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 92fccc2...d52bb18. Read the comment docs.

@tynes
Copy link
Contributor Author

tynes commented Apr 18, 2022

The following script was used to find the existing predeploys:

import { providers, utils } from 'ethers'
import * as fs from 'fs'

const outfile = 'predeploys.json'

;(async function () {
  const provider = new providers.StaticJsonRpcProvider('https://mainnet.optimism.io')

  const prefixes = [
    '0x420000000000000000000000000000000000',
    '0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD'
  ]


  // we don't need to search the entire space
  // const MAX_U16 = 0xffff
  const predeploys = []

  for (const prefix of prefixes) {
    for (let i = 0; i <= 100; i++) {
      const buf = Buffer.alloc(2);
      buf.writeUInt16BE(i, 0);
      const addr = utils.hexConcat([prefix, utils.hexZeroPad(buf, 2)])
      predeploys.push(addr)
    }
  }

  const detected = []

  for (const predeploy of predeploys) {
    const code = await provider.getCode(predeploy)
    if (code !== '0x') {
      console.log(`Predeploy detected at ${predeploy}`)
      detected.push({
        address: predeploy,
        code: code,
      })
    }
  }

  fs.writeFileSync(outfile, JSON.stringify(detected, null, 2))
})()

Results:

$ cat predeploys.json | jq -r '.[].address'
0x4200000000000000000000000000000000000000
0x4200000000000000000000000000000000000002
0x4200000000000000000000000000000000000006
0x4200000000000000000000000000000000000007
0x420000000000000000000000000000000000000f
0x4200000000000000000000000000000000000010
0x4200000000000000000000000000000000000011
0x4200000000000000000000000000000000000012
0x4200000000000000000000000000000000000013
0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000

@tynes tynes force-pushed the spec/predeploys branch from 684eed9 to 888738c Compare April 19, 2022 13:37
Copy link
Collaborator

@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.

Looks good. Left a couple nits worth fixing. I'd also suggest updating the glossary here:

https://github.com/maurelian/optimistic-specs/blob/e398ba7aaa1872188f371de517df9649330a03cd/specs/glossary.md#L104-L112

with this diff:

- Optimism has the following predeploys:
-
-- [L1 Attributes Predeployed Contract][l1-attr-predeploy]
+ All predeploy contracts are specified in the [predeploys specification][./predeploys.md].

@tynes tynes force-pushed the spec/predeploys branch from 888738c to 4199a9a Compare April 19, 2022 14:06
@tynes
Copy link
Contributor Author

tynes commented Apr 19, 2022

Thank you for the review! Addressed your nits

@tynes tynes force-pushed the spec/predeploys branch from 546fe99 to 6e0e901 Compare April 19, 2022 14:13
@tynes
Copy link
Contributor Author

tynes commented Apr 19, 2022

For some reason there is a CircleCI build error

# No configuration was found in your project. Please refer to https://circleci.com/docs/2.0/ to get started with your configuration.

@trianglesphere
Copy link
Contributor

For some reason there is a CircleCI build error

# No configuration was found in your project. Please refer to https://circleci.com/docs/2.0/ to get started with your configuration.

@mslipper Somethings acting up.

@tynes don't worry about circle CI blocking this PR

* @notice The Withdrawer contract facilitates sending both ETH value and data from L2 to L1.
* It is predeployed in the L2 state at address 0x4200000000000000000000000000000000000016.
*/
contract Withdrawer {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Can we embed contracts directly? My concern is them getting out of date. Another question is will we want to upgrade the pre-deploys? This is pretty out of scope and doesn't need to be addressed as part of this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The point here is that its all interfaces and that we can transparently change the predeploys in a backwards compatible way. I would much rather link to actual solidity files instead of embedding the source code in markdown, so I could add an interfaces directory if preferred

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh nice. That makes a bunch of sense (I just skimmed an saw solidity, not the fact that it was only interfaces).

Copy link
Collaborator

@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.

LGTM

Copy link
Contributor

@norswap norswap left a comment

Choose a reason for hiding this comment

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

Quick not super in depth review. Biggest comment is we should be clearer about the guarantees we're giving, esp. for the deprecated stuff.


Predeployed smart contracts exist on Optimism at predetermined addresses in
the genesis state. They are similar to precompiles but instead run directly
in the EVM instead of running native code outside of the EVM.
Copy link
Contributor

Choose a reason for hiding this comment

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

It could be said that some of these contracts don't really exist in the "genesis" state since historical transaction would not have been able to use them. It's as though they were included in the genesis but act as empty addresses until they become active at a certain block.

I guess with the regenesis, we only really have two class: (1) true (re)genesis contracts and (2) new bedrock contracts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once we know the height at which we switch to bedrock, we could add that to this document. Maybe it could go into a file dedicated to backwards compatibility?

## OVM\_L2ToL1MessagePasser

The `OVM_L2ToL1MessagePasser` is part of the legacy bridge. It is being
deprecated as part of the bedrock upgrade.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: capitalize Bedrock

Copy link
Contributor

Choose a reason for hiding this comment

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

What does deprecation mean? Will it still be usable / work correctly but use is discourage & it could be removed in the future?

/**
* @title OVM_L2ToL1MessagePasser
* @dev The L2 to L1 Message Passer is a utility contract which facilitate an L1 proof of the
* of a message on L2. The L1 Cross Domain Messenger performs this proof in its
Copy link
Contributor

Choose a reason for hiding this comment

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

"of the of a message"

Would suggest rewriting. e.g. it's not clear here that an "L1 proof" is a proof that happens on L1, or why/how this facilitates that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once the contracts are in the same repo as the specs, we should add links to the contracts themselves as to not need to maintain these here

legacy system, this contract was hooked into during `CREATE` and `CREATE2` to
ensure that the deployer was allowlisted. In the bedrock system, this will
be removed from the `CREATE` codepath since arbitrary contract deployment
has already been enabled.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to clarify (and this could be done up top) that some of these contracts are unused / might not function anymore, but need to be preserved as predeploys to guarantee the execution of historic blocks.

A good thing would be to come up with a taxonomy of these contracts, e.g.

  • functional
  • deprecated / functional (list preferred alternative)
  • deprecated / non-functional or useless

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a note at the top of the document saying that deprecated predeploys should not be used as well as adding a column to the table that includes whether or not a contract is deprecated

The `OVM_ETH` contains the ERC20 represented balances of ETH that has been
deposited to L2. As part of the bedrock upgrade, the balances will be migrated
from this contract to the actual Ethereum level accounts to preserve EVM
equivalence.
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens to the public functions here, will they still work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a note that this contract's usage should be avoided, some important functions (transfer) do not work currently

@tynes
Copy link
Contributor Author

tynes commented Apr 24, 2022

@norswap great feedback, thank you! Will address

@tynes
Copy link
Contributor Author

tynes commented May 11, 2022

This PR will need to be rebased and updated based on #421

@tynes tynes force-pushed the spec/predeploys branch from a04ef65 to a8d0fa8 Compare May 13, 2022 20:23
@tynes
Copy link
Contributor Author

tynes commented May 13, 2022

I've pushed a fix to this PR to address comments. I've removed the majority of the interfaces so that we don't need to maintain the interfaces here as well as in the repo. We can link directly to the contracts once they are all in the same repo

@tynes
Copy link
Contributor Author

tynes commented May 16, 2022

Closing in favor of ethereum-optimism/optimism#2568

@tynes tynes closed this May 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants