Skip to content

Commit

Permalink
Fixes in the runner
Browse files Browse the repository at this point in the history
  • Loading branch information
MaksymMalicki committed Dec 27, 2024
1 parent 8812042 commit 78cf788
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
7 changes: 3 additions & 4 deletions integration_tests/cairo_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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...,
Expand Down
28 changes: 18 additions & 10 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -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)",
Expand Down Expand Up @@ -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),
Expand All @@ -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{},
Expand Down
3 changes: 3 additions & 0 deletions pkg/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 78cf788

Please sign in to comment.