Skip to content

Commit

Permalink
Merge branch 'sc/superchain-erc20-redesign' into chore/erc20-new-sola…
Browse files Browse the repository at this point in the history
…dy-version
  • Loading branch information
0xDiscotech committed Oct 3, 2024
2 parents 0938dd8 + 1981789 commit 62235f7
Show file tree
Hide file tree
Showing 483 changed files with 13,470 additions and 7,352 deletions.
349 changes: 83 additions & 266 deletions .circleci/config.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ packages/contracts-bedrock/deployments/anvil
!.envrc.example
*.log

.devnet
.devnet*

# Ignore local fuzzing results
**/testdata/fuzz/
Expand Down
20 changes: 19 additions & 1 deletion .semgrepignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,27 @@ tests/
.semgrep_logs/

op-chain-ops/script/testdata
op-chain-ops/script/testdata/scripts/ScriptExample.s.sol

packages/*/node_modules
packages/*/test

# Autogenerated solidity library
# TODO: Define these exclusions inside of the semgrep rules once those rules
# are all defined locally in the repository instead of the semgrep app.

# Contracts: autogenerated solidity library
packages/contracts-bedrock/scripts/libraries/Solarray.sol

# Contracts: vendor interfaces
packages/contracts-bedrock/scripts/interfaces/IGnosisSafe.sol
packages/contracts-bedrock/src/EAS/

# Contracts: deliberate exclusions
packages/contracts-bedrock/src/universal/WETH98.sol
packages/contracts-bedrock/src/universal/interfaces/IWETH.sol
packages/contracts-bedrock/src/L2/SuperchainWETH.sol
packages/contracts-bedrock/src/L2/interfaces/ISuperchainWETH.sol
packages/contracts-bedrock/src/governance/GovernanceToken.sol
packages/contracts-bedrock/src/governance/interfaces/IGovernanceToken.sol
packages/contracts-bedrock/src/dispute/interfaces/IFaultDisputeGame.sol
packages/contracts-bedrock/src/dispute/interfaces/IPermissionedDisputeGame.sol
21 changes: 17 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,21 @@ reproducible-prestate: ## Builds reproducible-prestate binary
.PHONY: reproducible-prestate

# Include any files required for the devnet to build and run.
DEVNET_CANNON_PRESTATE_FILES := op-program/bin/prestate-proof.json op-program/bin/prestate.json op-program/bin/prestate-proof-mt.json op-program/bin/prestate-mt.bin.gz
DEVNET_CANNON_PRESTATE_FILES := op-program/bin/prestate-proof.json op-program/bin/prestate.bin.gz op-program/bin/prestate-proof-mt.json op-program/bin/prestate-mt.bin.gz


$(DEVNET_CANNON_PRESTATE_FILES):
make cannon-prestate
make cannon-prestate-mt

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 ""
./cannon/bin/cannon load-elf --type singlethreaded-2 --path op-program/bin/op-program-client.elf --out op-program/bin/prestate.bin.gz --meta op-program/bin/meta.json
./cannon/bin/cannon run --proof-at '=0' --stop-at '=1' --input op-program/bin/prestate.bin.gz --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 cannon-mt --path op-program/bin/op-program-client.elf --out op-program/bin/prestate-mt.bin.gz --meta op-program/bin/meta-mt.json
./cannon/bin/cannon load-elf --type multithreaded --path op-program/bin/op-program-client.elf --out op-program/bin/prestate-mt.bin.gz --meta op-program/bin/meta-mt.json
./cannon/bin/cannon run --proof-at '=0' --stop-at '=1' --input op-program/bin/prestate-mt.bin.gz --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-mt
Expand Down Expand Up @@ -206,6 +206,19 @@ devnet-allocs: pre-devnet ## Generates allocations for the local devnet
PYTHONPATH=./bedrock-devnet $(PYTHON) ./bedrock-devnet/main.py --monorepo-dir=. --allocs
.PHONY: devnet-allocs

