Git Product home page Git Product logo

optimism's Introduction



Optimism

Optimism is Ethereum, scaled.


What is Optimism?

Optimism is a project dedicated to scaling Ethereum's technology and expanding its ability to coordinate people from across the world to build effective decentralized economies and governance systems. The Optimism Collective builds open-source software for running L2 blockchains and aims to address key governance and economic challenges in the wider cryptocurrency ecosystem. Optimism operates on the principle of impact=profit, the idea that individuals who positively impact the Collective should be proportionally rewarded with profit. Change the incentives and you change the world.

In this repository, you'll find numerous core components of the OP Stack, the decentralized software stack maintained by the Optimism Collective that powers Optimism and forms the backbone of blockchains like OP Mainnet and Base. Designed to be "aggressively open source," the OP Stack encourages you to explore, modify, extend, and test the code as needed. Although not all elements of the OP Stack are contained here, many of its essential components can be found within this repository. By collaborating on free, open software and shared standards, the Optimism Collective aims to prevent siloed software development and rapidly accelerate the development of the Ethereum ecosystem. Come contribute, build the future, and redefine power, together.

Documentation

Community

General discussion happens most frequently on the Optimism discord. Governance discussion can also be found on the Optimism Governance Forum.

Contributing

Read through CONTRIBUTING.md for a general overview of the contributing process for this repository. Use the Developer Quick Start to get your development environment set up to start working on the Optimism Monorepo. Then check out the list of Good First Issues to find something fun to work on!

Security Policy and Vulnerability Reporting

Please refer to the canonical Security Policy document for detailed information about how to report vulnerabilities in this codebase. Bounty hunters are encouraged to check out the Optimism Immunefi bug bounty program. The Optimism Immunefi program offers up to $2,000,042 for in-scope critical vulnerabilities.

The Bedrock Upgrade

OP Mainnet is currently preparing for its next major upgrade, Bedrock. You can find detailed specifications for the Bedrock upgrade within the specs folder in this repository.

Please note that a significant number of packages and folders within this repository are part of the Bedrock upgrade and are NOT currently running in production. Refer to the Directory Structure section below to understand which packages are currently running in production and which are intended for use as part of the Bedrock upgrade.

Directory Structure

├── docs: A collection of documents including audits and post-mortems
├── op-bindings: Go bindings for Bedrock smart contracts.
├── op-batcher: L2-Batch Submitter, submits bundles of batches to L1
├── op-bootnode: Standalone op-node discovery bootnode
├── op-chain-ops: State surgery utilities
├── op-challenger: Dispute game challenge agent
├── op-e2e: End-to-End testing of all bedrock components in Go
├── op-exporter: Prometheus exporter client
├── op-heartbeat: Heartbeat monitor service
├── op-node: rollup consensus-layer client
├── op-preimage: Go bindings for Preimage Oracle
├── op-program: Fault proof program
├── op-proposer: L2-Output Submitter, submits proposals to L1
├── op-service: Common codebase utilities
├── op-wheel: Database utilities
├── ops-bedrock: Bedrock devnet work
├── packages
│   ├── chain-mon: Chain monitoring services
│   ├── common-ts: Common tools for building apps in TypeScript
│   ├── contracts-ts: ABI and Address constants
│   ├── contracts-bedrock: Bedrock smart contracts
│   ├── core-utils: Low-level utilities that make building Optimism easier
│   └── sdk: provides a set of tools for interacting with Optimism
├── proxyd: Configurable RPC request router and proxy
└── specs: Specs of the rollup starting at the Bedrock upgrade

Branching Model

Active Branches

Branch Status
master Accepts PRs from develop when intending to deploy to production.
develop Accepts PRs that are compatible with master OR from release/X.X.X branches.
release/X.X.X Accepts PRs for all changes, particularly those not backwards compatible with develop and master.

Overview

This repository generally follows this Git branching model. Please read the linked post if you're planning to make frequent PRs into this repository.

Production branch

The production branch is master. The master branch contains the code for latest "stable" releases. Updates from master always come from the develop branch.

Development branch

