Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
43 changes: 23 additions & 20 deletions stwo_cairo_prover/crates/adapter/src/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ pub struct CasmStatesByOpcode {
pub assert_eq_opcode: Vec<CasmState>,
pub assert_eq_opcode_double_deref: Vec<CasmState>,
pub assert_eq_opcode_imm: Vec<CasmState>,
pub call_opcode: Vec<CasmState>,
pub call_opcode_abs: Vec<CasmState>,
pub call_opcode_rel_imm: Vec<CasmState>,
pub jnz_opcode: Vec<CasmState>,
pub jnz_opcode_non_taken: Vec<CasmState>,
pub jnz_opcode_taken: Vec<CasmState>,
pub jump_opcode_rel_imm: Vec<CasmState>,
pub jump_opcode_rel: Vec<CasmState>,
pub jump_opcode_double_deref: Vec<CasmState>,
pub jump_opcode: Vec<CasmState>,
pub jump_opcode_abs: Vec<CasmState>,
pub mul_opcode_small: Vec<CasmState>,
pub mul_opcode: Vec<CasmState>,
pub ret_opcode: Vec<CasmState>,
Expand Down Expand Up @@ -172,7 +172,7 @@ impl CasmStatesByOpcode {
&& pc_update_jump
&& offset1 == -1
);
self.jump_opcode.push(state);
self.jump_opcode_abs.push(state);
}
}

Expand Down Expand Up @@ -211,7 +211,7 @@ impl CasmStatesByOpcode {
} else {
// call abs [ap/fp + offset2].
assert!((op_1_base_ap ^ op_1_base_fp) && !op_1_imm && pc_update_jump);
self.call_opcode.push(state);
self.call_opcode_abs.push(state);
}
}

Expand Down Expand Up @@ -244,7 +244,7 @@ impl CasmStatesByOpcode {
if taken {
self.jnz_opcode_taken.push(state);
} else {
self.jnz_opcode.push(state);
self.jnz_opcode_non_taken.push(state);
}
}

