diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a16017d4a..d21298bab8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. diff --git a/vm/src/tests/compare_factorial_outputs_all_layouts.sh b/vm/src/tests/compare_factorial_outputs_all_layouts.sh index 1a2067e4c8..e634fbb9d4 100755 --- a/vm/src/tests/compare_factorial_outputs_all_layouts.sh +++ b/vm/src/tests/compare_factorial_outputs_all_layouts.sh @@ -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 diff --git a/vm/src/types/instance_definitions/builtins_instance_def.rs b/vm/src/types/instance_definitions/builtins_instance_def.rs index a6d0bc44cc..ab13cf14fb 100644 --- a/vm/src/types/instance_definitions/builtins_instance_def.rs +++ b/vm/src/types/instance_definitions/builtins_instance_def.rs @@ -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, diff --git a/vm/src/types/instance_definitions/diluted_pool_instance_def.rs b/vm/src/types/instance_definitions/diluted_pool_instance_def.rs index 24e1a51ba6..9be73a835d 100644 --- a/vm/src/types/instance_definitions/diluted_pool_instance_def.rs +++ b/vm/src/types/instance_definitions/diluted_pool_instance_def.rs @@ -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, } diff --git a/vm/src/types/layout.rs b/vm/src/types/layout.rs index f7c523e5d7..ee0fae3196 100644 --- a/vm/src/types/layout.rs +++ b/vm/src/types/layout.rs @@ -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 { diff --git a/vm/src/types/layout_name.rs b/vm/src/types/layout_name.rs index d851292a51..1c957fbf90 100644 --- a/vm/src/types/layout_name.rs +++ b/vm/src/types/layout_name.rs @@ -17,6 +17,7 @@ pub enum LayoutName { starknet, starknet_with_keccak, recursive_large_output, + recursive_with_poseidon, all_solidity, all_cairo, dynamic, @@ -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", @@ -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, diff --git a/vm/src/vm/runners/cairo_runner.rs b/vm/src/vm/runners/cairo_runner.rs index 02a0811d52..1040e1f52a 100644 --- a/vm/src/vm/runners/cairo_runner.rs +++ b/vm/src/vm/runners/cairo_runner.rs @@ -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(),