Skip to content

Commit

Permalink
Merge branch 'develop' into sc/liquidity-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
agusduha committed Aug 13, 2024
2 parents 014c25d + a3b6a60 commit b8bd100
Show file tree
Hide file tree
Showing 299 changed files with 7,042 additions and 10,986 deletions.
173 changes: 65 additions & 108 deletions .circleci/config.yml

Large diffs are not rendered by default.

24 changes: 0 additions & 24 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,5 @@ description: Common setup steps used by our workflows
runs:
using: composite
steps:
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 9
- name: Setup node
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
registry-url: https://registry.npmjs.org
cache: pnpm

- name: Setup foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Install node dependencies
shell: bash
run: pnpm install --frozen-lockfile
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v3
with:
main-branch-name: "develop"
- run: |
echo "nx using following shas:"
echo "BASE: ${{ env.NX_BASE }}"
echo "HEAD: ${{ env.NX_HEAD }}"
shell: bash
7 changes: 0 additions & 7 deletions .github/workflows/slither.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ jobs:
steps:
- uses: actions/checkout@v4

# Workaround to prevent slither-action from trying to install JS deps.
# Without this step, it detects the `package.json`, and since there is no
# lockfile it defaults `npm install` which fails due to the preinstall
# script to enforce pnpm. https://github.com/crytic/slither-action/issues/44#issuecomment-1338183656
- name: Remove package.json
run: rm packages/contracts-bedrock/package.json

- name: Run Slither
uses: crytic/[email protected]
id: slither
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@
[submodule "packages/contracts-bedrock/lib/automate"]
path = packages/contracts-bedrock/lib/automate
url = https://github.com/gelatodigital/automate
[submodule "packages/contracts-bedrock/lib/openzeppelin-contracts-v5"]
path = packages/contracts-bedrock/lib/openzeppelin-contracts-v5
url = https://github.com/OpenZeppelin/openzeppelin-contracts
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

