Skip to content

Commit

Permalink
Merge pull request #93 from defi-wonderland/fix/superchain-erc20-fact…
Browse files Browse the repository at this point in the history
…ory-merge-conflicts

fix: superchain erc20 factory merge conflicts
  • Loading branch information
agusduha authored Oct 11, 2024
2 parents 6c46f9b + 061b1ff commit 97fb300
Show file tree
Hide file tree
Showing 69 changed files with 2,850 additions and 506 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ jobs:
- run:
name: Generate allocs
command: |
make devnet-allocs-tests
make devnet-allocs
- save_cache:
name: Save Go modules cache
key: gomod-contracts-build-{{ checksum "go.sum" }}
Expand Down Expand Up @@ -1369,7 +1369,7 @@ jobs:
name: Build contracts
environment:
FOUNDRY_PROFILE: ci
command: just build
command: just forge-build
working_directory: packages/contracts-bedrock
- run:
name: Publish artifacts
Expand Down
32 changes: 0 additions & 32 deletions .github/workflows/slither.yml

This file was deleted.

20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pre-devnet: submodules $(DEVNET_CANNON_PRESTATE_FILES)

devnet-up: pre-devnet ## Starts the local devnet
./ops/scripts/newer-file.sh .devnet/allocs-l1.json ./packages/contracts-bedrock \
|| make devnet-allocs
|| make devnet-allocs-single
PYTHONPATH=./bedrock-devnet $(PYTHON) ./bedrock-devnet/main.py --monorepo-dir=.
.PHONY: devnet-up

Expand All @@ -202,22 +202,22 @@ devnet-clean: ## Cleans up local devnet environment
docker volume ls --filter name=ops-bedrock --format='{{.Name}}' | xargs -r docker volume rm
.PHONY: devnet-clean

devnet-allocs: pre-devnet ## Generates allocations for the local devnet
devnet-allocs-single: pre-devnet ## Generates allocations for the local devnet
PYTHONPATH=./bedrock-devnet $(PYTHON) ./bedrock-devnet/main.py --monorepo-dir=. --allocs
.PHONY: devnet-allocs
.PHONY: devnet-allocs-single

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

