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

Integration test for Is_Zero #494

Merged
merged 15 commits into from
Jun 28, 2024
2 changes: 1 addition & 1 deletion .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/.env
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions integration_tests/cairo_zero_hint_tests/is_zero.small.cairo
Original file line number Diff line number Diff line change
@@ -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
Sh0g0-1758 marked this conversation as resolved.
Show resolved Hide resolved

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 ();
}
2 changes: 1 addition & 1 deletion pkg/hintrunner/zero/hintcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)"

Expand Down
7 changes: 5 additions & 2 deletions pkg/hintrunner/zero/zerohint_ec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
Loading