Skip to content

Commit

Permalink
Fixes for dict relocation
Browse files Browse the repository at this point in the history
  • Loading branch information
MaksymMalicki committed Feb 21, 2025
1 parent ef6d244 commit c687d70
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
7 changes: 1 addition & 6 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,6 @@ func runVM(
if err := cairoRunner.FinalizeSegments(); err != nil {
return fmt.Errorf("cannot finalize segments: %w", err)
}
case runner.ExecutionModeCairo:
if airPublicInputLocation != "" {
if err := cairoRunner.FinalizeBuiltins(); err != nil {
return fmt.Errorf("cannot finalize builtins: %w", err)
}
}
case runner.ProofModeCairo:
if err := cairoRunner.EndRun(); err != nil {
return fmt.Errorf("cannot end run: %w", err)
Expand Down Expand Up @@ -320,6 +314,7 @@ func runVM(
}
}
}

var segmentsOffsets []uint64
var relocatedMemory []*fp.Element
if proofmode || buildMemory {
Expand Down
27 changes: 14 additions & 13 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,15 +670,27 @@ func GetEntryCodeInstructions(function starknet.EntryPointByFunction, proofmode
}
hints := make(map[uint64][]hinter.Hinter)

paramsSize := 0
for _, param := range paramTypes {
paramsSize += param.Size
}

// The hint can be executed before the first instruction, because the AP correction was calculated based on the input arguments.
if paramsSize > 0 {
hints[uint64(0)] = append(hints[uint64(0)], []hinter.Hinter{
&core.ExternalWriteArgsToMemory{},
}...)
}

if gotSegmentArena {
hints[uint64(ctx.currentCodeOffset)] = []hinter.Hinter{
hints[uint64(ctx.currentCodeOffset)] = append(hints[uint64(ctx.currentCodeOffset)], []hinter.Hinter{
&core.AllocSegment{
Dst: hinter.ApCellRef(0),
},
&core.AllocSegment{
Dst: hinter.ApCellRef(1),
},
}
}...)
ctx.AddInlineCASM(
"[ap+2] = 0, ap++;",
)
Expand All @@ -694,10 +706,6 @@ func GetEntryCodeInstructions(function starknet.EntryPointByFunction, proofmode
apOffset += 3
}

paramsSize := 0
for _, param := range paramTypes {
paramsSize += param.Size
}
apOffset += paramsSize
gotGasBuiltin := false

Expand Down Expand Up @@ -728,13 +736,6 @@ func GetEntryCodeInstructions(function starknet.EntryPointByFunction, proofmode
)
}

// The hint can be executed before the first instruction, because the AP correction was calculated based on the input arguments.
if paramsSize > 0 {
hints[uint64(0)] = append(hints[uint64(0)], []hinter.Hinter{
&core.ExternalWriteArgsToMemory{},
}...)
}

codeOffsetBeforeCallRel := uint64(codeOffset) - uint64(ctx.currentCodeOffset)
ctx.AddInlineCASM("call rel 0;")
callRelArgLocation := len(ctx.instructions) - 1
Expand Down
5 changes: 4 additions & 1 deletion pkg/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ type VirtualMachine struct {
RcLimitsMax uint16
}

func (vm *VirtualMachine) PrintMemory() {
func (vm *VirtualMachine) PrintMemory(skipBytecode bool) {
for i := range vm.Memory.Segments {
if skipBytecode && i == ProgramSegment {
continue
}
for j, cell := range vm.Memory.Segments[i].Data {
if !cell.Known() {
continue
Expand Down

0 comments on commit c687d70

Please sign in to comment.