The primary development branch is develop. develop contains the most up-to-date software that remains backwards compatible with the latest experimental network deployments. If you're making a backwards compatible change, please direct your pull request towards develop.

Changes to contracts within packages/contracts-bedrock/src are usually NOT considered backwards compatible and SHOULD be made against a release candidate branch. Some exceptions to this rule exist for cases in which we absolutely must deploy some new contract after a release candidate branch has already been fully deployed. If you're changing or adding a contract and you're unsure about which branch to make a PR into, default to using the latest release candidate branch. See below for info about release candidate branches.

Release candidate branches

Branches marked release/X.X.X are release candidate branches. Changes that are not backwards compatible and all changes to contracts within packages/contracts-bedrock/src MUST be directed towards a release candidate branch. Release candidates are merged into develop and then into master once they've been fully deployed. We may sometimes have more than one active release/X.X.X branch if we're in the middle of a deployment. See table in the Active Branches section above to find the right branch to target.

Releases

Changesets

We use changesets to mark packages for new releases. When merging commits to the develop branch you MUST include a changeset file if your change would require that a new version of a package be released.

To add a changeset, run the command pnpm changeset in the root of this monorepo. You will be presented with a small prompt to select the packages to be released, the scope of the release (major, minor, or patch), and the reason for the release. Comments within changeset files will be automatically included in the changelog of the package.

Triggering Releases

Releases can be triggered using the following process:

  1. Create a PR that merges the develop branch into the master branch.
  2. Wait for the auto-generated Version Packages PR to be opened (may take several minutes).
  3. Change the base branch of the auto-generated Version Packages PR from master to develop and merge into develop.
  4. Create a second PR to merge the develop branch into the master branch.

After merging the second PR into the master branch, packages will be automatically released to their respective locations according to the set of changeset files in the develop branch at the start of the process. Please carry this process out exactly as listed to avoid develop and master falling out of sync.

NOTE: PRs containing changeset files merged into develop during the release process can cause issues with changesets that can require manual intervention to fix. It's strongly recommended to avoid merging PRs into develop during an active release.

License

All other files within this repository are licensed under the MIT License unless stated otherwise.

optimism's People

Contributors

ajsutton avatar ben-chain avatar cfromknecht avatar clabby avatar dependabot[bot] avatar elenadimitrova avatar felipe-op avatar gakonst avatar geohot avatar github-actions[bot] avatar hamdiallam avatar inphi avatar karlfloersch avatar maurelian avatar mdehoog avatar mergify[bot] avatar mslipper avatar norswap avatar optimismbot avatar optimisticben avatar protolambda avatar qbzzt avatar refcell avatar roninjin10 avatar sebastianst avatar smartcontracts avatar snario avatar tremarkley avatar trianglesphere avatar tynes avatar

Watchers

 avatar

optimism's Issues

`ops-bedrock` local devnet Shutter integration

We want to integrate shutter with all relevant components in the local devnet of the optimism codebase.
Whenever make devnet-up is invoked and the SHUTTER_ENABLED=true env var is set, a full ops-bedrock devnet
including all relevant actors in the shutter network should be started in a docker compose setup.

local development

  • integrate the following shutter repos as git submodules to build the newest development binaries directive

    • rolling-shutter
    • op-geth
  • for faster development, use replace directives in tandem with git submodules

    • op-geth
    • shop-contracts

initialisation

  • add shop-contracts to the op-binding
  • implement predeploy system contracts and initialisation routines for:
    • Inbox
    • KeyperSetManager
    • KeyBroadcastContract
    • optional one initial KeyperSet contract for the first keyper set
  • set the active keyperset for the 4 devnet keypers

docker compose setup

  • image build, starting and configuration of shutter services: 4
    • 4 keypers
    • 4 keyper validator nodes (shuttermint)
    • 2 bootstrap nodes
    • shutter-node (op-node integration)
  • bootstrap the tendermint chain from the seed-validator to the first initial keyper set

`op-keyper` L2 event / block subscription

The shutter keyper for optimism has to listen for new unsafe head blocks and subscribe to the shutter contract states on L2.

  • release decryption key share upon new unsafe head blocks to P2P network
  • construct and release aggregate decryption key when threshold keyshares are seen on P2P network
  • initiate the DKG when part of a new keyper set (KeyperSetManager event subscription)
  • bootstrap command for the initial keyper set / bootstrap validator (shuttermint)

