diff --git a/integration_tests/cairo_vm_test.go b/integration_tests/cairo_vm_test.go index fdbcee59..4b6a030b 100644 --- a/integration_tests/cairo_vm_test.go +++ b/integration_tests/cairo_vm_test.go @@ -75,7 +75,7 @@ func runAndTestFile(t *testing.T, path string, name string, benchmarkMap map[str } layout := getLayoutFromFileName(path) - _, traceFile, memoryFile, _, err := runVm(compiledOutput, layout, zero) + elapsedGo, traceFile, memoryFile, _, err := runVm(compiledOutput, layout, zero) if errorExpected { assert.Error(t, err, path) writeToFile(path) @@ -92,7 +92,7 @@ func runAndTestFile(t *testing.T, path string, name string, benchmarkMap map[str if zero { rustVmFilePath = compiledOutput } - _, rsTraceFile, rsMemoryFile, err := runRustVm(rustVmFilePath, layout, zero) + elapsedRs, rsTraceFile, rsMemoryFile, err := runRustVm(rustVmFilePath, layout, zero) if errorExpected { // we let the code go on so that we can check if the go vm also raises an error assert.Error(t, err, path) @@ -129,49 +129,39 @@ func runAndTestFile(t *testing.T, path string, name string, benchmarkMap map[str writeToFile(path) } - // if zero { - // elapsedPy, pyTraceFile, pyMemoryFile, err := runPythonVm(compiledOutput, layout) - // if errorExpected { - // // we let the code go on so that we can check if the go vm also raises an error - // assert.Error(t, err, path) - // } else { - // if err != nil { - // t.Error(err) - // return - // } - // } - - // if benchmark { - // benchmarkMap[name] = [3]int{int(elapsedPy.Milliseconds()), int(elapsedGo.Milliseconds()), int(elapsedRs.Milliseconds())} - // } - - // pyTrace, pyMemory, err := decodeProof(pyTraceFile, pyMemoryFile) - // if err != nil { - // t.Error(err) - // return - // } - - // if !assert.Equal(t, pyTrace, rsTrace) { - // t.Logf("pytrace:\n%s\n", traceRepr(pyTrace)) - // t.Logf("rstrace:\n%s\n", traceRepr(rsTrace)) - // writeToFile(path) - // } - // if !assert.Equal(t, pyMemory, rsMemory) { - // t.Logf("pymemory;\n%s\n", memoryRepr(pyMemory)) - // t.Logf("rsmemory;\n%s\n", memoryRepr(rsMemory)) - // writeToFile(path) - // } - // if !assert.Equal(t, pyTrace, trace) { - // t.Logf("pytrace:\n%s\n", traceRepr(pyTrace)) - // t.Logf("trace:\n%s\n", traceRepr(trace)) - // writeToFile(path) - // } - // if !assert.Equal(t, pyMemory, memory) { - // t.Logf("pymemory;\n%s\n", memoryRepr(pyMemory)) - // t.Logf("memory;\n%s\n", memoryRepr(memory)) - // writeToFile(path) - // } - // } + if zero { + elapsedPy, pyTraceFile, pyMemoryFile, err := runPythonVm(compiledOutput, layout) + if errorExpected { + // we let the code go on so that we can check if the go vm also raises an error + assert.Error(t, err, path) + } else { + if err != nil { + t.Error(err) + return + } + } + + if benchmark { + benchmarkMap[name] = [3]int{int(elapsedPy.Milliseconds()), int(elapsedGo.Milliseconds()), int(elapsedRs.Milliseconds())} + } + + pyTrace, pyMemory, err := decodeProof(pyTraceFile, pyMemoryFile) + if err != nil { + t.Error(err) + return + } + + if !assert.Equal(t, pyTrace, trace) { + t.Logf("pytrace:\n%s\n", traceRepr(pyTrace)) + t.Logf("trace:\n%s\n", traceRepr(trace)) + writeToFile(path) + } + if !assert.Equal(t, pyMemory, memory) { + t.Logf("pymemory;\n%s\n", memoryRepr(pyMemory)) + t.Logf("memory;\n%s\n", memoryRepr(memory)) + writeToFile(path) + } + } } var zerobench = flag.Bool("zerobench", false, "run integration tests and generate benchmarks file") diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 6e9e06ca..057c97a1 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -190,6 +190,7 @@ func (runner *Runner) initializeMainEntrypoint() (mem.MemoryAddress, error) { return runner.initializeEntrypoint(mainPCOffset, nil, &mvReturnFp, memory, stack, 0) } case ProofModeZero: + fmt.Println("program: ", runner.program.Labels) initialPCOffset, ok := runner.program.Labels["__start__"] if !ok { return mem.UnknownAddress, @@ -295,7 +296,6 @@ func (runner *Runner) initializeVm( return err } } - fmt.Println("offset", offset, "stackSize", stackSize, "cairo1FpOffset", cairo1FpOffset) initialFp := offset + uint64(len(stack)) + cairo1FpOffset var err error // initialize vm @@ -313,11 +313,6 @@ func (runner *Runner) initializeVm( // run until the program counter equals the `pc` parameter func (runner *Runner) RunUntilPc(pc *mem.MemoryAddress) error { for !runner.vm.Context.Pc.Equal(pc) { - fmt.Println("pc", runner.pc(), "ap", runner.vm.Context.Ap, "fp", runner.vm.Context.Fp) - // if runner.steps() == 4 { - // runner.vm.PrintMemory() - // } - // runner.vm.PrintMemory() if runner.steps() >= runner.maxsteps { return fmt.Errorf( "pc %s step %d: max step limit exceeded (%d)", @@ -554,7 +549,6 @@ func GetEntryCodeInstructions(function starknet.EntryPointByFunction, finalizeFo usedArgs := 0 var hints map[uint64][]hinter.Hinter for _, builtin := range function.Builtins { - fmt.Println("builtin", builtin, builtin == builtins.GasBuiltinType) if offset, isBuiltin := builtinsOffsetsMap[builtin]; isBuiltin { ctx.AddInlineCASM( fmt.Sprintf("[ap + 0] = [fp - %d], ap++;", offset), @@ -575,7 +569,6 @@ func GetEntryCodeInstructions(function starknet.EntryPointByFunction, finalizeFo ) apOffset += 1 } else if builtin == builtins.GasBuiltinType { - fmt.Println("builtin == builtins.GasBuiltinType") hints = map[uint64][]hinter.Hinter{ uint64(ctx.currentCodeOffset): { &core.ExternalWriteArgsToMemory{}, diff --git a/pkg/runner/runner_test.go b/pkg/runner/runner_test.go index a20c074b..50ded3f4 100644 --- a/pkg/runner/runner_test.go +++ b/pkg/runner/runner_test.go @@ -434,9 +434,8 @@ func TestModuloBuiltin(t *testing.T) { func createRunner(code string, layoutName string, builtins ...builtins.BuiltinType) Runner { program := createProgramWithBuiltins(code, builtins...) - hints := make(map[uint64][]hinter.Hinter) - runner, err := NewRunner(program, hints, ProofModeZero, false, math.MaxUint64, layoutName, nil) + runner, err := NewRunner(program, hints, ExecutionModeZero, false, math.MaxUint64, layoutName, nil) if err != nil { panic(err) }