From 78cf788365664c3d6f69632dd5eea71b0b27d9e6 Mon Sep 17 00:00:00 2001 From: MaksymMalicki Date: Fri, 27 Dec 2024 23:01:39 +0100 Subject: [PATCH] Fixes in the runner --- integration_tests/cairo_vm_test.go | 7 +++---- pkg/runner/runner.go | 28 ++++++++++++++++++---------- pkg/vm/vm.go | 3 +++ 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/integration_tests/cairo_vm_test.go b/integration_tests/cairo_vm_test.go index 09c8d28c..fdbcee59 100644 --- a/integration_tests/cairo_vm_test.go +++ b/integration_tests/cairo_vm_test.go @@ -242,9 +242,9 @@ func TestCairoFiles(t *testing.T) { wg.Wait() // wait for all goroutines to finish - // for _, root := range roots { - // clean(root.path) - // } + for _, root := range roots { + clean(root.path) + } if *zerobench { WriteBenchMarksToFile(benchmarkMap) @@ -483,7 +483,6 @@ func runVm(path, layout string, zero bool) (time.Duration, string, string, strin } } args = append(args, path) - fmt.Println(args) cmd := exec.Command( "../bin/cairo-vm", args..., diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 92306433..6c22bfdb 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -242,21 +242,22 @@ func (runner *Runner) initializeBuiltins(memory *mem.Memory) ([]mem.MemoryValue, } // check if all builtins from the program are in the layout for _, programBuiltin := range runner.program.Builtins { - if programBuiltin != builtins.GasBuiltinType { - if _, found := builtinsSet[programBuiltin]; !found { - builtinName, err := programBuiltin.MarshalJSON() - if err != nil { - return []mem.MemoryValue{}, err - } - return []mem.MemoryValue{}, fmt.Errorf("builtin %s not found in the layout: %s", builtinName, runner.layout.Name) + if programBuiltin == builtins.GasBuiltinType || programBuiltin == builtins.SegmentArenaType { + continue + } + if _, found := builtinsSet[programBuiltin]; !found { + builtinName, err := programBuiltin.MarshalJSON() + if err != nil { + return []mem.MemoryValue{}, err } + return []mem.MemoryValue{}, fmt.Errorf("builtin %s not found in the layout: %s", builtinName, runner.layout.Name) } } stack := []mem.MemoryValue{} - // adding to the stack only the builtins that are both in the program and in the layout + for _, bRunner := range runner.layout.Builtins { - if utils.Contains(runner.program.Builtins, bRunner.Builtin) || runner.isProofMode() { - builtinSegment := memory.AllocateBuiltinSegment(bRunner.Runner) + builtinSegment := memory.AllocateBuiltinSegment(bRunner.Runner) + if utils.Contains(runner.program.Builtins, bRunner.Builtin) { stack = append(stack, mem.MemoryValueFromMemoryAddress(&builtinSegment)) } } @@ -309,6 +310,11 @@ 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)", @@ -545,6 +551,7 @@ 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), @@ -565,6 +572,7 @@ 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/vm/vm.go b/pkg/vm/vm.go index 7673f6ac..743c4c7c 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -94,6 +94,9 @@ type VirtualMachine struct { func (vm *VirtualMachine) PrintMemory() { for i := range vm.Memory.Segments { for j, cell := range vm.Memory.Segments[i].Data { + if !cell.Known() { + continue + } fmt.Printf("%d:%d %s\n", i, j, cell) } }