OP node shutter state machine

OP node state machine

The OP node is responsible for requesting the next block via the engine API. Which type of block in a shutter system is to be requested is determined by the state of the shutter system contracts.
From the OP node's perspective there are three different block types to be requested:

  • (1) Shutterized Block (submits the decryption key via engine API)
  • (2) Deactivation Block (submits special decryption key via engine which will disable shutter)
  • (3) Vanilla Block (without submitting a decryption key)

Requirements

  • The rollup should never stall (delayed is ok)
  • The rollup should thus fallback to vanilla mode
  • The op-node has always the ability to disable shutter
  • The op-node should be able to realize that shutter is enabled and give the shutter system enough time to provide decryption keys
  • There should be a different set of conditions when to request each block type

Conditions

  • If shutter is enabled
    • Wait time X until a decryption key is received
    • Wait at least the minimum block time
  • If shutter is disabled
    • Wait the minimum block time
  • If time X is passed and shutter is enabled
    • request deactivation block

Internal State

The op node has different conditions to be met to request the the next block.
For that it needs to keep some internal state to know in which mode the rollup is running.
In its easiest form it's a flag of what the op node thinks the next block should be. Shutterized or unshutterized.

However, it is possible that the node's state is not equal to the actual state at any point in time, thus the node could accidentally request a different block type. This must result in an error being returned by op-geth.
This actually is the input to the internal op-node's shutter state transition.

stateDiagram
 direction LR
 s1: Disabled
     note left of s1
        success by engine API => Block could be produced
        error by engine API => expects decryption key
    end note
 s2: Enabled
    note right of s2
        success by engine API => Block could be produced in time with decryption key
        error by Engine API => expects vanilla block 
        timeout => did not receive decryption key during configured shutter timeout 
    end note
 
 s1 --> s2: error / (1)
 s2 --> s1: error / (3)
 s2 --> s1: timeout / (2)
 s1 --> s1: success / (3)
 s2 --> s2: success / (1)


Loading

`op-node` integrate shutter-node and engine-API changes