devnet-allocs-tests:
DEVNET_L2OO=true make devnet-allocs
cp -r .devnet/ .devnet-l2oo/
DEVNET_ALTDA=true make devnet-allocs
cp -r .devnet/ .devnet-alt-da/
DEVNET_ALTDA=false GENERIC_ALTDA=true make devnet-allocs
cp -r .devnet/ .devnet-alt-da-generic/
USE_MT_CANNON=true make devnet-allocs
cp -r .devnet/ .devnet-mt-cannon
make devnet-allocs
cp -r .devnet/ .devnet-standard/
.PHONY: devnet-allocs-tests

devnet-logs: ## Displays logs for the local devnet
@(cd ./ops-bedrock && docker compose logs -f)
.PHONY: devnet-logs
Expand Down
2 changes: 2 additions & 0 deletions bedrock-devnet/devnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from multiprocessing import Process, Queue
import concurrent.futures
from collections import namedtuple
# This import is necessary for devnet logs to be shown.
from . import log_setup


pjoin = os.path.join
Expand Down
4 changes: 1 addition & 3 deletions cannon/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ venv
*.log
testdata/example/bin
contracts/out
state.json
*.json
*.json.gz
*.pprof
*.out
bin
multicannon/embeds/cannon*
34 changes: 34 additions & 0 deletions cannon/Dockerfile.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM golang:1.22.7-alpine3.20 as builder

RUN apk add --no-cache make bash

COPY ./go.mod /app/go.mod
COPY ./go.sum /app/go.sum

WORKDIR /app

RUN echo "go mod cache: $(go env GOMODCACHE)"
RUN echo "go build cache: $(go env GOCACHE)"

RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build go mod download

COPY . /app

# We avoid copying the full .git dir into the build for just some metadata.
# Instead, specify:
# --build-arg GIT_COMMIT=$(git rev-parse HEAD)
# --build-arg GIT_DATE=$(git show -s --format='%ct')
ARG GIT_COMMIT
ARG GIT_DATE

ARG TARGETOS TARGETARCH

FROM --platform=$BUILDPLATFORM us-docker.pkg.dev/oplabs-tools-artifacts/images/cannon:v1.1.0-alpha.1 AS cannon-v2

FROM --platform=$BUILDPLATFORM builder as cannon-verify
COPY --from=cannon-v2 /usr/local/bin/cannon /usr/local/bin/cannon-v2
# verify the latest singlethreaded VM behavior against cannon-v2
RUN cd cannon && make diff-singlethreaded-2-cannon -e OTHER_CANNON=/usr/local/bin/cannon-v2
RUN --mount=type=cache,target=/root/.cache/go-build cd cannon && \
make diff-singlethreaded-2-cannon -e OTHER_CANNON=/usr/local/bin/cannon-v2 \
GOOS=$TARGETOS GOARCH=$TARGETARCH GITCOMMIT=$GIT_COMMIT GITDATE=$GIT_DATE
64 changes: 58 additions & 6 deletions cannon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,77 @@ VERSION ?= v0.0.0

LDFLAGSSTRING +=-X main.GitCommit=$(GITCOMMIT)
LDFLAGSSTRING +=-X main.GitDate=$(GITDATE)
LDFLAGSSTRING +=-X github.com/ethereum-optimism/optimism/op-program/version.Version=$(VERSION)
LDFLAGSSTRING +=-X github.com/ethereum-optimism/optimism/op-program/version.Meta=$(VERSION_META)
LDFLAGSSTRING +=-X github.com/ethereum-optimism/optimism/cannon/multicannon/version.Version=$(VERSION)
LDFLAGSSTRING +=-X github.com/ethereum-optimism/optimism/cannon/multicannon/version.Meta=$(VERSION_META)
LDFLAGS := -ldflags "$(LDFLAGSSTRING)"

# Use the old Apple linker to workaround broken xcode - https://github.com/golang/go/issues/65169
ifeq ($(shell uname),Darwin)
FUZZLDFLAGS := -ldflags=-extldflags=-Wl,-ld_classic
endif

