Skip to content

Commit

Permalink
Add recursive_with_poseidon layout (#1724)
Browse files Browse the repository at this point in the history
* Use enum for LayoutName

* Move LayoutName to its own module + fix tests

* Fix clap enum parsing

* Fix tests

* Fix test & doc

* Manually implement ValueEnum

* fmt

* Simplify code

* Move arbitrary impl to module

* Fix benchmark code

* Add changelog entry

* Remove unnecessary impl

* Use value instead of reference

Co-authored-by: Mario Rugiero <[email protected]>

* Fix test added by merge

* Add `recursive_with_poseidon` layout

* Add changelog entry

* Add comment + fix log_units in diluted pool

* Fix log_units & comment

---------

Co-authored-by: Mario Rugiero <[email protected]>
  • Loading branch information
fmoletta and Oppen authored Apr 19, 2024
1 parent 932986c commit 15bf794
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#### Upcoming Changes

* feat: Add `recursive_with_poseidon` layout[#1724](https://github.com/lambdaclass/cairo-vm/pull/1724)

* refactor(BREAKING): Use an enum to represent layout name[#1715](https://github.com/lambdaclass/cairo-vm/pull/1715)
* Add enum `LayoutName` to represent cairo layout names.
* `CairoRunConfig`, `Cairo1RunConfig` & `CairoRunner` field `layout` type changed from `String` to `LayoutName`.
Expand Down
2 changes: 1 addition & 1 deletion vm/src/tests/compare_factorial_outputs_all_layouts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ passed_tests=0
failed_tests=0
exit_code=0

for layout in "plain" "small" "dex" "recursive" "starknet" "starknet_with_keccak" "recursive_large_output" "all_solidity" "starknet_with_keccak"; do
for layout in "plain" "small" "dex" "recursive" "starknet" "starknet_with_keccak" "recursive_large_output" "recursive_with_poseidon" "all_solidity" "starknet_with_keccak"; do
# Run cairo_vm
echo "Running cairo-vm with layout $layout"
cargo run -p cairo-vm-cli --release -- --layout $layout --proof_mode $factorial_compiled --trace_file factorial_rs.trace --memory_file factorial_rs.memory --air_public_input factorial_rs.air_public_input --air_private_input factorial_rs.air_private_input
Expand Down
16 changes: 16 additions & 0 deletions vm/src/types/instance_definitions/builtins_instance_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@ impl BuiltinsInstanceDef {
}
}

pub(crate) fn recursive_with_poseidon() -> BuiltinsInstanceDef {
BuiltinsInstanceDef {
output: true,
pedersen: Some(PedersenInstanceDef::new(Some(256))),
range_check: Some(RangeCheckInstanceDef::new(Some(16))),
ecdsa: None,
bitwise: Some(BitwiseInstanceDef::new(Some(16))),
ec_op: None,
keccak: None,
poseidon: Some(PoseidonInstanceDef::new(Some(64))),
range_check96: None,
add_mod: None,
mul_mod: None,
}
}

pub(crate) fn all_cairo() -> BuiltinsInstanceDef {
BuiltinsInstanceDef {
output: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde::Serialize;

#[derive(Serialize, Debug, PartialEq)]
pub(crate) struct DilutedPoolInstanceDef {
pub(crate) units_per_step: u32,
pub(crate) units_per_step: u32, // 2 ^ log_units_per_step (for cairo_lang comparison)
pub(crate) spacing: u32,
pub(crate) n_bits: u32,
}
Expand Down
9 changes: 9 additions & 0 deletions vm/src/types/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ impl CairoLayout {
diluted_pool_instance_def: Some(DilutedPoolInstanceDef::default()),
}
}
pub(crate) fn recursive_with_poseidon() -> CairoLayout {
CairoLayout {
name: LayoutName::recursive_with_poseidon,
rc_units: 4,
builtins: BuiltinsInstanceDef::recursive_with_poseidon(),
public_memory_fraction: 8,
diluted_pool_instance_def: Some(DilutedPoolInstanceDef::new(8, 4, 16)),
}
}

pub(crate) fn all_cairo_instance() -> CairoLayout {
CairoLayout {
Expand Down
3 changes: 3 additions & 0 deletions vm/src/types/layout_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub enum LayoutName {
starknet,
starknet_with_keccak,
recursive_large_output,
recursive_with_poseidon,
all_solidity,
all_cairo,
dynamic,
Expand All @@ -32,6 +33,7 @@ impl LayoutName {
LayoutName::starknet => "starknet",
LayoutName::starknet_with_keccak => "starknet_with_keccak",
LayoutName::recursive_large_output => "recursive_large_output",
LayoutName::recursive_with_poseidon => "recursive_with_poseidon",
LayoutName::all_solidity => "all_solidity",
LayoutName::all_cairo => "all_cairo",
LayoutName::dynamic => "all_cairo",
Expand All @@ -56,6 +58,7 @@ impl ValueEnum for LayoutName {
Self::starknet,
Self::starknet_with_keccak,
Self::recursive_large_output,
Self::recursive_with_poseidon,
Self::all_solidity,
Self::all_cairo,
Self::dynamic,
Expand Down
1 change: 1 addition & 0 deletions vm/src/vm/runners/cairo_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ impl CairoRunner {
LayoutName::starknet => CairoLayout::starknet_instance(),
LayoutName::starknet_with_keccak => CairoLayout::starknet_with_keccak_instance(),
LayoutName::recursive_large_output => CairoLayout::recursive_large_output_instance(),
LayoutName::recursive_with_poseidon => CairoLayout::recursive_with_poseidon(),
LayoutName::all_cairo => CairoLayout::all_cairo_instance(),
LayoutName::all_solidity => CairoLayout::all_solidity_instance(),
LayoutName::dynamic => CairoLayout::dynamic_instance(),
Expand Down

0 comments on commit 15bf794

Please sign in to comment.