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

Add 0.11 changes #884

Merged
merged 40 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a2a45aa
Add poseidon builtin (#875)
fmoletta Mar 9, 2023
7fb6265
Use `starknet-crypto` for poseidon (#890)
xJonathanLEI Mar 10, 2023
3366594
ec_op changes 0.11 release (#876)
Jrigada Mar 10, 2023
fa673d6
[WIP] Update keccak-builtin (#873)
fmoletta Mar 10, 2023
110395c
Update layouts to cairo-lang 0.11 release (#874)
Jrigada Mar 10, 2023
637b733
Add new keccak hints + update import paths (#883)
fmoletta Mar 15, 2023
673afeb
Merge branch 'main' of github.com:lambdaclass/cairo-rs into 0.11
fmoletta Mar 15, 2023
4d96d82
Remove typeguard pin
fmoletta Mar 21, 2023
3d2dc35
Merge branch 'main' of github.com:lambdaclass/cairo-rs into 0.11
fmoletta Mar 21, 2023
094c941
Run cairo-format
fmoletta Mar 21, 2023
9e4f939
Fix program ruined by formatter
fmoletta Mar 21, 2023
c3def44
Fix wasm compatibility for newer files
fmoletta Mar 21, 2023
301b2b1
Fix wasm compatibility for newer files
fmoletta Mar 21, 2023
2e08c10
Merge branch 'main' into 0.11
fmoletta Mar 21, 2023
1c034ff
Fix wrong version
fmoletta Mar 21, 2023
76d23ec
Fix syntax
fmoletta Mar 21, 2023
192debf
Fix wasm compatibility
fmoletta Mar 21, 2023
a42d948
Tempfix for iai workflow
fmoletta Mar 21, 2023
5a4bc13
Fix workflow
fmoletta Mar 21, 2023
30e39b4
Use the same layout for memory trace proof mode comparison
fmoletta Mar 21, 2023
d180881
Merge branch 'main' into 0.11
fmoletta Mar 27, 2023
455a1e8
Add dynamic layout (#879)
fmoletta Mar 29, 2023
b8f9cf0
Merge remote-tracking branch 'origin/main' into 0.11
Oppen Mar 30, 2023
4993f9d
Fix workflows
Oppen Mar 30, 2023
3c08409
Merge branch 'main' into 0.11
fmoletta Mar 31, 2023
f2845f1
Update Cargo.lock
fmoletta Mar 31, 2023
8e3db85
Remove comment
fmoletta Mar 31, 2023
a9ad91e
[0.11] Add `SegmentArenaBuiltinRunner` (#913)
fmoletta Apr 3, 2023
0921e78
Add suggested changes
fmoletta Apr 3, 2023
47cb406
Merge branch '0.11' of github.com:lambdaclass/cairo-rs into 0.11
fmoletta Apr 3, 2023
91970f2
Fix overriden run_benchmarks script
fmoletta Apr 3, 2023
554f72a
Add `program_segment_size` argument to `verify_secure_runner` & `run_…
fmoletta Apr 3, 2023
b722cbe
Fix typo
fmoletta Apr 3, 2023
ac3e9b4
Add misc tests
fmoletta Apr 3, 2023
70b95ed
Add misc tests
fmoletta Apr 3, 2023
a41c833
Add misc test
fmoletta Apr 3, 2023
2875509
Add misc test
fmoletta Apr 3, 2023
1573457
Add misc test
fmoletta Apr 3, 2023
851dad7
Expand misc test
fmoletta Apr 3, 2023
d7c13c4
Add wasm attr + misc test
fmoletta Apr 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
335 changes: 220 additions & 115 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ $(TEST_PROOF_DIR)/%.json: $(TEST_PROOF_DIR)/%.cairo
cairo-compile --cairo_path="$(TEST_PROOF_DIR):$(PROOF_BENCH_DIR)" $< --output $@ --proof_mode

$(TEST_PROOF_DIR)/%.rs.trace $(TEST_PROOF_DIR)/%.rs.memory: $(TEST_PROOF_DIR)/%.json $(RELBIN)
cargo llvm-cov run -p cairo-vm-cli --release --no-report -- --layout all --proof_mode $< --trace_file $@ --memory_file $(@D)/$(*F).rs.memory
cargo llvm-cov run -p cairo-vm-cli --release --no-report -- --layout starknet_with_keccak --proof_mode $< --trace_file $@ --memory_file $(@D)/$(*F).rs.memory

$(TEST_PROOF_DIR)/%.trace $(TEST_PROOF_DIR)/%.memory: $(TEST_PROOF_DIR)/%.json
cairo-run --layout all --proof_mode --program $< --trace_file $@ --memory_file $(@D)/$(*F).memory
cairo-run --layout starknet_with_keccak --proof_mode --program $< --trace_file $@ --memory_file $(@D)/$(*F).memory

$(PROOF_BENCH_DIR)/%.json: $(PROOF_BENCH_DIR)/%.cairo
cairo-compile --cairo_path="$(TEST_PROOF_DIR):$(PROOF_BENCH_DIR)" $< --output $@ --proof_mode
Expand Down Expand Up @@ -68,10 +68,10 @@ $(TEST_DIR)/%.json: $(TEST_DIR)/%.cairo
cairo-compile --cairo_path="$(TEST_DIR):$(BENCH_DIR)" $< --output $@

$(TEST_DIR)/%.rs.trace $(TEST_DIR)/%.rs.memory: $(TEST_DIR)/%.json $(RELBIN)
cargo llvm-cov run -p cairo-vm-cli --release --no-report -- --layout all $< --trace_file $@ --memory_file $(@D)/$(*F).rs.memory
cargo llvm-cov run -p cairo-vm-cli --release --no-report -- --layout all_cairo $< --trace_file $@ --memory_file $(@D)/$(*F).rs.memory

$(TEST_DIR)/%.trace $(TEST_DIR)/%.memory: $(TEST_DIR)/%.json
cairo-run --layout all --program $< --trace_file $@ --memory_file $(@D)/$(*F).memory
cairo-run --layout starknet_with_keccak --program $< --trace_file $@ --memory_file $(@D)/$(*F).memory

$(BENCH_DIR)/%.json: $(BENCH_DIR)/%.cairo
cairo-compile --cairo_path="$(TEST_DIR):$(BENCH_DIR)" $< --output $@
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ cairo-compile cairo_programs/abs_value_array.cairo --output cairo_programs/abs_v
To run a compiled .json program through the VM, call the executable giving it the path and name of the file to be executed. For example:

```bash
target/release/cairo-rs-run cairo_programs/abs_value_array_compiled.json --layout all
target/release/cairo-rs-run cairo_programs/abs_value_array_compiled.json --layout all_cairo
```
The flag `--layout` determines which builtins can be used. More info about layouts [here](https://www.cairo-lang.org/docs/how_cairo_works/builtins.html#layouts).

Expand All @@ -109,7 +109,7 @@ cargo build --release

cairo-compile cairo_programs/abs_value_array.cairo --output cairo_programs/abs_value_array_compiled.json

target/release/cairo-rs-run cairo_programs/abs_value_array_compiled.json --layout all
target/release/cairo-rs-run cairo_programs/abs_value_array_compiled.json --layout all_cairo
```
### Using hints

Expand All @@ -133,7 +133,7 @@ let program =
```rust
let mut vm = VirtualMachine::new(false);

let mut cairo_runner = CairoRunner::new(&program, "all", false);
let mut cairo_runner = CairoRunner::new(&program, "all_cairo", false);

let mut hint_processor = BuiltinHintProcessor::new_empty();

Expand Down
2 changes: 1 addition & 1 deletion bench/criterion_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const BENCH_PATH: &str = "cairo_programs/benchmarks/";
pub fn criterion_benchmarks(c: &mut Criterion) {
let mut hint_executor = BuiltinHintProcessor::new_empty();
let cairo_run_config = cairo_vm::cairo_run::CairoRunConfig {
layout: "all",
layout: "all_cairo",
..cairo_vm::cairo_run::CairoRunConfig::default()
};
for benchmark_name in build_bench_strings() {
Expand Down
2 changes: 1 addition & 1 deletion bench/iai_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ macro_rules! iai_bench_expand_prog {
fn $val() {
let cairo_run_config = cairo_vm::cairo_run::CairoRunConfig {
trace_enabled: true,
layout: "all",
layout: "all_cairo",
//FIXME: we need to distinguish the proof compiled programs
//proof_mode: true,
secure_run: Some(true),
Expand Down
18 changes: 14 additions & 4 deletions cairo-vm-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ struct Args {

fn validate_layout(value: &str) -> Result<(), String> {
match value {
"plain" | "small" | "dex" | "bitwise" | "perpetual_with_bitwise" | "all" => Ok(()),
"plain"
| "small"
| "dex"
| "starknet"
| "starknet_with_keccak"
| "recursive_large_output"
| "all_cairo"
| "all_solidity"
| "dynamic" => Ok(()),
_ => Err(format!("{value} is not a valid layout")),
}
}
Expand Down Expand Up @@ -156,9 +164,11 @@ mod tests {
"plain",
"small",
"dex",
"bitwise",
"perpetual_with_bitwise",
"all",
"starknet",
"starknet_with_keccak",
"recursive_large_output",
"all_cairo",
"all_solidity",
];

for layout in valid_layouts {
Expand Down
1 change: 0 additions & 1 deletion cairo_programs/_keccak.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,3 @@ func main{output_ptr: felt*, range_check_ptr, bitwise_ptr: BitwiseBuiltin*}() {

return ();
}

4 changes: 2 additions & 2 deletions cairo_programs/cairo_finalize_keccak.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%builtins range_check bitwise

from starkware.cairo.common.cairo_keccak.keccak import keccak, finalize_keccak
from starkware.cairo.common.cairo_keccak.keccak import cairo_keccak, finalize_keccak
from starkware.cairo.common.uint256 import Uint256
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin
from starkware.cairo.common.alloc import alloc
Expand All @@ -18,7 +18,7 @@ func main{range_check_ptr: felt, bitwise_ptr: BitwiseBuiltin*}() {

let n_bytes = 16;

let (res: Uint256) = keccak{keccak_ptr=keccak_ptr}(inputs=inputs, n_bytes=n_bytes);
let (res: Uint256) = cairo_keccak{keccak_ptr=keccak_ptr}(inputs=inputs, n_bytes=n_bytes);

assert res.low = 293431514620200399776069983710520819074;
assert res.high = 317109767021952548743448767588473366791;
Expand Down
11 changes: 5 additions & 6 deletions cairo_programs/chained_ec_op.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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,
Expand All @@ -14,20 +13,20 @@ func main{ec_op_ptr: EcOpBuiltin*}() {
let q1 = EcPoint(
0x654fd7e67a123dd13868093b3b7777f1ffef596c2e324f25ceaf9146698482c,
0x4fad269cbf860980e38768fe9cb6b0b9ab03ee3fe84cfde2eccce597c874fd8,
);
);
let q2 = EcPoint(
0x654fd7e67a123dd13868093b3b7777f1ffef596c2e324f25ceaf9146698482c,
0x4fad269cbf860980e38768fe9cb6b0b9ab03ee3fe84cfde2eccce597c874fd8,
);
);
let q3 = EcPoint(
0x654fd7e67a123dd13868093b3b7777f1ffef596c2e324f25ceaf9146698482c,
0x4fad269cbf860980e38768fe9cb6b0b9ab03ee3fe84cfde2eccce597c874fd8,
);
let q : EcPoint* = alloc();
);
let q: EcPoint* = alloc();
assert q[0] = q1;
assert q[1] = q2;
assert q[2] = q3;
let m : felt* = alloc();
let m: felt* = alloc();
assert m[0] = 34;
assert m[1] = 34;
assert m[2] = 34;
Expand Down
9 changes: 7 additions & 2 deletions cairo_programs/common_signature.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ from starkware.cairo.common.cairo_builtins import SignatureBuiltin
from starkware.cairo.common.signature import verify_ecdsa_signature

func main{ecdsa_ptr: SignatureBuiltin*}() {
verify_ecdsa_signature(2718, 1735102664668487605176656616876767369909409133946409161569774794110049207117, 3086480810278599376317923499561306189851900463386393948998357832163236918254, 598673427589502599949712887611119751108407514580626464031881322743364689811);
return();
verify_ecdsa_signature(
2718,
1735102664668487605176656616876767369909409133946409161569774794110049207117,
3086480810278599376317923499561306189851900463386393948998357832163236918254,
598673427589502599949712887611119751108407514580626464031881322743364689811,
);
return ();
}
2 changes: 1 addition & 1 deletion cairo_programs/dict.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func main() {
let (local val6: felt) = dict_read{dict_ptr=my_dict}(key=11);
assert val6 = 35;
dict_write{dict_ptr=my_dict}(key=20, new_value=-5);
let (local val6 : felt) = dict_read{dict_ptr=my_dict}(key=20);
let (local val6: felt) = dict_read{dict_ptr=my_dict}(key=20);
assert val6 = -5;
return ();
}
9 changes: 3 additions & 6 deletions cairo_programs/dict_squash.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ func main{range_check_ptr}() -> () {
let (squashed_dict_start, squashed_dict_end) = dict_squash{range_check_ptr=range_check_ptr}(
dict_start, dict_end
);
assert squashed_dict_end[0] = DictAccess(
key=0, prev_value=1, new_value=4);
assert squashed_dict_end[1] = DictAccess(
key=1, prev_value=10, new_value=25);
assert squashed_dict_end[2] = DictAccess(
key=2, prev_value=-2, new_value=-16);
assert squashed_dict_end[0] = DictAccess(key=0, prev_value=1, new_value=4);
assert squashed_dict_end[1] = DictAccess(key=1, prev_value=10, new_value=25);
assert squashed_dict_end[2] = DictAccess(key=2, prev_value=-2, new_value=-16);
return ();
}
2 changes: 1 addition & 1 deletion cairo_programs/dict_update.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func main() {
let (local val3: felt) = dict_read{dict_ptr=my_dict}(key=10);
assert val3 = 22;
dict_update{dict_ptr=my_dict}(key=10, prev_value=22, new_value=-8);
let (local val4 : felt) = dict_read{dict_ptr=my_dict}(key=10);
let (local val4: felt) = dict_read{dict_ptr=my_dict}(key=10);
assert val4 = -8;
return ();
}
3 changes: 1 addition & 2 deletions cairo_programs/ec_op.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ from starkware.cairo.common.cairo_builtins import EcOpBuiltin
from starkware.cairo.common.ec_point import EcPoint
from starkware.cairo.common.ec import ec_op


func main{ec_op_ptr: EcOpBuiltin*}() {
let p = EcPoint(
0x6a4beaef5a93425b973179cdba0c9d42f30e01a5f1e2db73da0884b8d6756fc,
Expand All @@ -14,7 +13,7 @@ func main{ec_op_ptr: EcOpBuiltin*}() {
let q = EcPoint(
0x654fd7e67a123dd13868093b3b7777f1ffef596c2e324f25ceaf9146698482c,
0x4fad269cbf860980e38768fe9cb6b0b9ab03ee3fe84cfde2eccce597c874fd8,
);
);
let (r) = ec_op(p, m, q);
assert r.x = 108925483682366235368969256555281508851459278989259552980345066351008608800;
assert r.y = 1592365885972480102953613056006596671718206128324372995731808913669237079419;
Expand Down
1 change: 0 additions & 1 deletion cairo_programs/example_program.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func evaluate_fib() {
return ();
}


func main{range_check_ptr: felt}() {
let x = 64;
tempvar y = 64 * 64;
Expand Down
2 changes: 1 addition & 1 deletion cairo_programs/keccak_add_uint256.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%builtins output range_check bitwise

from starkware.cairo.common.cairo_keccak.keccak import keccak_add_uint256
from starkware.cairo.common.keccak_utils.keccak_utils import keccak_add_uint256
from starkware.cairo.common.uint256 import Uint256
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin
from starkware.cairo.common.alloc import alloc
Expand Down
18 changes: 18 additions & 0 deletions cairo_programs/keccak_builtin.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
%builtins keccak
from starkware.cairo.common.cairo_builtins import KeccakBuiltin
from starkware.cairo.common.keccak_state import KeccakBuiltinState

func main{keccak_ptr: KeccakBuiltin*}() {
assert keccak_ptr[0].input = KeccakBuiltinState(1, 2, 3, 4, 5, 6, 7, 8);
let result = keccak_ptr[0].output;
let keccak_ptr = keccak_ptr + KeccakBuiltin.SIZE;
assert result.s0 = 528644516554364142278482415480021626364691973678134577961206;
assert result.s1 = 768681319646568210457759892191562701823009052229295869963057;
assert result.s2 = 1439835513376369408063324968379272676079109225238241190228026;
assert result.s3 = 1150396629165612276474514703759718478742374517669870754478270;
assert result.s4 = 1515147102575186161827863034255579930572231617017100845406254;
assert result.s5 = 1412568161597072838250338588041800080889949791225997426843744;
assert result.s6 = 982235455376248641031519404605670648838699214888770304613539;
assert result.s7 = 1339947803093378278438908448344904300127577306141693325151040;
return ();
}
5 changes: 3 additions & 2 deletions cairo_programs/keccak_integration_tests.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
%builtins range_check bitwise

from starkware.cairo.common.keccak import unsafe_keccak, unsafe_keccak_finalize, KeccakState
from starkware.cairo.common.cairo_keccak.keccak import keccak_add_uint256, keccak, finalize_keccak
from starkware.cairo.common.cairo_keccak.keccak import cairo_keccak, finalize_keccak
from starkware.cairo.common.keccak_utils.keccak_utils import keccak_add_uint256
from starkware.cairo.common.alloc import alloc
from starkware.cairo.common.uint256 import Uint256
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin
Expand Down Expand Up @@ -56,7 +57,7 @@ func test_integration{range_check_ptr: felt, bitwise_ptr: BitwiseBuiltin*}(iter:
let (keccak_ptr: felt*) = alloc();
let keccak_ptr_start = keccak_ptr;

let res_2: Uint256 = keccak{keccak_ptr=keccak_ptr}(data_3, 16);
let res_2: Uint256 = cairo_keccak{keccak_ptr=keccak_ptr}(data_3, 16);

finalize_keccak(keccak_ptr_start=keccak_ptr_start, keccak_ptr_end=keccak_ptr);

Expand Down
19 changes: 19 additions & 0 deletions cairo_programs/keccak_uint256.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%builtins range_check bitwise keccak
from starkware.cairo.common.cairo_builtins import KeccakBuiltin, BitwiseBuiltin
from starkware.cairo.common.builtin_keccak.keccak import keccak_uint256s
from starkware.cairo.common.alloc import alloc
from starkware.cairo.common.uint256 import Uint256

func main{range_check_ptr, bitwise_ptr: BitwiseBuiltin*, keccak_ptr: KeccakBuiltin*}() {
let elements: Uint256* = alloc();
assert elements[0] = Uint256(713458135386519, 18359173571);
assert elements[1] = Uint256(1536741637546373185, 84357893467438914);
assert elements[2] = Uint256(2842949328439284983294, 39248298942938492384);
assert elements[3] = Uint256(27518568234293478923754395731931, 981587843715983274);
assert elements[4] = Uint256(326848123647324823482, 93453458349589345);
let (res) = keccak_uint256s(5, elements);
assert res.high = 23012215180764429403047187376747988760;
assert res.low = 13431206634823648732212765105043225161;

return ();
}
20 changes: 12 additions & 8 deletions cairo_programs/packed_sha256.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ const ALL_ONES = 2 ** 251 - 1;
// Pack the different instances with offsets of 35 bits. This is the maximal possible offset for
// 7 32-bit words and it allows space for carry bits in integer addition operations (up to
// 8 summands).
const SHIFTS = 1 + 2 ** 35 + 2 ** (35 * 2) + 2 ** (35 * 3) + 2 ** (35 * 4) + 2 ** (35 * 5) +
2 ** (35 * 6);
const SHIFTS = 1 + 2 ** 35 + 2 ** (35 * 2) + 2 ** (35 * 3) + 2 ** (35 * 4) + 2 ** (35 * 5) + 2 ** (
35 * 6
);

// Given an array of size 16, extends it to the message schedule array (of size 64) by writing
// 48 more values.
Expand Down Expand Up @@ -426,8 +427,9 @@ func _finalize_sha256_inner{range_check_ptr, bitwise_ptr: BitwiseBuiltin*}(
tempvar x6 = sha256_ptr[6 * SHA256_INSTANCE_SIZE];
assert [range_check_ptr + 12] = x6;
assert [range_check_ptr + 13] = MAX_VALUE - x6;
assert message[0] = x0 + 2 ** 35 * x1 + 2 ** (35 * 2) * x2 + 2 ** (35 * 3) * x3 +
2 ** (35 * 4) * x4 + 2 ** (35 * 5) * x5 + 2 ** (35 * 6) * x6;
assert message[0] = x0 + 2 ** 35 * x1 + 2 ** (35 * 2) * x2 + 2 ** (35 * 3) * x3 + 2 ** (
35 * 4
) * x4 + 2 ** (35 * 5) * x5 + 2 ** (35 * 6) * x6;

tempvar message = message + 1;
tempvar sha256_ptr = sha256_ptr + 1;
Expand Down Expand Up @@ -464,8 +466,9 @@ func _finalize_sha256_inner{range_check_ptr, bitwise_ptr: BitwiseBuiltin*}(
tempvar x6 = sha256_ptr[6 * SHA256_INSTANCE_SIZE];
assert [range_check_ptr + 12] = x6;
assert [range_check_ptr + 13] = MAX_VALUE - x6;
assert input_state[0] = x0 + 2 ** 35 * x1 + 2 ** (35 * 2) * x2 + 2 ** (35 * 3) * x3 +
2 ** (35 * 4) * x4 + 2 ** (35 * 5) * x5 + 2 ** (35 * 6) * x6;
assert input_state[0] = x0 + 2 ** 35 * x1 + 2 ** (35 * 2) * x2 + 2 ** (35 * 3) * x3 + 2 ** (
35 * 4
) * x4 + 2 ** (35 * 5) * x5 + 2 ** (35 * 6) * x6;

tempvar input_state = input_state + 1;
tempvar sha256_ptr = sha256_ptr + 1;
Expand Down Expand Up @@ -510,8 +513,9 @@ func _finalize_sha256_inner{range_check_ptr, bitwise_ptr: BitwiseBuiltin*}(
tempvar x6 = sha256_ptr[6 * SHA256_INSTANCE_SIZE];
assert [range_check_ptr + 12] = x6;
assert [range_check_ptr + 13] = MAX_VALUE - x6;
assert outputs[0] = x0 + 2 ** 35 * x1 + 2 ** (35 * 2) * x2 + 2 ** (35 * 3) * x3 +
2 ** (35 * 4) * x4 + 2 ** (35 * 5) * x5 + 2 ** (35 * 6) * x6;
assert outputs[0] = x0 + 2 ** 35 * x1 + 2 ** (35 * 2) * x2 + 2 ** (35 * 3) * x3 + 2 ** (
35 * 4
) * x4 + 2 ** (35 * 5) * x5 + 2 ** (35 * 6) * x6;

tempvar outputs = outputs + 1;
tempvar sha256_ptr = sha256_ptr + 1;
Expand Down
13 changes: 13 additions & 0 deletions cairo_programs/poseidon_builtin.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
%builtins poseidon
from starkware.cairo.common.cairo_builtins import PoseidonBuiltin
from starkware.cairo.common.poseidon_state import PoseidonBuiltinState

func main{poseidon_ptr: PoseidonBuiltin*}() {
assert poseidon_ptr[0].input = PoseidonBuiltinState(1, 2, 3);
let result = poseidon_ptr[0].output;
let poseidon_ptr = poseidon_ptr + PoseidonBuiltin.SIZE;
assert result.s0 = 442682200349489646213731521593476982257703159825582578145778919623645026501;
assert result.s1 = 2233832504250924383748553933071188903279928981104663696710686541536735838182;
assert result.s2 = 2512222140811166287287541003826449032093371832913959128171347018667852712082;
return ();
}
30 changes: 30 additions & 0 deletions cairo_programs/poseidon_hash.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
%builtins poseidon
from starkware.cairo.common.cairo_builtins import PoseidonBuiltin
from starkware.cairo.common.poseidon_state import PoseidonBuiltinState
from starkware.cairo.common.builtin_poseidon.poseidon import (
poseidon_hash,
poseidon_hash_single,
poseidon_hash_many,
)
from starkware.cairo.common.alloc import alloc

func main{poseidon_ptr: PoseidonBuiltin*}() {
// Hash one
let (x) = poseidon_hash_single(
218676008889449692916464780911713710628115973574242889792891157041292792362
);
assert x = 2835120893146788752888137145656423078969524407843035783270702964188823073934;
// Hash two
let (y) = poseidon_hash(1253795, 18540013156130945068);
assert y = 37282360750367388068593128053386029947772104009544220786084510532118246655;
// Hash five
let felts: felt* = alloc();
assert felts[0] = 84175983715088675913672849362079546;
assert felts[1] = 9384720329467203286234076408512594689579283578028960384690;
assert felts[2] = 291883989128409324823849293040390493094093;
assert felts[3] = 5849589438543859348593485948598349584395839402940940290490324;
assert felts[4] = 1836254780028456372728992049476335424263474849;
let (z) = poseidon_hash_many(5, felts);
assert z = 47102513329160951064697157194713013753695317629154835326726810042406974264;
return ();
}
1 change: 0 additions & 1 deletion cairo_programs/recover_y.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ from starkware.cairo.common.cairo_builtins import EcOpBuiltin
from starkware.cairo.common.ec_point import EcPoint
from starkware.cairo.common.ec import recover_y


func main{ec_op_ptr: EcOpBuiltin*}() {
let x = 0x6a4beaef5a93425b973179cdba0c9d42f30e01a5f1e2db73da0884b8d6756fc;
let r: EcPoint = recover_y(x);
Expand Down
Loading