Skip to content

Instantly share code, notes, and snippets.

@krebernisak
Created January 19, 2021 19:40
Show Gist options
  • Save krebernisak/d8362269d9b769b72e8b1f5bc5e3dd52 to your computer and use it in GitHub Desktop.
Save krebernisak/d8362269d9b769b72e8b1f5bc5e3dd52 to your computer and use it in GitHub Desktop.
Optimism OVM integration

Optimism OVM integration

The docs page, while a good resource, is currently out of date.

Solidity support

Solidity source code needs to be compiled using OVM modified solc compiler. Because of the way OVM is architectured, the Optimism team needs to work to support specific Solidity compiler versions. Currently supported are v0.5 & v0.6, while work is started on v0.7 & v0.8.

The JS compiler can be found in ethereum-optimism/solc-js repo. Branches of interest are master-0.5 & master-0.6.

The Optimism Transpilation Overview is a good overview on how Solidity code is compiled to OVM, and there is also some info on this OVM vs. EVM Incompatibilities page.

Known issues & gotchas

  • Contract size limit is 15-20% less than Ethereum's 24K.
  • Block gas limit is currently set at 9 million (in contrast to Ethereums 12.5 million).
  • Gas metering is not implemented correctly (false gas cost is reported).
  • No native coin on L2, ETH implemented as a pre-deployed ERC20 contract (think wETH).
  • Gas pricing will be implemented in the future, currently, networks accepts gasPrice=0
  • On L2 every tx is wrapped in a block, so 1 tx equals 1 block.
  • The node sometimes returns a receipt with success as status, but the code is not actually deployed. To check for successful deployment you'll need to check if the code is available for the address.
  • The OVM toolchain requires Node v10, with v12 support in the works.
  • Some opcodes are not supported, as they don't have any meaning, in L2 context. See docs for more details.
  • Issues with contracts that are themselves deployers of other contracts via CREATE/CREATE2.

Some background, on that last point, by Master Jedi Ben Jones:

The nuance is: because constructor arguments are technically appended to the initcode (not passed in with calldata), the safety checker will sometimes accidentally flag initcode as unsafe because the constructor parameter happens to have an unsafe EVM opcode in its encoding. This is not all that likely, but it means if you need to guarantee deployment of a contract every time, with any params, then you need to use an initialize function instead of a constructor. The reason it is only flagged in some cases is that there are only a few possible values for the constructor argument bytestrings which are unsafe--it's a combination of having an "unsafe" opcode (of which there are <20 out of 256 possible byte values) and being in "reachable" code. For example, if the constructor params happen to contain JUMPDEST SSTORE it would be unsafe/thrown out because SSTORE is an unsafe opcode which can be reached with a JUMP. OTOH, REVERT SSTORE is safe because the code cannot possibly execute SSTORE -- even though it is there, the operation immediately preceding it guarantees the contract will revert before the SSTORE ever actually happens.

Integration testing

The biggest problem testing OVM contracts is that different environments currently have different behaviors. Ganache is useful for testing, but the real integration tests should be run against the local network.

Ganache

OVM Ganache provider can be found in @eth-optimism/ovm-toolchain package. This is a wrapper around ganache-core that will enable OVM bytecode execution.

Please note that OVM version of Ganache is ~2-3x slower than standard.

Local network

To run the local network:

git clone git@github.com:ethereum-optimism/optimism-integration.git
cd optimism-integration
git submodule update
docker-compose pull
./up.sh

Make sure to update the repo and Docker images daily as the codebase is still in active development:

git pull origin master
git submodule update
docker-compose pull

Public networks

  • Kovan L2: { url: "https://kovan.optimism.io", port: 69 }
  • Goerli L2: { url: "https://goerli.optimism.io", port: 420 }

Both test networks are currently in an unstable state, and it's recommended to test against the local network. ETA for the stable testnet launch is 15.3.2021.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment