diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index f630180f..b788a923 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -18,7 +18,7 @@ jobs: python-version: '3.9' - name: Install cairo-lang - run: pip install cairo-lang==0.11 + run: pip install cairo-lang==0.13.1 - name: Build run: make build diff --git a/integration_tests/.env b/integration_tests/.env index 8ffc5395..b24a173e 100644 --- a/integration_tests/.env +++ b/integration_tests/.env @@ -1,2 +1,2 @@ # Set to run some specific file tests (ex. fib.cairo,alloc.cairo) -INTEGRATION_TESTS_FILTERS= +INTEGRATION_TESTS_FILTERS=is_zero.small.cairo diff --git a/integration_tests/cairo_zero_hint_tests/is_zero.small.cairo b/integration_tests/cairo_zero_hint_tests/is_zero.small.cairo new file mode 100644 index 00000000..c1d5e802 --- /dev/null +++ b/integration_tests/cairo_zero_hint_tests/is_zero.small.cairo @@ -0,0 +1,31 @@ +// Returns 1 if x == 0 (mod secp256k1_prime), and 0 otherwise. +// Serves as integration test for the following hints : +// isZeroNondetCode +// isZeroPackCode +// isZeroDivModCode + +%builtins range_check + +from starkware.cairo.common.cairo_secp.field import is_zero, SumBigInt3 + +func main{range_check_ptr}() -> () { + + // Test One + let a = SumBigInt3(0, 0, 0); + let (res: felt) = is_zero(a); + assert res = 1; + + // Test Two + let b = SumBigInt3(42, 0, 0); + let (res: felt) = is_zero(b); + assert res = 0; + + // Test Three + let c = SumBigInt3( + 77371252455336262886226991, 77371252455336267181195263, 19342813113834066795298815 + ); + let (res: felt) = is_zero(c); + assert res = 1; + + return (); +} diff --git a/pkg/hintrunner/zero/hintcode.go b/pkg/hintrunner/zero/hintcode.go index 3df68b47..45b54588 100644 --- a/pkg/hintrunner/zero/hintcode.go +++ b/pkg/hintrunner/zero/hintcode.go @@ -94,7 +94,7 @@ ids.multiplicities = segments.gen_arg([len(positions_dict[k]) for k in output])` ecDoubleAssignNewXV1Code string = "from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack\n\nslope = pack(ids.slope, PRIME)\nx = pack(ids.point.x, PRIME)\ny = pack(ids.point.y, PRIME)\n\nvalue = new_x = (pow(slope, 2, SECP_P) - 2 * x) % SECP_P" ecDoubleAssignNewYV1Code string = "value = new_y = (slope * (x - new_x) - y) % SECP_P" ecMulInnerCode string = "memory[ap] = (ids.scalar % PRIME) % 2" - isZeroNondetCode string = "x == 0" + isZeroNondetCode string = "memory[ap] = to_felt_or_relocatable(x == 0)" isZeroPackCode string = "from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack\n\nx = pack(ids.x, PRIME) % SECP_P" isZeroDivModCode string = "from starkware.cairo.common.cairo_secp.secp_utils import SECP_P\nfrom starkware.python.math_utils import div_mod\n\nvalue = x_inv = div_mod(1, x, SECP_P)" diff --git a/pkg/hintrunner/zero/zerohint_ec.go b/pkg/hintrunner/zero/zerohint_ec.go index 6d67362f..62cdfc16 100644 --- a/pkg/hintrunner/zero/zerohint_ec.go +++ b/pkg/hintrunner/zero/zerohint_ec.go @@ -736,9 +736,10 @@ func createEcMulInnerHinter(resolver hintReferenceResolver) (hinter.Hinter, erro // i.e, 1 if `x == 0`, 0 otherwise func newIsZeroNondetHint() hinter.Hinter { return &GenericZeroHinter{ - Name: "IsZeroConditional", + Name: "IsZeroNondet", Op: func(vm *VM.VirtualMachine, ctx *hinter.HintRunnerContext) error { - //> x == 0 + //> python hint in cairo file: "x == 0" + //> compiled file hint: "memory[ap] = to_felt_or_relocatable(x == 0)" x, err := ctx.ScopeManager.GetVariableValueAsBigInt("x") if err != nil { @@ -775,6 +776,7 @@ func newIsZeroPackHint(x hinter.ResOperander) hinter.Hinter { Name: "IsZeroPack", Op: func(vm *VM.VirtualMachine, ctx *hinter.HintRunnerContext) error { //> from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack + //> x = pack(ids.x, PRIME) % SECP_P xAddr, err := x.GetAddress(vm) @@ -829,6 +831,7 @@ func newIsZeroDivModHint() hinter.Hinter { Op: func(vm *VM.VirtualMachine, ctx *hinter.HintRunnerContext) error { //> from starkware.cairo.common.cairo_secp.secp_utils import SECP_P //> from starkware.python.math_utils import div_mod + //> value = x_inv = div_mod(1, x, SECP_P) secPBig, ok := secp_utils.GetSecPBig()