Skip to content

Commit

Permalink
add hintcode + integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
TAdev0 committed Jul 11, 2024
1 parent 1285eeb commit 7be05bc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 96 deletions.
1 change: 1 addition & 0 deletions integration_tests/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Set to run some specific file tests (ex. fib.cairo,alloc.cairo)
INTEGRATION_TESTS_FILTERS=

95 changes: 0 additions & 95 deletions integration_tests/BenchMarks.txt
Original file line number Diff line number Diff line change
@@ -1,99 +1,4 @@
===========================================================================================================================
| File | PythonVM (ms) | GoVM (ms) |
===========================================================================================================================
| is_quad_residue.small.cairo | 815 | 122 |
---------------------------------------------------------------------------------------------------------------------------
| memset.cairo | 723 | 107 |
---------------------------------------------------------------------------------------------------------------------------
| pow.small.cairo | 810 | 109 |
---------------------------------------------------------------------------------------------------------------------------
| search_sorted_lower.small.cairo | 849 | 107 |
---------------------------------------------------------------------------------------------------------------------------
| bitwise_builtin_test.starknet_with_keccak.cairo| 1312 | 108 |
---------------------------------------------------------------------------------------------------------------------------
| dict.cairo | 840 | 106 |
---------------------------------------------------------------------------------------------------------------------------
| hintrefs.cairo | 1029 | 109 |
---------------------------------------------------------------------------------------------------------------------------
| uint256_sqrt.small.cairo | 929 | 109 |
---------------------------------------------------------------------------------------------------------------------------
| assert_250_bits.small.cairo | 843 | 109 |
---------------------------------------------------------------------------------------------------------------------------
| assert_not_equal.cairo | 923 | 182 |
---------------------------------------------------------------------------------------------------------------------------
| div_mod_n.small.cairo | 889 | 113 |
---------------------------------------------------------------------------------------------------------------------------
| ec.small.cairo | 4754 | 158 |
---------------------------------------------------------------------------------------------------------------------------
| import_secp256R1P.small.cairo | 705 | 103 |
---------------------------------------------------------------------------------------------------------------------------
| usort.small.cairo | 916 | 106 |
---------------------------------------------------------------------------------------------------------------------------
| verify_ecdsa_signature.small.cairo | 747 | 104 |
---------------------------------------------------------------------------------------------------------------------------
| cmp.small.cairo | 913 | 110 |
---------------------------------------------------------------------------------------------------------------------------
| signed_div_rem.small.cairo | 1000 | 115 |
---------------------------------------------------------------------------------------------------------------------------
| poseidon_test.starknet_with_keccak.cairo| 1318 | 108 |
---------------------------------------------------------------------------------------------------------------------------
| assert_not_zero.cairo | 1052 | 104 |
---------------------------------------------------------------------------------------------------------------------------
| blake.starknet_with_keccak.cairo | 47471 | 512 |
---------------------------------------------------------------------------------------------------------------------------
| set_add.small.cairo | 707 | 107 |
---------------------------------------------------------------------------------------------------------------------------
| split64.small.cairo | 804 | 106 |
---------------------------------------------------------------------------------------------------------------------------
| sqrt.small.cairo | 853 | 106 |
---------------------------------------------------------------------------------------------------------------------------
| verify_zero.small.cairo | 738 | 105 |
---------------------------------------------------------------------------------------------------------------------------
| simple.cairo | 600 | 103 |
---------------------------------------------------------------------------------------------------------------------------
| dict_squash.small.cairo | 1005 | 115 |
---------------------------------------------------------------------------------------------------------------------------
| memcpy.cairo | 627 | 103 |
---------------------------------------------------------------------------------------------------------------------------
| split_felt.small.cairo | 1041 | 106 |
---------------------------------------------------------------------------------------------------------------------------
| uint256_add.small.cairo | 722 | 105 |
---------------------------------------------------------------------------------------------------------------------------
| factorial.cairo | 1047 | 106 |
---------------------------------------------------------------------------------------------------------------------------
| pedersen_test.small.cairo | 639 | 103 |
---------------------------------------------------------------------------------------------------------------------------
| is_zero.small.cairo | 872 | 107 |
---------------------------------------------------------------------------------------------------------------------------
| random_ec.cairo | 763 | 108 |
---------------------------------------------------------------------------------------------------------------------------
| split_int.small.cairo | 793 | 106 |
---------------------------------------------------------------------------------------------------------------------------
| uint256_signedNN.small.cairo | 767 | 105 |
---------------------------------------------------------------------------------------------------------------------------
| uint256_unsigned_div_rem.small.cairo | 883 | 108 |
---------------------------------------------------------------------------------------------------------------------------
| unsafe_keccak.small.cairo | 740 | 104 |
---------------------------------------------------------------------------------------------------------------------------
| unsigned_div_rem.small.cairo | 826 | 106 |
---------------------------------------------------------------------------------------------------------------------------
| alloc.cairo | 737 | 620 |
---------------------------------------------------------------------------------------------------------------------------
| find_element.small.cairo | 813 | 105 |
---------------------------------------------------------------------------------------------------------------------------
| get_point_from_x.small.cairo | 1039 | 135 |
---------------------------------------------------------------------------------------------------------------------------
| is_positive.small.cairo | 784 | 105 |
---------------------------------------------------------------------------------------------------------------------------
| reduce_v1.small.cairo | 860 | 108 |
---------------------------------------------------------------------------------------------------------------------------
| uint256_mul_div_mod.small.cairo | 977 | 110 |
---------------------------------------------------------------------------------------------------------------------------
| unsafe_keccak_finalize.small.cairo | 662 | 104 |
---------------------------------------------------------------------------------------------------------------------------
| fib.cairo | 641 | 103 |
---------------------------------------------------------------------------------------------------------------------------
| ecdsa_test.starknet_with_keccak.cairo | 1506 | 108 |
---------------------------------------------------------------------------------------------------------------------------
| keccak_test.starknet_with_keccak.cairo| 1369 | 110 |
===========================================================================================================================
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
%builtins ec_op