devnet-logs: ## Displays logs for the local devnet
@(cd ./ops-bedrock && docker compose logs -f)
Expand Down
6 changes: 3 additions & 3 deletions cannon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ cd ../cannon
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 --type singlethreaded --path=../op-program/bin/op-program-client.elf
# This outputs state.bin.gz (VM state) and meta.json (for debug symbols).
./bin/cannon load-elf --type singlethreaded-2 --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 All @@ -45,7 +45,7 @@ make cannon
--proof-at '=<TRACE_INDEX>' \
--stop-at '=<STOP_INDEX>' \
--snapshot-at '%1000000000' \
--input ./state.json \
--input ./state.bin.gz \
-- \
../op-program/bin/op-program \
--network op-mainnet \
Expand Down
2 changes: 1 addition & 1 deletion cannon/cmd/load_elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (
LoadELFOutFlag = &cli.PathFlag{
Name: "out",
Usage: "Output path to write state to. State is dumped to stdout if set to '-'. Not written if empty. Use file extension '.bin', '.bin.gz', or '.json' for binary, compressed binary, or JSON formats.",
Value: "state.json",
Value: "state.bin.gz",
Required: false,
}
LoadELFMetaFlag = &cli.PathFlag{
Expand Down
1 change: 0 additions & 1 deletion cannon/mipsevm/multithreaded/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ func (s *State) EncodeThreadProof() []byte {
out := make([]byte, 0, THREAD_WITNESS_SIZE)
out = append(out, threadBytes[:]...)
out = append(out, otherThreadsWitness[:]...)

return out
}

Expand Down
130 changes: 98 additions & 32 deletions cannon/mipsevm/tests/evm_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func TestEVM(t *testing.T) {

cases := GetMipsVersionTestCases(t)
skippedTests := map[string][]string{
"multi-threaded": []string{"clone.bin"},
"single-threaded": []string{},
"multi-threaded": {"clone.bin"},
"single-threaded": {},
}

for _, c := range cases {
Expand Down Expand Up @@ -248,31 +248,31 @@ func TestEVMSingleStep_LoadStore(t *testing.T) {
versions := GetMipsVersionTestCases(t)
cases := []struct {
name string
rs uint32
rt uint32
rs Word
rt Word
isUnAligned bool
opcode uint32
memVal uint32
expectMemVal uint32
expectRes uint32
memVal Word
expectMemVal Word
expectRes Word
}{
{name: "lb", opcode: uint32(0x20), memVal: uint32(0x12_00_00_00), expectRes: uint32(0x12)}, // lb $t0, 4($t1)
{name: "lh", opcode: uint32(0x21), memVal: uint32(0x12_23_00_00), expectRes: uint32(0x12_23)}, // lh $t0, 4($t1)
{name: "lw", opcode: uint32(0x23), memVal: uint32(0x12_23_45_67), expectRes: uint32(0x12_23_45_67)}, // lw $t0, 4($t1)
{name: "lbu", opcode: uint32(0x24), memVal: uint32(0x12_23_00_00), expectRes: uint32(0x12)}, // lbu $t0, 4($t1)
{name: "lhu", opcode: uint32(0x25), memVal: uint32(0x12_23_00_00), expectRes: uint32(0x12_23)}, // lhu $t0, 4($t1)
{name: "lwl", opcode: uint32(0x22), rt: uint32(0xaa_bb_cc_dd), memVal: uint32(0x12_34_56_78), expectRes: uint32(0x12_34_56_78)}, // lwl $t0, 4($t1)
{name: "lwl unaligned address", opcode: uint32(0x22), rt: uint32(0xaa_bb_cc_dd), isUnAligned: true, memVal: uint32(0x12_34_56_78), expectRes: uint32(0x34_56_78_dd)}, // lwl $t0, 5($t1)
{name: "lwr", opcode: uint32(0x26), rt: uint32(0xaa_bb_cc_dd), memVal: uint32(0x12_34_56_78), expectRes: uint32(0xaa_bb_cc_12)}, // lwr $t0, 4($t1)
{name: "lwr unaligned address", opcode: uint32(0x26), rt: uint32(0xaa_bb_cc_dd), isUnAligned: true, memVal: uint32(0x12_34_56_78), expectRes: uint32(0xaa_bb_12_34)}, // lwr $t0, 5($t1)
{name: "sb", opcode: uint32(0x28), rt: uint32(0xaa_bb_cc_dd), expectMemVal: uint32(0xdd_00_00_00)}, // sb $t0, 4($t1)
{name: "sh", opcode: uint32(0x29), rt: uint32(0xaa_bb_cc_dd), expectMemVal: uint32(0xcc_dd_00_00)}, // sh $t0, 4($t1)
{name: "swl", opcode: uint32(0x2a), rt: uint32(0xaa_bb_cc_dd), expectMemVal: uint32(0xaa_bb_cc_dd)}, // swl $t0, 4($t1)
{name: "sw", opcode: uint32(0x2b), rt: uint32(0xaa_bb_cc_dd), expectMemVal: uint32(0xaa_bb_cc_dd)}, // sw $t0, 4($t1)
{name: "swr unaligned address", opcode: uint32(0x2e), rt: uint32(0xaa_bb_cc_dd), isUnAligned: true, expectMemVal: uint32(0xcc_dd_00_00)}, // swr $t0, 5($t1)
{name: "lb", opcode: uint32(0x20), memVal: Word(0x12_00_00_00), expectRes: Word(0x12)}, // lb $t0, 4($t1)
{name: "lh", opcode: uint32(0x21), memVal: Word(0x12_23_00_00), expectRes: Word(0x12_23)}, // lh $t0, 4($t1)
{name: "lw", opcode: uint32(0x23), memVal: Word(0x12_23_45_67), expectRes: Word(0x12_23_45_67)}, // lw $t0, 4($t1)
{name: "lbu", opcode: uint32(0x24), memVal: Word(0x12_23_00_00), expectRes: Word(0x12)}, // lbu $t0, 4($t1)
{name: "lhu", opcode: uint32(0x25), memVal: Word(0x12_23_00_00), expectRes: Word(0x12_23)}, // lhu $t0, 4($t1)
{name: "lwl", opcode: uint32(0x22), rt: Word(0xaa_bb_cc_dd), memVal: Word(0x12_34_56_78), expectRes: Word(0x12_34_56_78)}, // lwl $t0, 4($t1)
{name: "lwl unaligned address", opcode: uint32(0x22), rt: Word(0xaa_bb_cc_dd), isUnAligned: true, memVal: Word(0x12_34_56_78), expectRes: Word(0x34_56_78_dd)}, // lwl $t0, 5($t1)
{name: "lwr", opcode: uint32(0x26), rt: Word(0xaa_bb_cc_dd), memVal: Word(0x12_34_56_78), expectRes: Word(0xaa_bb_cc_12)}, // lwr $t0, 4($t1)
{name: "lwr unaligned address", opcode: uint32(0x26), rt: Word(0xaa_bb_cc_dd), isUnAligned: true, memVal: Word(0x12_34_56_78), expectRes: Word(0xaa_bb_12_34)}, // lwr $t0, 5($t1)
{name: "sb", opcode: uint32(0x28), rt: Word(0xaa_bb_cc_dd), expectMemVal: Word(0xdd_00_00_00)}, // sb $t0, 4($t1)
{name: "sh", opcode: uint32(0x29), rt: Word(0xaa_bb_cc_dd), expectMemVal: Word(0xcc_dd_00_00)}, // sh $t0, 4($t1)
{name: "swl", opcode: uint32(0x2a), rt: Word(0xaa_bb_cc_dd), expectMemVal: Word(0xaa_bb_cc_dd)}, // swl $t0, 4($t1)
{name: "sw", opcode: uint32(0x2b), rt: Word(0xaa_bb_cc_dd), expectMemVal: Word(0xaa_bb_cc_dd)}, // sw $t0, 4($t1)
{name: "swr unaligned address", opcode: uint32(0x2e), rt: Word(0xaa_bb_cc_dd), isUnAligned: true, expectMemVal: Word(0xcc_dd_00_00)}, // swr $t0, 5($t1)
}

var t1 uint32 = 0x100
var t1 Word = 0x100
var baseReg uint32 = 9
var rtReg uint32 = 8
for _, v := range versions {
Expand All @@ -292,15 +292,15 @@ func TestEVMSingleStep_LoadStore(t *testing.T) {
state.GetRegistersRef()[baseReg] = t1

state.GetMemory().SetUint32(0, insn)
state.GetMemory().SetUint32(t1+4, tt.memVal)
state.GetMemory().SetWord(t1+4, tt.memVal)
step := state.GetStep()

// Setup expectations
expected := testutil.NewExpectedState(state)
expected.ExpectStep()

if tt.expectMemVal != 0 {
expected.ExpectMemoryWrite(t1+4, tt.expectMemVal)
expected.ExpectMemoryWriteWord(t1+4, tt.expectMemVal)
} else {
expected.Registers[rtReg] = tt.expectRes
}
Expand All @@ -315,6 +315,69 @@ func TestEVMSingleStep_LoadStore(t *testing.T) {
}
}

func TestEVMSingleStep_MovzMovn(t *testing.T) {
var tracer *tracing.Hooks
versions := GetMipsVersionTestCases(t)
cases := []struct {
name string
funct uint32
}{
{name: "movz", funct: uint32(0xa)},
{name: "movn", funct: uint32(0xb)},
}
for _, v := range versions {
for i, tt := range cases {
testName := fmt.Sprintf("%v (%v)", tt.name, v.Name)
t.Run(testName, func(t *testing.T) {
goVm := v.VMFactory(nil, os.Stdout, os.Stderr, testutil.CreateLogger(), testutil.WithRandomization(int64(i)), testutil.WithPC(0), testutil.WithNextPC(4))
state := goVm.GetState()
rsReg := uint32(9)
rtReg := uint32(10)
rdReg := uint32(8)
insn := rsReg<<21 | rtReg<<16 | rdReg<<11 | tt.funct
var t2 Word
if tt.funct == 0xa {
t2 = 0x0
} else {
t2 = 0x1
}
state.GetRegistersRef()[rtReg] = t2
state.GetRegistersRef()[rsReg] = Word(0xb)
state.GetRegistersRef()[rdReg] = Word(0xa)
state.GetMemory().SetUint32(0, insn)
step := state.GetStep()
// Setup expectations
expected := testutil.NewExpectedState(state)
expected.ExpectStep()
expected.Registers[rdReg] = state.GetRegistersRef()[rsReg]

stepWitness, err := goVm.Step(true)
require.NoError(t, err)
// Check expectations
expected.Validate(t, state)
testutil.ValidateEVM(t, stepWitness, step, goVm, v.StateHashFn, v.Contracts, tracer)

if tt.funct == 0xa {
t2 = 0x1
} else {
t2 = 0x0
}
state.GetRegistersRef()[rtReg] = t2
expected.ExpectStep()
expected.Registers[rtReg] = t2
expected.Registers[rdReg] = state.GetRegistersRef()[rdReg]

stepWitness, err = goVm.Step(true)
require.NoError(t, err)
// Check expectations
expected.Validate(t, state)
testutil.ValidateEVM(t, stepWitness, step, goVm, v.StateHashFn, v.Contracts, tracer)
})
}
}

}

func TestEVM_MMap(t *testing.T) {
var tracer *tracing.Hooks

Expand Down Expand Up @@ -580,13 +643,15 @@ func TestEVMFault(t *testing.T) {

versions := GetMipsVersionTestCases(t)
cases := []struct {
name string
nextPC arch.Word
insn uint32
name string
nextPC arch.Word
insn uint32
errMsg string
memoryProofAddresses []Word
}{
{"illegal instruction", 0, 0xFF_FF_FF_FF},
{"branch in delay-slot", 8, 0x11_02_00_03},
{"jump in delay-slot", 8, 0x0c_00_00_0c},
{"illegal instruction", 0, 0xFF_FF_FF_FF, "invalid instruction", []Word{0xa7ef00cc}},
{"branch in delay-slot", 8, 0x11_02_00_03, "branch in delay slot", []Word{}},
{"jump in delay-slot", 8, 0x0c_00_00_0c, "jump in delay slot", []Word{}},
}

for _, v := range versions {
Expand All @@ -599,8 +664,9 @@ func TestEVMFault(t *testing.T) {
// set the return address ($ra) to jump into when test completes
state.GetRegistersRef()[31] = testutil.EndAddr

require.Panics(t, func() { _, _ = goVm.Step(true) })
testutil.AssertEVMReverts(t, state, v.Contracts, tracer)
proofData := v.ProofGenerator(t, goVm.GetState(), tt.memoryProofAddresses...)
require.Panics(t, func() { _, _ = goVm.Step(false) })
testutil.AssertEVMReverts(t, state, v.Contracts, tracer, proofData, tt.errMsg)
})
}
}
Expand Down
6 changes: 4 additions & 2 deletions cannon/mipsevm/tests/evm_multithreaded_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1183,10 +1183,12 @@ func TestEVM_UnsupportedSyscall(t *testing.T) {
// Setup basic getThreadId syscall instruction
state.Memory.SetUint32(state.GetPC(), syscallInsn)
state.GetRegistersRef()[2] = Word(syscallNum)

proofData := multiThreadedProofGenerator(t, state)
// Set up post-state expectations
require.Panics(t, func() { _, _ = goVm.Step(true) })
testutil.AssertEVMReverts(t, state, contracts, tracer)

errorMessage := "MIPS2: unimplemented syscall"
testutil.AssertEVMReverts(t, state, contracts, tracer, proofData, errorMessage)
})
}
}
Expand Down
Loading

0 comments on commit 97fb300

Please sign in to comment.