cannon:
env GO111MODULE=on GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -v $(LDFLAGS) -o ./bin/cannon .
.DEFAULT_GOAL := cannon

cannon32-impl:
env GO111MODULE=on GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build --tags=cannon32 -v $(LDFLAGS) -o ./bin/cannon32-impl .

cannon64-impl:
env GO111MODULE=on GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build --tags=cannon64 -v $(LDFLAGS) -o ./bin/cannon64-impl .

cannon-embeds: cannon32-impl cannon64-impl
# singlethreaded-v2
@cp bin/cannon32-impl ./multicannon/embeds/cannon-2
# multithreaded
@cp bin/cannon32-impl ./multicannon/embeds/cannon-1
# 64-bit multithreaded
@cp bin/cannon64-impl ./multicannon/embeds/cannon-3

cannon: cannon-embeds
env GO111MODULE=on GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -v $(LDFLAGS) -o ./bin/cannon ./multicannon/

clean:
rm -rf bin
rm -rf bin multicannon/embeds/cannon*

elf:
make -C ./testdata/example elf

sanitize-program:
@if ! { mips-linux-gnu-objdump -d -j .text $$GUEST_PROGRAM | awk '{print $3}' | grep -Ew -m1 '(bgezal|bltzal)'; }; then \
echo "guest program is sanitized for unsupported instructions"; \
else \
echo "found unsupported instructions in the guest program"; \
exit 1; \
fi

contract:
cd ../packages/contracts-bedrock && forge build

test: elf contract
go test -v ./...

diff-%-cannon: cannon elf
$$OTHER_CANNON load-elf --type $* --path ./testdata/example/bin/hello.elf --out ./bin/prestate-other.bin.gz --meta ""
./bin/cannon load-elf --type $* --path ./testdata/example/bin/hello.elf --out ./bin/prestate.bin.gz --meta ""
@cmp ./bin/prestate-other.bin.gz ./bin/prestate.bin.gz
@if [ $$? -eq 0 ]; then \
echo "Generated identical prestates"; \
else \
echo "Generated different prestates"; \
exit 1; \
fi
$$OTHER_CANNON run --proof-at '=0' --stop-at '=100000000' --input=./bin/prestate.bin.gz --output ./bin/out-other.bin.gz --meta ""
./bin/cannon run --proof-at '=0' --stop-at '=100000000' --input=./bin/prestate.bin.gz --output ./bin/out.bin.gz --meta ""
@cmp ./bin/out-other.bin.gz ./bin/out.bin.gz
@if [ $$? -eq 0 ]; then \
echo "Generated identical states"; \
else \
echo "Generated different prestates"; \
exit 1; \
fi

cannon-stf-verify:
@docker build --progress plain -f Dockerfile.diff ../

fuzz:
# Common vm tests
go test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz=FuzzStateSyscallBrk ./mipsevm/tests
Expand All @@ -44,8 +91,13 @@ fuzz:
go test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz=FuzzStateSyscallCloneMT ./mipsevm/tests

.PHONY: \
cannon32-impl \
cannon64-impl \
cannon-embeds \
cannon \
clean \
test \
lint \
fuzz
fuzz \
diff-%-cannon \
cannon-stf-verify
2 changes: 1 addition & 1 deletion cannon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ make cannon

# Transform MIPS op-program client binary into first VM state.
# This outputs state.json (VM state) and meta.json (for debug symbols).
./bin/cannon load-elf --path=../op-program/bin/op-program-client.elf
./bin/cannon load-elf --type singlethreaded --path=../op-program/bin/op-program-client.elf

# Run cannon emulator (with example inputs)
# Note that the server-mode op-program command is passed into cannon (after the --),
Expand Down
66 changes: 32 additions & 34 deletions cannon/cmd/load_elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ import (
"github.com/ethereum-optimism/optimism/cannon/mipsevm/singlethreaded"
"github.com/ethereum-optimism/optimism/cannon/mipsevm/versions"
"github.com/ethereum-optimism/optimism/cannon/serialize"
openum "github.com/ethereum-optimism/optimism/op-service/enum"
"github.com/ethereum-optimism/optimism/op-service/ioutil"
"github.com/ethereum-optimism/optimism/op-service/jsonutil"
)

