From 36a071c79214a1be5e21cab7232a4b308be9e3d1 Mon Sep 17 00:00:00 2001 From: Pedro Fontana Date: Tue, 19 Sep 2023 11:41:37 -0300 Subject: [PATCH] Implement usort_enter_scope Hint --- pkg/hints/hint_processor.go | 2 ++ pkg/hints/usort_hints.go | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/pkg/hints/hint_processor.go b/pkg/hints/hint_processor.go index f31400f9..63435512 100644 --- a/pkg/hints/hint_processor.go +++ b/pkg/hints/hint_processor.go @@ -69,6 +69,8 @@ func (p *CairoVmHintProcessor) ExecuteHint(vm *vm.VirtualMachine, hintData *any, return memcpy_enter_scope(data.Ids, vm, execScopes) case VM_ENTER_SCOPE: return vm_enter_scope(execScopes) + case USORT_ENTER_SCOPE: + return usort_enter_scope(execScopes) default: return errors.Errorf("Unknown Hint: %s", data.Code) } diff --git a/pkg/hints/usort_hints.go b/pkg/hints/usort_hints.go index ad6a6811..3d0a5d75 100644 --- a/pkg/hints/usort_hints.go +++ b/pkg/hints/usort_hints.go @@ -1 +1,28 @@ package hints + +import ( + "github.com/lambdaclass/cairo-vm.go/pkg/lambdaworks" + "github.com/lambdaclass/cairo-vm.go/pkg/types" +) + +// Implements hint: +// %{ vm_enter_scope(dict(__usort_max_size = globals().get('__usort_max_size'))) %} +func usort_enter_scope(executionScopes *types.ExecutionScopes) error { + usort_max_size, err := executionScopes.Get("usort_max_size") + + usort_max_size_felt := usort_max_size.(lambdaworks.Felt) + + if err != nil { + return err + } + + if usort_max_size == nil { + executionScopes.EnterScope(make(map[string]interface{})) + } + + scope := make(map[string]interface{}) + scope["usort_max_size"] = usort_max_size_felt + executionScopes.EnterScope(scope) + + return nil +}