from starkware.cairo.common.cairo_builtins import EcOpBuiltin
from starkware.cairo.common.ec_point import EcPoint
from starkware.cairo.common.ec import chained_ec_op
from starkware.cairo.common.alloc import alloc

func main{ec_op_ptr: EcOpBuiltin*}() {
let p = EcPoint(
0x6a4beaef5a93425b973179cdba0c9d42f30e01a5f1e2db73da0884b8d6756fc,
0x72565ec81bc09ff53fbfad99324a92aa5b39fb58267e395e8abe36290ebf24f,
);
let q1 = EcPoint(
0x654fd7e67a123dd13868093b3b7777f1ffef596c2e324f25ceaf9146698482c,
0x4fad269cbf860980e38768fe9cb6b0b9ab03ee3fe84cfde2eccce597c874fd8,
);
let q2 = EcPoint(
0x654fd7e67a123dd13868093b3b7777f1ffef596c2e324f25ceaf9146698482c,
0x4fad269cbf860980e38768fe9cb6b0b9ab03ee3fe84cfde2eccce597c874fd8,
);
let q3 = EcPoint(
0x654fd7e67a123dd13868093b3b7777f1ffef596c2e324f25ceaf9146698482c,
0x4fad269cbf860980e38768fe9cb6b0b9ab03ee3fe84cfde2eccce597c874fd8,
);
let q: EcPoint* = alloc();
assert q[0] = q1;
assert q[1] = q2;
assert q[2] = q3;
let m: felt* = alloc();
assert m[0] = 34;
assert m[1] = 34;
assert m[2] = 34;
let (r) = chained_ec_op(p, m, q, 3);
assert r.x = 3384892298291437283292800194657711696590239153368187334668717989522828417221;
assert r.y = 1522177177154723444905194991592642153940491339266976531102714535684279750063;
return ();
}
2 changes: 1 addition & 1 deletion pkg/hintrunner/zero/hintcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ ids.multiplicities = segments.gen_arg([len(positions_dict[k]) for k in output])`
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)"
recoverYCode string = "from starkware.crypto.signature.signature import ALPHA, BETA, FIELD_PRIME\nfrom starkware.python.math_utils import recover_y\nids.p.x = ids.x\n# This raises an exception if `x` is not on the curve.\nids.p.y = recover_y(ids.x, ALPHA, BETA, FIELD_PRIME)"
randomEcPointCode string = "from starkware.crypto.signature.signature import ALPHA, BETA, FIELD_PRIME\nfrom starkware.python.math_utils import random_ec_point\nfrom starkware.python.utils import to_bytes\n\n# Define a seed for random_ec_point that's dependent on all the input, so that:\n# (1) The added point s is deterministic.\n# (2) It's hard to choose inputs for which the builtin will fail.\nseed = b\"\".join(map(to_bytes, [ids.p.x, ids.p.y, ids.m, ids.q.x, ids.q.y]))\nids.s.x, ids.s.y = random_ec_point(FIELD_PRIME, ALPHA, BETA, seed)"
chainedEcOpRandomEcPointCode string = ""
chainedEcOpRandomEcPointCode string = "from starkware.crypto.signature.signature import ALPHA, BETA, FIELD_PRIME\nfrom starkware.python.math_utils import random_ec_point\nfrom starkware.python.utils import to_bytes\n\nn_elms = ids.len\nassert isinstance(n_elms, int) and n_elms >= 0, \\\n f'Invalid value for len. Got: {n_elms}.'\nif '__chained_ec_op_max_len' in globals():\n assert n_elms <= __chained_ec_op_max_len, \\\n f'chained_ec_op() can only be used with len<={__chained_ec_op_max_len}. ' \\\n f'Got: n_elms={n_elms}.'\n\n# Define a seed for random_ec_point that's dependent on all the input, so that:\n# (1) The added point s is deterministic.\n# (2) It's hard to choose inputs for which the builtin will fail.\nseed = b\"\".join(\n map(\n to_bytes,\n [\n ids.p.x,\n ids.p.y,\n *memory.get_range(ids.m, n_elms),\n *memory.get_range(ids.q.address_, 2 * n_elms),\n ],\n )\n)\nids.s.x, ids.s.y = random_ec_point(FIELD_PRIME, ALPHA, BETA, seed)"

// ------ Signature hints related code ------
verifyECDSASignatureCode string = "ecdsa_builtin.add_signature(ids.ecdsa_ptr.address_, (ids.signature_r, ids.signature_s))"
Expand Down

0 comments on commit 7be05bc

Please sign in to comment.