Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
mipsevm: implement mips in Go, no unicorn required anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
protolambda committed May 3, 2023
1 parent 2ab1eb7 commit fab95d1
Show file tree
Hide file tree
Showing 5 changed files with 596 additions and 19 deletions.
27 changes: 14 additions & 13 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ func Run(ctx *cli.Context) error {
if err != nil {
return err
}
mu, err := mipsevm.NewUnicorn()
if err != nil {
return fmt.Errorf("failed to create unicorn emulator: %w", err)
}
if err := mipsevm.LoadUnicorn(state, mu); err != nil {
return fmt.Errorf("failed to load state into unicorn emulator: %w", err)
}
//mu, err := mipsevm.NewUnicorn()
//if err != nil {
// return fmt.Errorf("failed to create unicorn emulator: %w", err)
//}
//if err := mipsevm.LoadUnicorn(state, mu); err != nil {
// return fmt.Errorf("failed to load state into unicorn emulator: %w", err)
//}
l := Logger(os.Stderr, log.LvlInfo)
outLog := &mipsevm.LoggingWriter{Name: "program std-out", Log: l}
errLog := &mipsevm.LoggingWriter{Name: "program std-err", Log: l}
Expand Down Expand Up @@ -207,14 +207,15 @@ func Run(ctx *cli.Context) error {
proofAt := ctx.Generic(RunProofAtFlag.Name).(*StepMatcherFlag).Matcher()
snapshotAt := ctx.Generic(RunSnapshotAtFlag.Name).(*StepMatcherFlag).Matcher()

us, err := mipsevm.NewUnicornState(mu, state, po, outLog, errLog)
if err != nil {
return fmt.Errorf("failed to setup instrumented VM state: %w", err)
}
//us, err := mipsevm.NewUnicornState(mu, state, po, outLog, errLog)
//if err != nil {
// return fmt.Errorf("failed to setup instrumented VM state: %w", err)
//}
us := mipsevm.NewNonUnicornState(state, po, outLog, errLog)
proofFmt := ctx.String(RunProofFmtFlag.Name)
snapshotFmt := ctx.String(RunSnapshotFmtFlag.Name)

stepFn := us.Step
stepFn := us.NonUnicornStep
if po.cmd != nil {
stepFn = Guard(po.cmd.ProcessState, stepFn)
}
Expand Down Expand Up @@ -262,7 +263,7 @@ func Run(ctx *cli.Context) error {
return fmt.Errorf("failed to write proof data: %w", err)
}
} else {
_, err = us.Step(false)
_, err = stepFn(false)
if err != nil {
return fmt.Errorf("failed at step %d (PC: %08x): %w", step, state.PC, err)
}
Expand Down
6 changes: 3 additions & 3 deletions mipsevm/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestEVM(t *testing.T) {
insn := state.Memory.GetMemory(state.PC)
t.Logf("step: %4d pc: 0x%08x insn: 0x%08x", state.Step, state.PC, insn)

stepWitness, err := us.Step(true)
stepWitness, err := us.NonUnicornStep(true)
require.NoError(t, err)
input := stepWitness.EncodeStepInput()
startingGas := uint64(30_000_000)
Expand Down Expand Up @@ -156,7 +156,7 @@ func TestHelloEVM(t *testing.T) {
t.Logf("step: %4d pc: 0x%08x insn: 0x%08x", state.Step, state.PC, insn)
}

stepWitness, err := us.Step(true)
stepWitness, err := us.NonUnicornStep(true)
require.NoError(t, err)
input := stepWitness.EncodeStepInput()
startingGas := uint64(30_000_000)
Expand Down Expand Up @@ -232,7 +232,7 @@ func TestClaimEVM(t *testing.T) {
t.Logf("step: %4d pc: 0x%08x insn: 0x%08x", state.Step, state.PC, insn)
}

stepWitness, err := us.Step(true)
stepWitness, err := us.NonUnicornStep(true)
require.NoError(t, err)
input := stepWitness.EncodeStepInput()
startingGas := uint64(30_000_000)
Expand Down
Loading

0 comments on commit fab95d1

Please sign in to comment.