Skip to content

Commit

Permalink
Merge branch 'main' into Keccak_integration_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TAdev0 committed Jul 3, 2024
2 parents 026267b + 707d13f commit d67a992
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
16 changes: 14 additions & 2 deletions integration_tests/cairo_zero_hint_tests/ec.small.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
%builtins range_check

from starkware.cairo.common.cairo_secp.bigint import BigInt3
from starkware.cairo.common.cairo_secp.ec import EcPoint, ec_negate, compute_doubling_slope, compute_slope, ec_double, fast_ec_add

from starkware.cairo.common.cairo_secp.ec import EcPoint, ec_negate, compute_doubling_slope, compute_slope, ec_double, fast_ec_add, ec_mul_inner
func test_ec_negate{range_check_ptr}() {
let p = EcPoint(BigInt3(1, 2, 3), BigInt3(1, 2, 3));
let (res) = ec_negate(p);
Expand Down Expand Up @@ -84,11 +83,24 @@ func test_fast_ec_add{range_check_ptr}() {
return ();
}

func test_ec_muller_inner{range_check_ptr}() {
let (pow2, res) = ec_mul_inner(
EcPoint(
BigInt3(65162296, 359657, 04862662171381), BigInt3(-5166641367474701, -63029418, 793)
),
123,
298,
);

return ();
}

func main{range_check_ptr}() {
test_ec_negate();
test_compute_doubling_slope();
test_compute_slope();
test_ec_double();
test_fast_ec_add();
test_ec_muller_inner();
return ();
}
1 change: 1 addition & 0 deletions pkg/hintrunner/zero/zerohint_ec.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ func newEcMulInnerHint(scalar hinter.ResOperander) hinter.Hinter {
resultFelt := new(fp.Element).SetBytes(resultUint256.Bytes())
resultMv := mem.MemoryValueFromFieldElement(resultFelt)
apAddr := vm.Context.AddressAp()

return vm.Memory.WriteToAddress(&apAddr, &resultMv)
},
}
Expand Down
13 changes: 6 additions & 7 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")
return fmt.Errorf("casting n into a uint64 failed")
}

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

0 comments on commit d67a992

Please sign in to comment.