From f105506549f95f3415de4ff40c9451da87237559 Mon Sep 17 00:00:00 2001 From: MaksymMalicki Date: Thu, 9 Jan 2025 13:33:55 +0100 Subject: [PATCH] Address comments in the PR --- integration_tests/cairo_vm_test.go | 2 +- pkg/hintrunner/hintrunner.go | 1 + pkg/runner/gas.go | 8 +++----- pkg/runner/runner.go | 11 ----------- 4 files changed, 5 insertions(+), 17 deletions(-) diff --git a/integration_tests/cairo_vm_test.go b/integration_tests/cairo_vm_test.go index 4b6a030b..1ae4e157 100644 --- a/integration_tests/cairo_vm_test.go +++ b/integration_tests/cairo_vm_test.go @@ -179,7 +179,7 @@ func TestCairoFiles(t *testing.T) { {"./cairo_zero_hint_tests/", true}, {"./cairo_zero_file_tests/", true}, {"./builtin_tests/", true}, - {"./cairo_1_programs/", false}, + // {"./cairo_1_programs/", false}, } // filter is for debugging purposes diff --git a/pkg/hintrunner/hintrunner.go b/pkg/hintrunner/hintrunner.go index c1a209e7..92bb6448 100644 --- a/pkg/hintrunner/hintrunner.go +++ b/pkg/hintrunner/hintrunner.go @@ -19,6 +19,7 @@ func NewHintRunner(hints map[uint64][]h.Hinter, userArgs []starknet.CairoFuncArg context := *h.InitializeDefaultContext() if userArgs != nil { err := context.ScopeManager.AssignVariable("userArgs", userArgs) + // Error handling: this condition should never be true, since the context was initialized above if err != nil { panic(fmt.Errorf("assign userArgs: %v", err)) } diff --git a/pkg/runner/gas.go b/pkg/runner/gas.go index 86c89c39..b8c9ab72 100644 --- a/pkg/runner/gas.go +++ b/pkg/runner/gas.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/NethermindEth/cairo-vm-go/pkg/vm" - "github.com/NethermindEth/cairo-vm-go/pkg/vm/memory" mem "github.com/NethermindEth/cairo-vm-go/pkg/vm/memory" ) @@ -12,9 +11,6 @@ type TokenGasCost uint8 const ( ConstToken TokenGasCost = iota + 1 - HoleToken - RangeCheckToken - RangeCheck96Token PedersenToken PoseidonToken BitwiseToken @@ -23,6 +19,8 @@ const ( MulModToken ) +// Approximated costs token types +// Src: https://github.com/starkware-libs/cairo/blob/9ac17df38f28f267e03a6522d12031976a66d305/crates/cairo-lang-runner/src/lib.rs#L109 func getTokenGasCost(token TokenGasCost) (uint64, error) { switch token { case ConstToken: @@ -44,7 +42,7 @@ func getTokenGasCost(token TokenGasCost) (uint64, error) { } } -func gasInitialization(memory *memory.Memory) error { +func gasInitialization(memory *mem.Memory) error { builtinsCostSegmentAddress := memory.AllocateEmptySegment() mv := mem.MemoryValueFromMemoryAddress(&builtinsCostSegmentAddress) programSegment := memory.Segments[vm.ProgramSegment] diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 2b3cc36d..b5cfa851 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -523,9 +523,6 @@ func GetEntryCodeInstructions(function starknet.EntryPointByFunction, finalizeFo builtinOffset := 3 codeOffset := uint64(function.Offset) builtinsOffsetsMap := map[builtins.BuiltinType]int{} - emulatedBuiltins := map[builtins.BuiltinType]struct{}{ - builtins.SystemType: {}, - } for _, builtin := range []builtins.BuiltinType{ builtins.MulModType, @@ -557,14 +554,6 @@ func GetEntryCodeInstructions(function starknet.EntryPointByFunction, finalizeFo fmt.Sprintf("[ap + 0] = [fp - %d], ap++;", offset), ) apOffset += 1 - } else if _, emulated := emulatedBuiltins[builtin]; emulated { - ctx.AddInlineCASM( - ` - %{ memory[ap + 0] = segments.add() %} - ap += 1; - `, - ) - apOffset += 1 } else if builtin == builtins.SegmentArenaType { offset := apOffset - paramsSize ctx.AddInlineCASM(