Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: convert felt to uint64 in hints where possible #484

Merged
merged 10 commits into from
Jul 3, 2024
11 changes: 5 additions & 6 deletions pkg/hintrunner/zero/zerohint_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ func newMemContinueHint(continueTarget hinter.ResOperander, memset bool) hinter.
return err
}

newN, ok := n.(fp.Element)
newN, ok := n.(uint64)
if !ok {
return fmt.Errorf("casting n into a felt failed")
TAdev0 marked this conversation as resolved.
Show resolved Hide resolved
}

newN.Sub(&newN, &utils.FeltOne)
newN = newN - 1

if err := ctx.ScopeManager.AssignVariable("n", newN); err != nil {
return err
Expand All @@ -55,7 +54,7 @@ func newMemContinueHint(continueTarget hinter.ResOperander, memset bool) hinter.
}

var continueTargetMv memory.MemoryValue
if utils.FeltLt(&utils.FeltZero, &newN) {
if newN > 0 {
continueTargetMv = memory.MemoryValueFromFieldElement(&utils.FeltOne)
} else {
continueTargetMv = memory.MemoryValueFromFieldElement(&utils.FeltZero)
Expand Down Expand Up @@ -127,12 +126,12 @@ func newMemEnterScopeHint(value hinter.ResOperander, memset bool) hinter.Hinter
// MemcpyEnterScope
//> vm_enter_scope({'n': ids.len})

value, err := hinter.ResolveAsFelt(vm, value)
value, err := hinter.ResolveAsUint64(vm, value)
if err != nil {
return err
}

ctx.ScopeManager.EnterScope(map[string]any{"n": *value})
ctx.ScopeManager.EnterScope(map[string]any{"n": value})
return nil
},
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/hintrunner/zero/zerohint_others_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestZeroHintOthers(t *testing.T) {
{Name: "continue_copying", Kind: uninitialized},
},
ctxInit: func(ctx *hinter.HintRunnerContext) {
err := ctx.ScopeManager.AssignVariable("n", *feltInt64(1))
err := ctx.ScopeManager.AssignVariable("n", uint64(1))
if err != nil {
t.Fatal(err)
}
Expand All @@ -25,7 +25,7 @@ func TestZeroHintOthers(t *testing.T) {
return newMemContinueHint(ctx.operanders["continue_copying"], false)
},
check: func(t *testing.T, ctx *hintTestContext) {
varValueInScopeEquals("n", *feltInt64(0))(t, ctx)
varValueInScopeEquals("n", uint64(0))(t, ctx)
varValueEquals("continue_copying", feltInt64(0))(t, ctx)
},
},
Expand All @@ -34,7 +34,7 @@ func TestZeroHintOthers(t *testing.T) {
{Name: "continue_copying", Kind: uninitialized},
},
ctxInit: func(ctx *hinter.HintRunnerContext) {
err := ctx.ScopeManager.AssignVariable("n", *feltInt64(5))
err := ctx.ScopeManager.AssignVariable("n", uint64(5))
if err != nil {
t.Fatal(err)
}
Expand All @@ -43,7 +43,7 @@ func TestZeroHintOthers(t *testing.T) {
return newMemContinueHint(ctx.operanders["continue_copying"], false)
},
check: func(t *testing.T, ctx *hintTestContext) {
varValueInScopeEquals("n", *feltInt64(4))(t, ctx)
varValueInScopeEquals("n", uint64(4))(t, ctx)
varValueEquals("continue_copying", feltInt64(1))(t, ctx)
},
},
Expand All @@ -56,7 +56,7 @@ func TestZeroHintOthers(t *testing.T) {
makeHinter: func(ctx *hintTestContext) hinter.Hinter {
return newMemEnterScopeHint(ctx.operanders["len"], false)
},
check: varValueInScopeEquals("n", *feltUint64(1)),
check: varValueInScopeEquals("n", uint64(1)),
},
},
"SearchSortedLower": {
Expand Down
Loading