Expand Down Expand Up @@ -490,14 +490,14 @@ impl CasmStatesByOpcode {
assert_eq_opcode,
assert_eq_opcode_double_deref,
assert_eq_opcode_imm,
call_opcode,
call_opcode_abs,
call_opcode_rel_imm,
jnz_opcode,
jnz_opcode_non_taken,
jnz_opcode_taken,
jump_opcode_rel_imm,
jump_opcode_rel,
jump_opcode_double_deref,
jump_opcode,
jump_opcode_abs,
mul_opcode_small,
mul_opcode,
ret_opcode,
Expand All @@ -513,15 +513,15 @@ impl CasmStatesByOpcode {
self.assert_eq_opcode_double_deref
.extend(assert_eq_opcode_double_deref);
self.assert_eq_opcode_imm.extend(assert_eq_opcode_imm);
self.call_opcode.extend(call_opcode);
self.call_opcode_abs.extend(call_opcode_abs);
self.call_opcode_rel_imm.extend(call_opcode_rel_imm);
self.jnz_opcode.extend(jnz_opcode);
self.jnz_opcode_non_taken.extend(jnz_opcode_non_taken);
self.jnz_opcode_taken.extend(jnz_opcode_taken);
self.jump_opcode_rel_imm.extend(jump_opcode_rel_imm);
self.jump_opcode_rel.extend(jump_opcode_rel);
self.jump_opcode_double_deref
.extend(jump_opcode_double_deref);
self.jump_opcode.extend(jump_opcode);
self.jump_opcode_abs.extend(jump_opcode_abs);
self.mul_opcode_small.extend(mul_opcode_small);
self.mul_opcode.extend(mul_opcode);
self.ret_opcode.extend(ret_opcode);
Expand All @@ -544,12 +544,15 @@ impl CasmStatesByOpcode {
"assert_eq_opcode_imm".to_string(),
self.assert_eq_opcode_imm.len(),
),
("call_opcode".to_string(), self.call_opcode.len()),
("call_opcode_abs".to_string(), self.call_opcode_abs.len()),
(
"call_opcode_rel_imm".to_string(),
self.call_opcode_rel_imm.len(),
),
("jnz_opcode".to_string(), self.jnz_opcode.len()),
(
"jnz_opcode_non_taken".to_string(),
self.jnz_opcode_non_taken.len(),
),
("jnz_opcode_taken".to_string(), self.jnz_opcode_taken.len()),
(
"jump_opcode_rel_imm".to_string(),
Expand All @@ -560,7 +563,7 @@ impl CasmStatesByOpcode {
"jump_opcode_double_deref".to_string(),
self.jump_opcode_double_deref.len(),
),
("jump_opcode".to_string(), self.jump_opcode.len()),
("jump_opcode_abs".to_string(), self.jump_opcode_abs.len()),
("mul_opcode_small".to_string(), self.mul_opcode_small.len()),
("mul_opcode".to_string(), self.mul_opcode.len()),
("ret_opcode".to_string(), self.ret_opcode.len()),
Expand Down Expand Up @@ -904,7 +907,7 @@ mod mappings_tests {

let input = input_from_plain_casm(instructions);
let casm_states_by_opcode = input.state_transitions.casm_states_by_opcode;
assert_eq!(casm_states_by_opcode.jump_opcode.len(), 1);
assert_eq!(casm_states_by_opcode.jump_opcode_abs.len(), 1);
assert_eq!(casm_states_by_opcode.call_opcode_rel_imm.len(), 1);
assert_eq!(casm_states_by_opcode.add_opcode_small.len(), 1);
}
Expand Down Expand Up @@ -968,7 +971,7 @@ mod mappings_tests {

let input = input_from_plain_casm(instructions);
let casm_states_by_opcode = input.state_transitions.casm_states_by_opcode;
assert_eq!(casm_states_by_opcode.call_opcode.len(), 2);
assert_eq!(casm_states_by_opcode.call_opcode_abs.len(), 2);
assert_eq!(casm_states_by_opcode.call_opcode_rel_imm.len(), 1);
}

Expand All @@ -983,7 +986,7 @@ mod mappings_tests {

let input = input_from_plain_casm(instructions);
let casm_states_by_opcode = input.state_transitions.casm_states_by_opcode;
assert_eq!(casm_states_by_opcode.call_opcode.len(), 2);
assert_eq!(casm_states_by_opcode.call_opcode_abs.len(), 2);
}

#[test]
Expand All @@ -997,7 +1000,7 @@ mod mappings_tests {

let input = input_from_plain_casm(instructions);
let casm_states_by_opcode = input.state_transitions.casm_states_by_opcode;
assert_eq!(casm_states_by_opcode.jnz_opcode.len(), 1);
assert_eq!(casm_states_by_opcode.jnz_opcode_non_taken.len(), 1);
}

#[test]
Expand All @@ -1012,7 +1015,7 @@ mod mappings_tests {

let input = input_from_plain_casm(instructions);
let casm_states_by_opcode = input.state_transitions.casm_states_by_opcode;
assert_eq!(casm_states_by_opcode.jnz_opcode.len(), 1);
assert_eq!(casm_states_by_opcode.jnz_opcode_non_taken.len(), 1);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions stwo_cairo_prover/crates/cairo-air/src/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ pub struct CairoInteractionElements {
pub poseidon_full_round_chain: relations::PoseidonFullRoundChain,
pub cube_252: relations::Cube252,
pub poseidon_round_keys: relations::PoseidonRoundKeys,
pub range_check_felt_252_width_27: relations::RangeCheckFelt252Width27,
pub range_check_252_width_27: relations::RangeCheck252Width27,
pub memory_address_to_id: relations::MemoryAddressToId,
pub memory_id_to_value: relations::MemoryIdToBig,
pub range_checks: RangeChecksInteractionElements,
Expand All @@ -612,7 +612,7 @@ impl CairoInteractionElements {
poseidon_full_round_chain: relations::PoseidonFullRoundChain::draw(channel),
cube_252: relations::Cube252::draw(channel),
poseidon_round_keys: relations::PoseidonRoundKeys::draw(channel),
range_check_felt_252_width_27: relations::RangeCheckFelt252Width27::draw(channel),
range_check_252_width_27: relations::RangeCheck252Width27::draw(channel),
partial_ec_mul: relations::PartialEcMul::draw(channel),
pedersen_points_table: relations::PedersenPointsTable::draw(channel),
memory_address_to_id: relations::MemoryAddressToId::draw(channel),
Expand Down
4 changes: 2 additions & 2 deletions stwo_cairo_prover/crates/cairo-air/src/builtins_air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ impl BuiltinComponents {
.range_checks
.rc_4_4_4_4
.clone(),
range_check_felt_252_width_27_lookup_elements: interaction_elements
.range_check_felt_252_width_27
range_check_252_width_27_lookup_elements: interaction_elements
.range_check_252_width_27
.clone(),
},
interaction_claim.poseidon_builtin.unwrap().claimed_sum,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ mod tests {
use stwo_constraint_framework::expr::ExprEvaluator;

use super::*;
use crate::components::constraints_regression_test_values::CALL_OPCODE;
use crate::components::constraints_regression_test_values::CALL_OPCODE_ABS;

#[test]
fn call_opcode_constraints_regression() {
fn call_opcode_abs_constraints_regression() {
let mut rng = SmallRng::seed_from_u64(0);
let eval = Eval {
claim: Claim { log_size: 4 },
Expand All @@ -233,6 +233,6 @@ mod tests {
sum += c.assign(&assignment) * rng.gen::<QM31>();
}

assert_eq!(sum, CALL_OPCODE);
assert_eq!(sum, CALL_OPCODE_ABS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ pub const BLAKE_G: QM31 = qm31!(589517194, 1714400972, 124778100, 1709965715);
pub const BLAKE_ROUND_SIGMA: QM31 = qm31!(1679325815, 2032005875, 1831081253, 999201494);
pub const BLAKE_ROUND: QM31 = qm31!(689010793, 1714718853, 1598356108, 1862084735);
pub const CALL_OPCODE_REL_IMM: QM31 = qm31!(1058958974, 291699845, 1067131259, 1385778936);
pub const CALL_OPCODE: QM31 = qm31!(753588549, 110829970, 382462386, 1929508194);
pub const CALL_OPCODE_ABS: QM31 = qm31!(753588549, 110829970, 382462386, 1929508194);
pub const CUBE_252: QM31 = qm31!(2138805547, 791862161, 1496263445, 1432185054);
pub const GENERIC_OPCODE: QM31 = qm31!(1897142610, 70087557, 1948231093, 404344144);
pub const JNZ_OPCODE_TAKEN: QM31 = qm31!(863863896, 1799155008, 2087434855, 1577176263);
pub const JNZ_OPCODE: QM31 = qm31!(527000951, 699354015, 1174877270, 2099424613);
pub const JNZ_OPCODE_NON_TAKEN: QM31 = qm31!(527000951, 699354015, 1174877270, 2099424613);
pub const JUMP_OPCODE_DOUBLE_DEREF: QM31 = qm31!(1104346987, 1319193194, 162676979, 376017635);
pub const JUMP_OPCODE_REL_IMM: QM31 = qm31!(79712695, 631991609, 2034114495, 1081569364);
pub const JUMP_OPCODE_REL: QM31 = qm31!(1321760482, 1745914118, 2079741091, 369317996);
pub const JUMP_OPCODE: QM31 = qm31!(1822069462, 1014890554, 653917245, 1477843164);
pub const JUMP_OPCODE_ABS: QM31 = qm31!(1822069462, 1014890554, 653917245, 1477843164);
pub const MEMORY_ADDRESS_TO_ID: QM31 = qm31!(1557081375, 1030421885, 614292297, 1358103414);
pub const SMALL_MEMORY_ID_TO_BIG: QM31 = qm31!(1926563719, 1031963008, 80105391, 1734885910);
pub const BIG_MEMORY_ID_TO_BIG: QM31 = qm31!(482978858, 145449557, 1999339889, 1114454455);
Expand All @@ -38,15 +38,15 @@ pub const MUL_OPCODE: QM31 = qm31!(1765238355, 567102279, 1303576643, 132743394)
pub const PARTIAL_EC_MUL: QM31 = qm31!(1047475528, 531269891, 634870981, 2036983447);
pub const PEDERSEN_BUILTIN: QM31 = qm31!(830213408, 1658716778, 2015482698, 1847357253);
pub const PEDERSEN_POINTS_TABLE: QM31 = qm31!(2016504587, 1568791972, 1116506128, 884768463);
pub const POSEIDON_3_PARTIAL_ROUNDS_CHAIN: QM31 = qm31!(999129644, 603403435, 224776492, 211478069);
pub const POSEIDON_BUILTIN: QM31 = qm31!(943376676, 1660908785, 1242555985, 619448508);
pub const POSEIDON_3_PARTIAL_ROUNDS_CHAIN: QM31 =
qm31!(2033262826, 667964543, 319252363, 1402641406);
pub const POSEIDON_BUILTIN: QM31 = qm31!(1982000500, 548063079, 361145103, 1920658348);
pub const POSEIDON_FULL_ROUND_CHAIN: QM31 = qm31!(941127383, 452604700, 507558048, 839794501);
pub const POSEIDON_ROUND_KEYS: QM31 = qm31!(1182501131, 1048397214, 2019522910, 988967040);
pub const QM_31_ADD_MUL_OPCODE: QM31 = qm31!(989822133, 613070772, 258458924, 1917445389);
pub const RANGE_CHECK_BUILTIN_BITS_96: QM31 = qm31!(1203114103, 1251795602, 1884838449, 1758114216);
pub const RANGE_CHECK_BUILTIN_BITS_128: QM31 = qm31!(98318865, 510635574, 1814943674, 477505709);
pub const RANGE_CHECK_FELT_252_WIDTH_27: QM31 =
qm31!(1797698280, 1382662020, 2068921887, 1211498423);
pub const RANGE_CHECK_252_WIDTH_27: QM31 = qm31!(432510888, 1744417094, 1925158638, 1069774182);
pub const RANGE_CHECK_6: QM31 = qm31!(1839596244, 1029136098, 314080530, 1911163288);
pub const RANGE_CHECK_8: QM31 = qm31!(619380186, 51892308, 1959448152, 27164417);
pub const RANGE_CHECK_11: QM31 = qm31!(1797671535, 1448714071, 655307656, 610124137);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ mod tests {
use stwo_constraint_framework::expr::ExprEvaluator;

use super::*;
use crate::components::constraints_regression_test_values::JNZ_OPCODE;
use crate::components::constraints_regression_test_values::JNZ_OPCODE_NON_TAKEN;

#[test]
fn jnz_opcode_constraints_regression() {
fn jnz_opcode_non_taken_constraints_regression() {
let mut rng = SmallRng::seed_from_u64(0);
let eval = Eval {
claim: Claim { log_size: 4 },
Expand All @@ -197,6 +197,6 @@ mod tests {
sum += c.assign(&assignment) * rng.gen::<QM31>();
}

assert_eq!(sum, JNZ_OPCODE);
assert_eq!(sum, JNZ_OPCODE_NON_TAKEN);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ mod tests {
use stwo_constraint_framework::expr::ExprEvaluator;

use super::*;
use crate::components::constraints_regression_test_values::JUMP_OPCODE;
use crate::components::constraints_regression_test_values::JUMP_OPCODE_ABS;

#[test]
fn jump_opcode_constraints_regression() {
fn jump_opcode_abs_constraints_regression() {
let mut rng = SmallRng::seed_from_u64(0);
let eval = Eval {
claim: Claim { log_size: 4 },
Expand All @@ -180,6 +180,6 @@ mod tests {
sum += c.assign(&assignment) * rng.gen::<QM31>();
}

assert_eq!(sum, JUMP_OPCODE);
assert_eq!(sum, JUMP_OPCODE_ABS);
}
}
8 changes: 4 additions & 4 deletions stwo_cairo_prover/crates/cairo-air/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ pub mod blake_compress_opcode;
pub mod blake_g;
pub mod blake_round;
pub mod blake_round_sigma;
pub mod call_opcode;
pub mod call_opcode_abs;
pub mod call_opcode_rel_imm;
pub mod cube_252;
pub mod generic_opcode;
pub mod jnz_opcode;
pub mod jnz_opcode_non_taken;
pub mod jnz_opcode_taken;
pub mod jump_opcode;
pub mod jump_opcode_abs;
pub mod jump_opcode_double_deref;
pub mod jump_opcode_rel;
pub mod jump_opcode_rel_imm;
Expand Down Expand Up @@ -45,6 +45,7 @@ pub mod range_check_20_e;
pub mod range_check_20_f;
pub mod range_check_20_g;
pub mod range_check_20_h;
pub mod range_check_252_width_27;
pub mod range_check_3_3_3_3_3;
pub mod range_check_3_6_6_3;
pub mod range_check_4_3;
Expand All @@ -64,7 +65,6 @@ pub mod range_check_9_9_g;
pub mod range_check_9_9_h;
pub mod range_check_builtin_bits_128;
pub mod range_check_builtin_bits_96;
pub mod range_check_felt_252_width_27;
pub mod ret_opcode;
pub mod triple_xor_32;
pub mod verify_bitwise_xor_12;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub const RELATION_USES_PER_ROW: [RelationUse; 6] = [
uses: 1,
},
RelationUse {
relation_id: "RangeCheckFelt252Width27",
relation_id: "RangeCheck252Width27",
uses: 3,
},
RelationUse {
Expand All @@ -37,7 +37,7 @@ pub struct Eval {
pub cube_252_lookup_elements: relations::Cube252,
pub range_check_4_4_4_4_lookup_elements: relations::RangeCheck_4_4_4_4,
pub range_check_4_4_lookup_elements: relations::RangeCheck_4_4,
pub range_check_felt_252_width_27_lookup_elements: relations::RangeCheckFelt252Width27,
pub range_check_252_width_27_lookup_elements: relations::RangeCheck252Width27,
pub poseidon_3_partial_rounds_chain_lookup_elements: relations::Poseidon3PartialRoundsChain,
}

Expand Down Expand Up @@ -381,7 +381,7 @@ impl FrameworkEval for Eval {
&self.cube_252_lookup_elements,
&self.range_check_4_4_4_4_lookup_elements,
&self.range_check_4_4_lookup_elements,
&self.range_check_felt_252_width_27_lookup_elements,
&self.range_check_252_width_27_lookup_elements,
&mut eval,
);
PoseidonPartialRound::evaluate(
Expand Down Expand Up @@ -472,7 +472,7 @@ impl FrameworkEval for Eval {
&self.cube_252_lookup_elements,
&self.range_check_4_4_4_4_lookup_elements,
&self.range_check_4_4_lookup_elements,
&self.range_check_felt_252_width_27_lookup_elements,
&self.range_check_252_width_27_lookup_elements,
&mut eval,
);
PoseidonPartialRound::evaluate(
Expand Down Expand Up @@ -563,7 +563,7 @@ impl FrameworkEval for Eval {
&self.cube_252_lookup_elements,
&self.range_check_4_4_4_4_lookup_elements,
&self.range_check_4_4_lookup_elements,
&self.range_check_felt_252_width_27_lookup_elements,
&self.range_check_252_width_27_lookup_elements,
&mut eval,
);
eval.add_to_relation(RelationEntry::new(
Expand Down Expand Up @@ -689,8 +689,7 @@ mod tests {
cube_252_lookup_elements: relations::Cube252::dummy(),
range_check_4_4_4_4_lookup_elements: relations::RangeCheck_4_4_4_4::dummy(),
range_check_4_4_lookup_elements: relations::RangeCheck_4_4::dummy(),
range_check_felt_252_width_27_lookup_elements:
relations::RangeCheckFelt252Width27::dummy(),
range_check_252_width_27_lookup_elements: relations::RangeCheck252Width27::dummy(),
poseidon_3_partial_rounds_chain_lookup_elements:
relations::Poseidon3PartialRoundsChain::dummy(),
};
Expand Down
Loading
Loading