|
1 | | -use crate::types::layout_name::LayoutName; |
2 | | - |
3 | | -use super::instance_definitions::{ |
4 | | - builtins_instance_def::BuiltinsInstanceDef, diluted_pool_instance_def::DilutedPoolInstanceDef, |
| 1 | +use crate::{types::layout_name::LayoutName, vm::errors::runner_errors::RunnerError}; |
| 2 | + |
| 3 | +use super::{ |
| 4 | + builtin_name::BuiltinName, |
| 5 | + instance_definitions::{ |
| 6 | + builtins_instance_def::BuiltinsInstanceDef, |
| 7 | + diluted_pool_instance_def::DilutedPoolInstanceDef, |
| 8 | + }, |
5 | 9 | }; |
6 | 10 |
|
7 | 11 | pub(crate) const MEMORY_UNITS_PER_STEP: u32 = 8; |
@@ -214,38 +218,58 @@ pub struct RawCairoLayoutParams { |
214 | 218 | } |
215 | 219 |
|
216 | 220 | impl TryFrom<RawCairoLayoutParams> for CairoLayoutParams { |
217 | | - type Error = &'static str; |
| 221 | + type Error = RunnerError; |
218 | 222 |
|
219 | 223 | fn try_from(value: RawCairoLayoutParams) -> Result<Self, Self::Error> { |
220 | 224 | if !value.uses_pedersen_builtin && value.pedersen_ratio != 0 { |
221 | | - return Err("pedersen ratio should be 0 when disabled"); |
| 225 | + return Err(RunnerError::BadDynamicLayoutBuiltinRatio( |
| 226 | + BuiltinName::pedersen, |
| 227 | + )); |
222 | 228 | } |
223 | 229 | if !value.uses_range_check_builtin && value.range_check_ratio != 0 { |
224 | | - return Err("range_check ratio should be 0 when disabled"); |
| 230 | + return Err(RunnerError::BadDynamicLayoutBuiltinRatio( |
| 231 | + BuiltinName::range_check, |
| 232 | + )); |
225 | 233 | } |
226 | 234 | if !value.uses_ecdsa_builtin && value.ecdsa_ratio != 0 { |
227 | | - return Err("ecdsa ratio should be 0 when disabled"); |
| 235 | + return Err(RunnerError::BadDynamicLayoutBuiltinRatio( |
| 236 | + BuiltinName::ecdsa, |
| 237 | + )); |
228 | 238 | } |
229 | 239 | if !value.uses_bitwise_builtin && value.bitwise_ratio != 0 { |
230 | | - return Err("bitwise ratio should be 0 when disabled"); |
| 240 | + return Err(RunnerError::BadDynamicLayoutBuiltinRatio( |
| 241 | + BuiltinName::bitwise, |
| 242 | + )); |
231 | 243 | } |
232 | 244 | if !value.uses_ec_op_builtin && value.ec_op_ratio != 0 { |
233 | | - return Err("ec_op ratio should be 0 when disabled"); |
| 245 | + return Err(RunnerError::BadDynamicLayoutBuiltinRatio( |
| 246 | + BuiltinName::ec_op, |
| 247 | + )); |
234 | 248 | } |
235 | 249 | if !value.uses_keccak_builtin && value.keccak_ratio != 0 { |
236 | | - return Err("keccak ratio should be 0 when disabled"); |
| 250 | + return Err(RunnerError::BadDynamicLayoutBuiltinRatio( |
| 251 | + BuiltinName::keccak, |
| 252 | + )); |
237 | 253 | } |
238 | 254 | if !value.uses_poseidon_builtin && value.poseidon_ratio != 0 { |
239 | | - return Err("poseidon ratio should be 0 when disabled"); |
| 255 | + return Err(RunnerError::BadDynamicLayoutBuiltinRatio( |
| 256 | + BuiltinName::poseidon, |
| 257 | + )); |
240 | 258 | } |
241 | 259 | if !value.uses_range_check96_builtin && value.range_check96_ratio != 0 { |
242 | | - return Err("range_check96 ratio should be 0 when disabled"); |
| 260 | + return Err(RunnerError::BadDynamicLayoutBuiltinRatio( |
| 261 | + BuiltinName::range_check96, |
| 262 | + )); |
243 | 263 | } |
244 | 264 | if !value.uses_add_mod_builtin && value.add_mod_ratio != 0 { |
245 | | - return Err("add_mod ratio should be 0 when disabled"); |
| 265 | + return Err(RunnerError::BadDynamicLayoutBuiltinRatio( |
| 266 | + BuiltinName::add_mod, |
| 267 | + )); |
246 | 268 | } |
247 | 269 | if !value.uses_mul_mod_builtin && value.mul_mod_ratio != 0 { |
248 | | - return Err("mul_mod ratio should be 0 when disabled"); |
| 270 | + return Err(RunnerError::BadDynamicLayoutBuiltinRatio( |
| 271 | + BuiltinName::mul_mod, |
| 272 | + )); |
249 | 273 | } |
250 | 274 |
|
251 | 275 | Ok(CairoLayoutParams { |
@@ -290,16 +314,16 @@ where |
290 | 314 |
|
291 | 315 | #[cfg(test)] |
292 | 316 | mod tests { |
| 317 | + use super::*; |
| 318 | + #[cfg(feature = "mod_builtin")] |
| 319 | + use crate::types::instance_definitions::mod_instance_def::ModInstanceDef; |
293 | 320 | use crate::types::instance_definitions::{ |
294 | 321 | bitwise_instance_def::BitwiseInstanceDef, ec_op_instance_def::EcOpInstanceDef, |
295 | 322 | ecdsa_instance_def::EcdsaInstanceDef, keccak_instance_def::KeccakInstanceDef, |
296 | | - mod_instance_def::ModInstanceDef, pedersen_instance_def::PedersenInstanceDef, |
297 | | - poseidon_instance_def::PoseidonInstanceDef, |
| 323 | + pedersen_instance_def::PedersenInstanceDef, poseidon_instance_def::PoseidonInstanceDef, |
298 | 324 | range_check_instance_def::RangeCheckInstanceDef, |
299 | 325 | }; |
300 | 326 |
|
301 | | - use super::*; |
302 | | - |
303 | 327 | #[cfg(target_arch = "wasm32")] |
304 | 328 | use wasm_bindgen_test::*; |
305 | 329 |
|
@@ -490,22 +514,30 @@ mod tests { |
490 | 514 | layout.builtins.range_check96, |
491 | 515 | Some(RangeCheckInstanceDef { ratio: Some(0) }) |
492 | 516 | ); |
493 | | - assert_eq!( |
494 | | - layout.builtins.mul_mod, |
495 | | - Some(ModInstanceDef { |
496 | | - ratio: Some(32), |
497 | | - word_bit_len: 96, // hardcoded |
498 | | - batch_size: 1 // hardcoded |
499 | | - }) |
500 | | - ); |
501 | | - assert_eq!( |
502 | | - layout.builtins.add_mod, |
503 | | - Some(ModInstanceDef { |
504 | | - ratio: Some(0), |
505 | | - word_bit_len: 96, // hardcoded |
506 | | - batch_size: 1 // hardcoded |
507 | | - }) |
508 | | - ); |
| 517 | + #[cfg(feature = "mod_builtin")] |
| 518 | + { |
| 519 | + assert_eq!( |
| 520 | + layout.builtins.mul_mod, |
| 521 | + Some(ModInstanceDef { |
| 522 | + ratio: Some(32), |
| 523 | + word_bit_len: 96, // hardcoded |
| 524 | + batch_size: 1 // hardcoded |
| 525 | + }), |
| 526 | + ); |
| 527 | + assert_eq!( |
| 528 | + layout.builtins.add_mod, |
| 529 | + Some(ModInstanceDef { |
| 530 | + ratio: Some(0), |
| 531 | + word_bit_len: 96, // hardcoded |
| 532 | + batch_size: 1 // hardcoded |
| 533 | + }) |
| 534 | + ); |
| 535 | + } |
| 536 | + #[cfg(not(feature = "mod_builtin"))] |
| 537 | + { |
| 538 | + assert_eq!(layout.builtins.mul_mod, None,); |
| 539 | + assert_eq!(layout.builtins.add_mod, None,); |
| 540 | + } |
509 | 541 | } |
510 | 542 |
|
511 | 543 | #[test] |
|
0 commit comments