The op-node consensus client has to be modified to integrate with the shutter op-geth execution client as well as the external shutter P2P integration (see #9) .

  • implement the different behaviour of the Engine API requests depending on shutter mode (active, inactive, deactivation)
  • Implement the failure handling logic described in #7
  • tbd: allow to use the shutter op-node with rollups that do not implement shutter (optional)

Block production

If shutter is active

  • triggered whenever key is received and x seconds have passed (instead of just time based)
  • pass reveal tx via Engine API to op-geth

if shutter is not active

  • continue with current implementation

`shutter-node` - shutter P2P-network and shop-contracts integration

The shutter node will be a separate application that serves as a gateway to the shutter P2P network and reading the shutter contract's state for the op-node.
It will expose an HTTP API where the op-node can poll for the decryption-key of a certain L2 block-number.

  • define the HTTP API's technology (push/pull/longpoll, RPC/REST, WS, etc.):

    • The shutter-node exposes a blocking GET endpoint, so that the op-node can long-poll for a block-numbers decryption-key. The op-node can remotely call (however implemented) getDecryptionKey(blocknumber int). The endpoint will either return immediately when a key has been received already, or it will block until it receives the key and then return.
      Like that, the op-node can already call getDecryptionKey(n+1), when n is the current block-number to be build.
      Keyper's then wait for their op-geth to return n from eth_blockNumber and release their key for n+1. Once the key is received by the shutter node, it will return the key immediately to the blocking http request.
  • define the HTTP API's methods / state-transfer model

  • P2P Handler / Validator functions

  • L2 JSON RPC client

    • contract event subscription worker (shutter paused, new keyper sets, public keys)
    • eth_blockNumber new unsafe head event worker
  • internal promise based event listening for long-polling GET requests

  • concurrency safe data-structure for received events & data persistence (database)

Initialize Shutter system contracts

The shutter contracts are predeployed in the genesis file. However, they are not initialized.

In order to let a devnet run we need to send certain transactions in order to initialize the contracts, so they the keyper set starts running.

In production the dao will need to send those transactions.

  • Pass a public address which is controlled by us as the default admin
  • KeyperSetContract
    • Deploy a KeyperSetContract
    • Set Threshold
    • Set KeyBroadcaster
    • Add Keypers to the contract
    • finalize
    • broadcast eon key
    • schedule keyper set in keyper set manager
  • Set withdraw role in Inbox

Steps to Sepolia testnet deployment

  • Engine API interactions / changes?
    • decr. key parameter + returns errors depending on shutter state
  • HTTP API shutter-node <-> op-node
  • shutter-node database persistence
  • op-node state keeping (shutter-node timeouts / error handling / key forwarding)
  • check if shoptimism needs to IMPORT (go mod) shutter-geth library version as well
    • if so we likely need to sync our geth with a certain upstream version for shoptimism compatibility
  • L1 automatic contract deployment
    • utilisation of deployed L1 contracts in bedrock-local devnet script
    • on own new devnet L1, but external and no genesis control
    • on the sepolia chain with possibly external RPC provider
  • devops / infrastructure for the docker compose hosting
    • try fist: L1 rpc provider for sepolia instead of local node (alchemy seems to have sepolia RPC endpoints)
    • rest docker compose deployment on 1 big machine
    • expose only JSON-RPC to the world ("l2 blackbox")
    • use local bedrock-devnet docker-compose without the ("genesis") L1 geth node (or use the node as proxy to sepolia)
  • use "master keys" that we control for the restricted contracts
  • for manual testing: tx sending / encrypting part needs to be implemented or adapted somehow

Deposit transactions are not executed on L2

With the current devnet script L2 deposit transactions execute on L1 but are not enforced on L2. Need to investigate.

  •  check if deposit transaction work without modifying devnet script

Connect to shutter p2p and listen to decryption key

We decided to outsource the key listening process into its own application.

The main reason for it is, to keep the diff to the original op-node small as we need to maintain it. The application must

  • connect to p2p network and listen to decryption keys
  • connect to op-geth to be able to read the state via the standard JSON RPC interface
  • once a decryption key is received for the next block, validate with respect to eon key broadcast on chain and current keyper set

The decryption key must be forwarded to the op-node app. This can be done either by pushing, polling or long-polling by the op-node.
Thus, the op-node app needs to implement this mechanism.

@ezdac any preferences regarding the inter process comms?

Shut off mechanism

The operator is able to disable Shutter by requesting a new block with an empty decryption key via the engine API (@jannikluhn please share the exact interface with op-geth).
As a first iteration, the op-node should trigger the shutoff mechanism automatically if it wasn't able to receive the key in a specified amount of time. The exact timeout should be configurable.

OPStack testnet [EPIC]

Initial testnet release (needs a name to distinguish)

Requirements:

  • Shutterized OP stack runs on testnet
  • needs to run a DEX live
  • needs to somehow show users that it's shutterized (at the level of Max's demo, but that they can see it for themselves)
  • Faucet for ETH and Banana tokens

Components:

  • Faucet
    • prefunded balance
    • Maybe reuse Beamer's faucet
    • fund user's balance with SHOP-ETH and banana tokens
  • The testnet itself running on Sepolia
  • Uni V2 fork smart contracts deployed
    • create and fund pool
  • Uni V2 front-end hosted
    • faucet button
    • Make it work with shutter specific tx lifecycle (inclusion tx != execution)
  • Frontend Popup to show transaction life cycle
    • show once transaction is included (still encrypted) and waiting for execution
    • show block when it will be executed
    • show that tx got executed

Nice to have:

  • Every trade is configured with 10% slippage
  • after tx is executed, shows the actual slippage
  • At a later stage all unencrypted txs will be sandwiched to extract the entire 10%

Stage 2 (needs a name to distinguish)

  • optional: sandwich bot which sandwiches everyone who doesn't use shutter (maybe collaborate with propellerheads)
  • javascript library/SDK for end user to encrypt

Stage 3 (needs a name to distinguish)

  • Deploy on Gnosis Chain?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.