Skip to content

[DNM] Starkware Development #2076

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

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
106e5f8
Add starkware-development to CI (like another main) (#2025)
JulianGCalderon Mar 25, 2025
ce73503
Keep None memory cells for the prover input info (#2021)
Stavbe Mar 25, 2025
05fb44f
CI: Fix cache not found error (#2026)
JulianGCalderon Mar 25, 2025
bdd75dd
Remove dependancy in cairo pie when collectiog builtin segments info …
Stavbe Mar 26, 2025
7d7c460
Add Commit Signing section (#2019)
gabrielbosio Mar 26, 2025
92e3188
use btreemap instead of hashmap for deterministic iteration order. (#…
Stavbe Mar 27, 2025
10154c6
Stav/sync starkware dev (#2035)
yuvalsw Mar 27, 2025
2137db8
fill holes is builtins segments
Stavbe Apr 2, 2025
1d70783
fill holes is builtins segments (#2036)
Stavbe Apr 3, 2025
6dfd853
fill holes is builtins segments
Stavbe Apr 2, 2025
2b5ceaf
Rebase starkware-development on top of current main (#2052)
YairVaknin-starkware Apr 7, 2025
895be71
Added hints felt unpacking for blake (#2032)
yuvalsw Apr 7, 2025
d729b9f
add prover input info flag to vm-cli
Stavbe Apr 3, 2025
b9330cd
Stav/add prover input info flag (#2047)
Stavbe Apr 7, 2025
3179708
set disable trace padding for prover input info
Stavbe Apr 10, 2025
ba51705
Stav/disable trace padding for prover input info (#2066)
Stavbe Apr 14, 2025
28f4004
Add_perp_and_dex_w_bitwise_layouts (#2067)
YairVaknin-starkware Apr 14, 2025
9c44e1c
Fix_zero_offset_output_base_assumption (#2068)
YairVaknin-starkware Apr 14, 2025
58174f3
add flag to serialize prover input info into binary files
Stavbe Apr 27, 2025
33d75ca
use bincode for faster writing prover input info (#2074)
Stavbe Apr 29, 2025
dc1c49b
Use_btreemap_for_deterministic_order_of_pie_keys (#2085)
YairVaknin-starkware May 5, 2025
b1a91f9
[BREAKING] Compute_missing_builtin_cells_only_in_proof_mode (#2088)
YairVaknin-starkware May 7, 2025
a5b3c9d
move prover input info to a new seperate file (#2079)
Stavbe May 14, 2025
547dca1
add trace not enabled error
Stavbe Apr 29, 2025
da5dffd
add trace not enabled error (#2080)
Stavbe May 22, 2025
627c1ac
add test to filling holes (#2087)
Stavbe May 22, 2025
41486b5
memory comparision test only for non proof mode cases
Stavbe May 15, 2025
b818326
Stav/remove test compare to python vm (#2086)
Stavbe May 22, 2025
7269a8f
Sync with main (#2116)
gabrielbosio Jun 4, 2025
870fd60
Revert "Sync with main (#2116)" (#2117)
gabrielbosio Jun 4, 2025
bdf604f
Bump cairo-lang to 0.13.5 (#1959) (#2118)
gabrielbosio Jun 5, 2025
15de4b2
Enable_using_secure_run_in_proof_mode (#2113)
YairVaknin-starkware Jun 16, 2025
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
31 changes: 31 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,37 @@ jobs:
key: codecov-cache-test-no_std-mod_builtin-${{ github.sha }}
fail-on-cache-miss: true

- name: Fetch results for tests with stdlib (w/cairo-0-secp-hints; part. 1)
uses: actions/cache/restore@v3
with:
path: lcov-test#1-cairo-0-secp-hints.info
key: codecov-cache-test#1-cairo-0-secp-hints-${{ github.sha }}
fail-on-cache-miss: true
- name: Fetch results for tests with stdlib (w/cairo-0-secp-hints; part. 2)
uses: actions/cache/restore@v3
with:
path: lcov-test#2-cairo-0-secp-hints.info
key: codecov-cache-test#2-cairo-0-secp-hints-${{ github.sha }}
fail-on-cache-miss: true
- name: Fetch results for tests with stdlib (w/cairo-0-secp-hints; part. 3)
uses: actions/cache/restore@v3
with:
path: lcov-test#3-cairo-0-secp-hints.info
key: codecov-cache-test#3-cairo-0-secp-hints-${{ github.sha }}
fail-on-cache-miss: true
- name: Fetch results for tests with stdlib (w/cairo-0-secp-hints; part. 4)
uses: actions/cache/restore@v3
with:
path: lcov-test#4-cairo-0-secp-hints.info
key: codecov-cache-test#4-cairo-0-secp-hints-${{ github.sha }}
fail-on-cache-miss: true
- name: Fetch results for tests without stdlib (w/cairo-0-secp-hints)
uses: actions/cache/restore@v3
with:
path: lcov-no_std-cairo-0-secp-hints.info
key: codecov-cache-test-no_std-cairo-0-secp-hints-${{ github.sha }}
fail-on-cache-miss: true

- name: Upload coverage to codecov.io
uses: codecov/codecov-action@v3
with:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
## Cairo-VM Changelog

#### Upcoming Changes
* Refactor: Replaced HashMap with BTreeMap to guarantee deterministic ordering of the data [#2023] (https://github.com/lambdaclass/cairo-vm/pull/2023)

* fix: Updated the logic for collecting builtin segment data for prover input info, removing dependency on the existence of stop pointers. [#2022](https://github.com/lambdaclass/cairo-vm/pull/2022)

* fix: Keep None values in memory segments for the prover input info [#2021](https://github.com/lambdaclass/cairo-vm/pull/2021)

* fix: Always use a normal segment in first SegmentArena segment [#1845](https://github.com/lambdaclass/cairo-vm/pull/1845)

Expand Down Expand Up @@ -28,6 +33,8 @@

* feat: Add `ProverInfo` and extract the relevant information for it from the runner [#2001](https://github.com/lambdaclass/cairo-vm/pull/2001)

* feat: Support hints for new blake felt serialization library code [#1994](https://github.com/lambdaclass/cairo-vm/pull/1994)

#### [2.0.1] - 2025-03-17

* feat: Limited padding of builtin segments to >=16 [#1981](https://github.com/lambdaclass/cairo-vm/pull/1981)
Expand Down
32 changes: 30 additions & 2 deletions cairo-vm-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use cairo_vm::air_public_input::PublicInputError;
use cairo_vm::cairo_run::{self, EncodeTraceError};
use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor;
use cairo_vm::prover_input_info::ProverInputInfoError;
#[cfg(feature = "with_tracer")]
use cairo_vm::serde::deserialize_program::DebugInfo;
use cairo_vm::types::layout::CairoLayoutParams;
Expand Down Expand Up @@ -69,6 +70,10 @@
conflicts_with_all = ["proof_mode", "air_private_input", "air_public_input"]
)]
cairo_pie_output: Option<String>,
#[arg(long = "prover_input_info", requires_all = ["proof_mode"])]
prover_input_info: Option<String>,
#[arg(long = "prover_input_info_json", requires_all = ["proof_mode"])]
prover_input_info_json: Option<String>,
#[arg(long = "merge_extra_segments")]
merge_extra_segments: bool,
#[arg(long = "allow_missing_builtins")]
Expand Down Expand Up @@ -102,6 +107,8 @@
#[error(transparent)]
PublicInput(#[from] PublicInputError),
#[error(transparent)]
ProveInputInfo(#[from] ProverInputInfoError),
#[error(transparent)]
#[cfg(feature = "with_tracer")]
TraceData(#[from] TraceDataError),
}
Expand Down Expand Up @@ -168,7 +175,10 @@
fn run(args: impl Iterator<Item = String>) -> Result<(), Error> {
let args = Args::try_parse_from(args)?;

let trace_enabled = args.trace_file.is_some() || args.air_public_input.is_some();
let trace_enabled = args.trace_file.is_some()
|| args.air_public_input.is_some()
|| args.prover_input_info.is_some()
|| args.prover_input_info_json.is_some();

let cairo_layout_params = match args.cairo_layout_params_file {
Some(file) => Some(CairoLayoutParams::from_file(&file)?),
Expand All @@ -184,7 +194,8 @@
secure_run: args.secure_run,
allow_missing_builtins: args.allow_missing_builtins,
dynamic_layout_params: cairo_layout_params,
..Default::default()
disable_trace_padding: args.prover_input_info.is_some()
|| args.prover_input_info_json.is_some(),
};

let mut cairo_runner = match if args.run_from_cairo_pie {
Expand Down Expand Up @@ -235,6 +246,18 @@
memory_writer.flush()?;
}

if let Some(path) = args.prover_input_info {
let prover_input_info = cairo_runner.get_prover_input_info()?;
let bytes = prover_input_info.serialize()?;
std::fs::write(path, bytes)?;
}

if let Some(path) = args.prover_input_info_json {
let prover_input_info = cairo_runner.get_prover_input_info()?;
let json = prover_input_info.serialize_json()?;
std::fs::write(path, json)?;

Check warning on line 258 in cairo-vm-cli/src/main.rs

View check run for this annotation

Codecov / codecov/patch

cairo-vm-cli/src/main.rs#L256-L258

Added lines #L256 - L258 were not covered by tests
}

if let Some(file_path) = args.air_public_input {
let json = cairo_runner.get_air_public_input()?.serialize_json()?;
std::fs::write(file_path, json)?;
Expand Down Expand Up @@ -358,6 +381,7 @@
#[values(false, true)] air_public_input: bool,
#[values(false, true)] air_private_input: bool,
#[values(false, true)] cairo_pie_output: bool,
#[values(false, true)] prover_input_info: bool,
) {
let mut args = vec!["cairo-vm-cli".to_string()];
if let Some(layout) = layout {
Expand Down Expand Up @@ -388,11 +412,15 @@
if print_output {
args.extend_from_slice(&["--print_output".to_string()]);
}
if prover_input_info {
args.extend_from_slice(&["--prover_input_info".to_string(), "/dev/null".to_string()]);
}

args.push("../cairo_programs/proof_programs/fibonacci.json".to_string());
if air_public_input && !proof_mode
|| (air_private_input && (!proof_mode || !trace_file || !memory_file))
|| cairo_pie_output && proof_mode
|| prover_input_info && !proof_mode
{
assert_matches!(run(args.into_iter()), Err(_));
} else {
Expand Down
1 change: 1 addition & 0 deletions cairo1-run/cairo
Submodule cairo added at 879302
7 changes: 6 additions & 1 deletion cairo1-run/src/cairo_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,12 @@ pub fn cairo_run_program(
runner.run_for_steps(1, &mut hint_processor)?;
}

runner.end_run(false, false, &mut hint_processor)?;
runner.end_run(
false,
false,
&mut hint_processor,
cairo_run_config.proof_mode,
)?;

let result_inner_type_size =
result_inner_type_size(return_type_id, &sierra_program_registry, &type_sizes);
Expand Down
167 changes: 167 additions & 0 deletions cairo_programs/cairo-0-secp-hints-feature/negative_points.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
%builtins range_check

from starkware.cairo.common.secp256r1.ec import (
EcPoint,
)
from starkware.cairo.common.secp256r1.bigint import nondet_bigint3
from starkware.cairo.common.cairo_secp.bigint3 import BigInt3

func main{range_check_ptr: felt}() {
let point = EcPoint(
BigInt3(1, 2, 3),
BigInt3(-1, -2, -3),
);

let slope = compute_doubling_slope_prime(point);
assert slope = BigInt3(
15487438216801236710343013, 27596288489803578791625491, 8178446608657045587339469
);

let slope = compute_doubling_slope_secp256r1(point);
assert slope = BigInt3(
56511396263956479754791421, 38561311687768998103117219, 2015104701319196654781984
);

let x = BigInt3(-1,-2,-3);
let y = try_get_point_from_x_prime(x, 0);
assert y = BigInt3(
39197606747300743094893670, 38008389934708701866119639, 2071781356858789560884686
);

let x = BigInt3(-1,-2,-3);
let y = try_get_point_from_x_secp256r1(x, 0);
assert y = BigInt3(
56004882917990234964232380, 17943756516348761157632108, 3811440313376405071875160
);

let slope = BigInt3(-1,-2,-3);
let x = ec_double_x_prime(point, slope);
assert x = BigInt3(
648518346341351470, 77370588372549613637288996, 18662792551970020321619971
);

let slope = BigInt3(-1,-2,-3);
let x = ec_double_x_secp256r1(point, slope);
assert x = BigInt3(
21299552074028835321108137, 50187220174510023990904347, 2291813387120727975022296
);

return ();
}

func compute_doubling_slope_prime{range_check_ptr}(point: EcPoint) -> BigInt3 {
%{
from starkware.cairo.common.cairo_secp.secp256r1_utils import SECP256R1_ALPHA, SECP256R1_P
from starkware.cairo.common.cairo_secp.secp_utils import pack
from starkware.python.math_utils import ec_double_slope

# Compute the slope.
x = pack(ids.point.x, PRIME)
y = pack(ids.point.y, PRIME)
value = slope = ec_double_slope(point=(x, y), alpha=SECP256R1_ALPHA, p=SECP256R1_P)
%}
let (slope: BigInt3) = nondet_bigint3();
return slope;
}

func compute_doubling_slope_secp256r1{range_check_ptr}(point: EcPoint) -> BigInt3 {
%{
from starkware.cairo.common.cairo_secp.secp256r1_utils import SECP256R1_ALPHA, SECP256R1_P
from starkware.cairo.common.cairo_secp.secp_utils import pack
from starkware.python.math_utils import ec_double_slope

# Compute the slope.
x = pack(ids.point.x, SECP256R1_P)
y = pack(ids.point.y, SECP256R1_P)
value = slope = ec_double_slope(point=(x, y), alpha=SECP256R1_ALPHA, p=SECP256R1_P)
%}
let (slope: BigInt3) = nondet_bigint3();
return slope;
}

func try_get_point_from_x_prime{range_check_ptr}(x: BigInt3, v: felt) -> BigInt3 {
%{
from starkware.cairo.common.cairo_secp.secp_utils import SECP256R1, pack
from starkware.python.math_utils import y_squared_from_x

y_square_int = y_squared_from_x(
x=pack(ids.x, PRIME),
alpha=SECP256R1.alpha,
beta=SECP256R1.beta,
field_prime=SECP256R1.prime,
)

# Note that (y_square_int ** ((SECP256R1.prime + 1) / 4)) ** 2 =
# = y_square_int ** ((SECP256R1.prime + 1) / 2) =
# = y_square_int ** ((SECP256R1.prime - 1) / 2 + 1) =
# = y_square_int * y_square_int ** ((SECP256R1.prime - 1) / 2) = y_square_int * {+/-}1.
y = pow(y_square_int, (SECP256R1.prime + 1) // 4, SECP256R1.prime)

# We need to decide whether to take y or prime - y.
if ids.v % 2 == y % 2:
value = y
else:
value = (-y) % SECP256R1.prime
%}
let (y: BigInt3) = nondet_bigint3();
return y;
}

func try_get_point_from_x_secp256r1{range_check_ptr}(x: BigInt3, v: felt) -> BigInt3 {
%{
from starkware.cairo.common.cairo_secp.secp_utils import SECP256R1, pack
from starkware.python.math_utils import y_squared_from_x

y_square_int = y_squared_from_x(
x=pack(ids.x, SECP256R1.prime),
alpha=SECP256R1.alpha,
beta=SECP256R1.beta,
field_prime=SECP256R1.prime,
)

# Note that (y_square_int ** ((SECP256R1.prime + 1) / 4)) ** 2 =
# = y_square_int ** ((SECP256R1.prime + 1) / 2) =
# = y_square_int ** ((SECP256R1.prime - 1) / 2 + 1) =
# = y_square_int * y_square_int ** ((SECP256R1.prime - 1) / 2) = y_square_int * {+/-}1.
y = pow(y_square_int, (SECP256R1.prime + 1) // 4, SECP256R1.prime)

# We need to decide whether to take y or prime - y.
if ids.v % 2 == y % 2:
value = y
else:
value = (-y) % SECP256R1.prime
%}
let (y: BigInt3) = nondet_bigint3();
return y;
}


func ec_double_x_prime{range_check_ptr}(point: EcPoint, slope: BigInt3) -> BigInt3 {
%{
from starkware.cairo.common.cairo_secp.secp256r1_utils import SECP256R1_P
from starkware.cairo.common.cairo_secp.secp_utils import pack

slope = pack(ids.slope, PRIME)
x = pack(ids.point.x, PRIME)
y = pack(ids.point.y, PRIME)

value = new_x = (pow(slope, 2, SECP256R1_P) - 2 * x) % SECP256R1_P
%}
let (new_x: BigInt3) = nondet_bigint3();
return new_x;
}

func ec_double_x_secp256r1{range_check_ptr}(point: EcPoint, slope: BigInt3) -> BigInt3 {
%{
from starkware.cairo.common.cairo_secp.secp256r1_utils import SECP256R1_P
from starkware.cairo.common.cairo_secp.secp_utils import pack

slope = pack(ids.slope, SECP256R1_P)
x = pack(ids.point.x, SECP256R1_P)
y = pack(ids.point.y, SECP256R1_P)

value = new_x = (pow(slope, 2, SECP256R1_P) - 2 * x) % SECP256R1_P
%}
let (new_x: BigInt3) = nondet_bigint3();
return new_x;
}
12 changes: 12 additions & 0 deletions cairo_programs/poseidon_builtin_hole.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
%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.s2 = 2512222140811166287287541003826449032093371832913959128171347018667852712082;
return ();
}
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ bitarray==2.7.3
fastecdsa==2.3.2
sympy==1.11.1
typeguard==2.13.3
cairo-lang==0.13.3
cairo-lang==0.13.5
2 changes: 1 addition & 1 deletion vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ num-integer = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
hex = { workspace = true }
bincode = { workspace = true }
bincode = { workspace = true , features = ["alloc"]}
starknet-crypto = { workspace = true }
sha3 = { workspace = true }
indoc = { workspace = true }
Expand Down
7 changes: 3 additions & 4 deletions vm/src/cairo_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@
cairo_run_config.disable_trace_padding,
false,
hint_processor,
cairo_run_config.proof_mode,
)?;

cairo_runner.vm.verify_auto_deductions()?;
cairo_runner.read_return_values(allow_missing_builtins)?;
if cairo_run_config.proof_mode {
cairo_runner.finalize_segments()?;
Expand Down Expand Up @@ -208,9 +208,9 @@
cairo_run_config.disable_trace_padding,
false,
hint_processor,
cairo_run_config.proof_mode,
)?;

cairo_runner.vm.verify_auto_deductions()?;
cairo_runner.read_return_values(allow_missing_builtins)?;

if secure_run {
Expand Down Expand Up @@ -258,9 +258,8 @@

res.map_err(|err| VmException::from_vm_error(&cairo_runner, err))?;

cairo_runner.end_run(false, false, hint_processor)?;
cairo_runner.end_run(false, false, hint_processor, cairo_run_config.proof_mode)?;

Check warning on line 261 in vm/src/cairo_run.rs

View check run for this annotation

Codecov / codecov/patch

vm/src/cairo_run.rs#L261

Added line #L261 was not covered by tests

cairo_runner.vm.verify_auto_deductions()?;
cairo_runner.read_return_values(allow_missing_builtins)?;
if cairo_run_config.proof_mode {
cairo_runner.finalize_segments()?;
Expand Down
Loading
Loading