var (
LoadELFVMTypeFlag = &cli.StringFlag{
Name: "type",
Usage: "VM type to create state for. Options are 'cannon' (default), 'cannon-mt'",
Value: "cannon",
Required: false,
Usage: "VM type to create state for. Valid options: " + openum.EnumString(stateVersions()),
Required: true,
}
LoadELFPathFlag = &cli.PathFlag{
Name: "path",
Usage: "Path to 32-bit big-endian MIPS ELF file",
Usage: "Path to 32/64-bit big-endian MIPS ELF file",
TakesFile: true,
Required: true,
}
Expand All @@ -43,21 +43,12 @@ var (
}
)

type VMType string

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

func vmTypeFromString(ctx *cli.Context) (VMType, error) {
if vmTypeStr := ctx.String(LoadELFVMTypeFlag.Name); vmTypeStr == string(cannonVMType) {
return cannonVMType, nil
} else if vmTypeStr == string(mtVMType) {
return mtVMType, nil
} else {
return "", fmt.Errorf("unknown VM type %q", vmTypeStr)
func stateVersions() []string {
vers := make([]string, len(versions.StateVersionTypes))
for i, v := range versions.StateVersionTypes {
vers[i] = v.String()
}
return vers
}

func LoadELF(ctx *cli.Context) error {
Expand All @@ -73,9 +64,12 @@ func LoadELF(ctx *cli.Context) error {
var createInitialState func(f *elf.File) (mipsevm.FPVMState, error)

var patcher = program.PatchStack
if vmType, err := vmTypeFromString(ctx); err != nil {
ver, err := versions.ParseStateVersion(ctx.String(LoadELFVMTypeFlag.Name))
if err != nil {
return err
} else if vmType == cannonVMType {
}
switch ver {
case versions.VersionSingleThreaded2:
createInitialState = func(f *elf.File) (mipsevm.FPVMState, error) {
return program.LoadELF(f, singlethreaded.CreateInitialState)
}
Expand All @@ -86,12 +80,12 @@ func LoadELF(ctx *cli.Context) error {
}
return program.PatchStack(state)
}
} else if vmType == mtVMType {
case versions.VersionMultiThreaded, versions.VersionMultiThreaded64:
createInitialState = func(f *elf.File) (mipsevm.FPVMState, error) {
return program.LoadELF(f, multithreaded.CreateInitialState)
}
} else {
return fmt.Errorf("invalid VM type: %q", vmType)
default:
return fmt.Errorf("unsupported state version: %d (%s)", ver, ver.String())
}

state, err := createInitialState(elfProgram)
Expand All @@ -118,15 +112,19 @@ func LoadELF(ctx *cli.Context) error {
return serialize.Write(ctx.Path(LoadELFOutFlag.Name), versionedState, OutFilePerm)
}

var LoadELFCommand = &cli.Command{
Name: "load-elf",
Usage: "Load ELF file into Cannon state",
Description: "Load ELF file into Cannon state",
Action: LoadELF,
Flags: []cli.Flag{
LoadELFVMTypeFlag,
LoadELFPathFlag,
LoadELFOutFlag,
LoadELFMetaFlag,
},
func CreateLoadELFCommand(action cli.ActionFunc) *cli.Command {
return &cli.Command{
Name: "load-elf",
Usage: "Load ELF file into Cannon state",
Description: "Load ELF file into Cannon state",
Action: action,
Flags: []cli.Flag{
LoadELFVMTypeFlag,
LoadELFPathFlag,
LoadELFOutFlag,
LoadELFMetaFlag,
},
}
}

var LoadELFCommand = CreateLoadELFCommand(LoadELF)
Loading

0 comments on commit 62235f7

Please sign in to comment.