20 changes: 6 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Interactions within this repository are subject to a [Code of Conduct](https://g
| [go](https://go.dev/) | `^1.21` | `go version` |
| [node](https://nodejs.org/en/) | `^20` | `node --version` |
| [nvm](https://github.com/nvm-sh/nvm) | `^0.39` | `nvm --version` |
| [pnpm](https://pnpm.io/installation) | `^8` | `pnpm --version` |
| [just](https://github.com/casey/just) | `^1.34.0`| `just --version` |
| [foundry](https://github.com/foundry-rs/foundry#installation) | `^0.2.0` | `forge --version` |
| [make](https://linux.die.net/man/1/make) | `^3` | `make --version` |
| [jq](https://github.com/jqlang/jq) | `^1.6` | `jq --version` |
Expand All @@ -46,7 +46,7 @@ You can use [`nvm`](https://github.com/nvm-sh/nvm) to manage multiple versions o

`foundry` is updated frequently and occasionally contains breaking changes.
This repository pins a specific version of `foundry` inside of [`versions.json`](./versions.json).
Use the command `pnpm update:foundry` at the root of the monorepo to make sure that your version of `foundry` is the same as the one currently being used in CI.
Use the command `just update-foundry` at the root of the monorepo to make sure that your version of `foundry` is the same as the one currently being used in CI.

#### `direnv`

Expand Down Expand Up @@ -89,19 +89,11 @@ Use the above command to rebuild the monorepo.

Before running tests: **follow the above instructions to get everything built.**

#### Running unit tests (typescript)

Run unit tests for all packages in parallel via:

```bash
pnpm test
```

To run unit tests for a specific package:
#### Running unit tests (solidity)

```bash
cd packages/package-to-test
pnpm test
cd packages/contracts-bedrock
just test
```

#### Running unit tests (Go)
Expand All @@ -125,7 +117,7 @@ To run `slither` locally, do:
```bash
cd packages/contracts-bedrock
pip3 install slither-analyzer
pnpm slither
just slither
```

## Labels
Expand Down
28 changes: 15 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ lint-go-fix: ## Lints Go code with specific linters and fixes reported issues
golangci-lint run -E goimports,sqlclosecheck,bodyclose,asciicheck,misspell,errorlint --timeout 5m -e "errors.As" -e "errors.Is" ./... --fix
.PHONY: lint-go-fix

build-ts: submodules ## Builds TypeScript components
if [ -f "$$NVM_DIR/nvm.sh" ]; then \
. $$NVM_DIR/nvm.sh && nvm use; \
fi
pnpm install:ci
pnpm build
.PHONY: build-ts

ci-builder: ## Builds the CI builder Docker image
docker build -t ci-builder -f ops/docker/ci-builder/Dockerfile .
.PHONY: ci-builder
Expand Down Expand Up @@ -137,12 +129,24 @@ reproducible-prestate: ## Builds reproducible-prestate binary
make -C ./op-program reproducible-prestate
.PHONY: reproducible-prestate

# Include any files required for the devnet to build and run. This appears to be the only one that's actually needed.
DEVNET_CANNON_PRESTATE_FILES := op-program/bin/prestate-proof.json op-program/bin/prestate.json

$(DEVNET_CANNON_PRESTATE_FILES):
make cannon-prestate

cannon-prestate: op-program cannon ## Generates prestate using cannon and op-program
./cannon/bin/cannon load-elf --path op-program/bin/op-program-client.elf --out op-program/bin/prestate.json --meta op-program/bin/meta.json
./cannon/bin/cannon run --proof-at '=0' --stop-at '=1' --input op-program/bin/prestate.json --meta op-program/bin/meta.json --proof-fmt 'op-program/bin/%d.json' --output ""
mv op-program/bin/0.json op-program/bin/prestate-proof.json
.PHONY: cannon-prestate

cannon-prestate-mt: op-program cannon ## Generates prestate using cannon and op-program in the multithreaded cannon format
./cannon/bin/cannon load-elf --type mt --path op-program/bin/op-program-client.elf --out op-program/bin/prestate-mt.json --meta op-program/bin/meta-mt.json
./cannon/bin/cannon run --type mt --proof-at '=0' --stop-at '=1' --input op-program/bin/prestate-mt.json --meta op-program/bin/meta-mt.json --proof-fmt 'op-program/bin/%d-mt.json' --output ""
mv op-program/bin/0-mt.json op-program/bin/prestate-proof-mt.json
.PHONY: cannon-prestate

mod-tidy: ## Cleans up unused dependencies in Go modules
# Below GOPRIVATE line allows mod-tidy to be run immediately after
# releasing new versions. This bypasses the Go modules proxy, which
Expand All @@ -160,16 +164,14 @@ nuke: clean devnet-clean ## Completely clean the project directory
git clean -Xdf
.PHONY: nuke

pre-devnet: submodules ## Prepares for running a local devnet
## Prepares for running a local devnet
pre-devnet: submodules $(DEVNET_CANNON_PRESTATE_FILES)
@if ! [ -x "$(command -v geth)" ]; then \
make install-geth; \
fi
@if ! [ -x "$(command -v eth2-testnet-genesis)" ]; then \
make install-eth2-testnet-genesis; \
fi
@if [ ! -e op-program/bin ]; then \
make cannon-prestate; \
fi
.PHONY: pre-devnet

devnet-up: pre-devnet ## Starts the local devnet
Expand Down Expand Up @@ -207,7 +209,7 @@ test-unit: ## Runs unit tests for all components
make -C ./op-proposer test
make -C ./op-batcher test
make -C ./op-e2e test
pnpm test
(cd packages/contracts-bedrock && just test)
.PHONY: test-unit

# Remove the baseline-commit to generate a base reading & show all issues
Expand Down
2 changes: 1 addition & 1 deletion bedrock-devnet/devnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
log = logging.getLogger()

# Global constants
FORKS = ["delta", "ecotone", "fjord"]
FORKS = ["delta", "ecotone", "fjord", "granite"]

# Global environment variables
DEVNET_NO_BUILD = os.getenv('DEVNET_NO_BUILD') == "true"
Expand Down
2 changes: 1 addition & 1 deletion cannon/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cache
venv
.idea
*.log
example/bin
testdata/example/bin
contracts/out
state.json
*.json
Expand Down
2 changes: 1 addition & 1 deletion cannon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ clean:
rm -rf bin

elf:
make -C ./example elf
make -C ./testdata/example elf

contract:
cd ../packages/contracts-bedrock && forge build
Expand Down
2 changes: 1 addition & 1 deletion cannon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ The smart-contracts are integrated into the Optimism monorepo contracts:

Example programs that can be run and proven with Cannon.
Optional dependency, but required for `mipsevm` Go tests.
See [`example/Makefile`](./example/Makefile) for building the example MIPS binaries.
See [`testdata/example/Makefile`](./testdata/example/Makefile) for building the example MIPS binaries.

## License

Expand Down
29 changes: 27 additions & 2 deletions cannon/cmd/load_elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"debug/elf"
"fmt"

"github.com/ethereum-optimism/optimism/cannon/mipsevm"
"github.com/ethereum-optimism/optimism/cannon/mipsevm/multithreaded"
"github.com/urfave/cli/v2"

"github.com/ethereum-optimism/optimism/cannon/mipsevm/program"
Expand Down Expand Up @@ -39,6 +41,28 @@ var (
)

func LoadELF(ctx *cli.Context) error {
var createInitialState func(f *elf.File) (mipsevm.FPVMState, error)
var writeState func(path string, state mipsevm.FPVMState) error

if vmType, err := vmTypeFromString(ctx); err != nil {
return err
} else if vmType == cannonVMType {
createInitialState = func(f *elf.File) (mipsevm.FPVMState, error) {
return program.LoadELF(f, singlethreaded.CreateInitialState)
}
writeState = func(path string, state mipsevm.FPVMState) error {
return jsonutil.WriteJSON[*singlethreaded.State](path, state.(*singlethreaded.State), OutFilePerm)
}
} else if vmType == mtVMType {
createInitialState = func(f *elf.File) (mipsevm.FPVMState, error) {
return program.LoadELF(f, multithreaded.CreateInitialState)
}
writeState = func(path string, state mipsevm.FPVMState) error {
return jsonutil.WriteJSON[*multithreaded.State](path, state.(*multithreaded.State), OutFilePerm)
}
} else {
return fmt.Errorf("invalid VM type: %q", vmType)
}
elfPath := ctx.Path(LoadELFPathFlag.Name)
elfProgram, err := elf.Open(elfPath)
if err != nil {
Expand All @@ -47,7 +71,7 @@ func LoadELF(ctx *cli.Context) error {
if elfProgram.Machine != elf.EM_MIPS {
return fmt.Errorf("ELF is not big-endian MIPS R3000, but got %q", elfProgram.Machine.String())
}
state, err := program.LoadELF(elfProgram, singlethreaded.CreateInitialState)
state, err := createInitialState(elfProgram)
if err != nil {
return fmt.Errorf("failed to load ELF data into VM state: %w", err)
}
Expand All @@ -71,7 +95,7 @@ func LoadELF(ctx *cli.Context) error {
if err := jsonutil.WriteJSON[*program.Metadata](ctx.Path(LoadELFMetaFlag.Name), meta, OutFilePerm); err != nil {
return fmt.Errorf("failed to output metadata: %w", err)
}
return jsonutil.WriteJSON[*singlethreaded.State](ctx.Path(LoadELFOutFlag.Name), state, OutFilePerm)
return writeState(ctx.Path(LoadELFOutFlag.Name), state)
}

var LoadELFCommand = &cli.Command{
Expand All @@ -80,6 +104,7 @@ var LoadELFCommand = &cli.Command{
Description: "Load ELF file into Cannon JSON state, optionally patch out functions",
Action: LoadELF,
Flags: []cli.Flag{
VMTypeFlag,
LoadELFPathFlag,
LoadELFPatchFlag,
LoadELFOutFlag,
Expand Down
2 changes: 1 addition & 1 deletion cannon/cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package cmd

import (
"io"
"log/slog"
"os"

"golang.org/x/exp/slog"
"golang.org/x/term"

"github.com/ethereum/go-ethereum/log"
Expand Down
39 changes: 22 additions & 17 deletions cannon/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"time"

"github.com/ethereum-optimism/optimism/cannon/mipsevm/multithreaded"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/log"
Expand All @@ -24,13 +25,6 @@ import (
)

var (
RunType = &cli.StringFlag{
Name: "type",
Usage: "VM type to run. Options are 'cannon' (default)",
Value: "cannon",
// TODO(client-pod#903): This should be required once we have additional vm types
Required: false,
}
RunInputFlag = &cli.PathFlag{
Name: "input",
Usage: "path of input JSON state. Stdin if left empty.",
Expand Down Expand Up @@ -258,20 +252,14 @@ func Guard(proc *os.ProcessState, fn StepFn) StepFn {

var _ mipsevm.PreimageOracle = (*ProcessPreimageOracle)(nil)

type VMType string

var cannonVMType VMType = "cannon"

func Run(ctx *cli.Context) error {
if ctx.Bool(RunPProfCPU.Name) {
defer profile.Start(profile.NoShutdownHook, profile.ProfilePath("."), profile.CPUProfile).Stop()
}

var vmType VMType
if vmTypeStr := ctx.String(RunType.Name); vmTypeStr == string(cannonVMType) {
vmType = cannonVMType
} else {
return fmt.Errorf("unknown VM type %q", vmType)
vmType, err := vmTypeFromString(ctx)
if err != nil {
return err
}

guestLogger := Logger(os.Stderr, log.LevelInfo)
Expand Down Expand Up @@ -366,6 +354,7 @@ func Run(ctx *cli.Context) error {
var vm mipsevm.FPVM
var debugProgram bool
if vmType == cannonVMType {
l.Info("Using cannon VM")
cannon, err := singlethreaded.NewInstrumentedStateFromFile(ctx.Path(RunInputFlag.Name), po, outLog, errLog, meta)
if err != nil {
return err
Expand All @@ -380,6 +369,22 @@ func Run(ctx *cli.Context) error {
}
}
vm = cannon
} else if vmType == mtVMType {
l.Info("Using cannon multithreaded VM")
cannon, err := multithreaded.NewInstrumentedStateFromFile(ctx.Path(RunInputFlag.Name), po, outLog, errLog, l)
if err != nil {
return err
}
debugProgram = ctx.Bool(RunDebugFlag.Name)
if debugProgram {
if metaPath := ctx.Path(RunMetaFlag.Name); metaPath == "" {
return fmt.Errorf("cannot enable debug mode without a metadata file")
}
if err := cannon.InitDebug(meta); err != nil {
return fmt.Errorf("failed to initialize debug mode: %w", err)
}
}
vm = cannon
} else {
return fmt.Errorf("unknown VM type %q", vmType)
}
Expand Down Expand Up @@ -503,7 +508,7 @@ var RunCommand = &cli.Command{
Description: "Run VM step(s) and generate proof data to replicate onchain. See flags to match when to output a proof, a snapshot, or to stop early.",
Action: Run,
Flags: []cli.Flag{
RunType,
VMTypeFlag,
RunInputFlag,
RunOutputFlag,
RunProofAtFlag,
Expand Down
29 changes: 29 additions & 0 deletions cannon/cmd/vmtype.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cmd

import (
"fmt"

"github.com/urfave/cli/v2"
)

type VMType string

var cannonVMType VMType = "cannon"
var mtVMType VMType = "cannon-mt"

var VMTypeFlag = &cli.StringFlag{
Name: "type",
Usage: "VM type to create state for. Options are 'cannon' (default), 'cannon-mt'",
Value: "cannon",
Required: false,
}

func vmTypeFromString(ctx *cli.Context) (VMType, error) {
if vmTypeStr := ctx.String(VMTypeFlag.Name); vmTypeStr == string(cannonVMType) {
return cannonVMType, nil
} else if vmTypeStr == string(mtVMType) {
return mtVMType, nil
} else {
return "", fmt.Errorf("unknown VM type %q", vmTypeStr)
}
}
Loading

0 comments on commit b8bd100

Please sign in to comment.