diff --git a/CHANGELOG.md b/CHANGELOG.md index c5a02fa4df..10bd3ed043 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ #### Upcoming Changes +* Bump `starknet-types-core` version + Use the lib's pedersen hash [#1734](https://github.com/lambdaclass/cairo-vm/pull/1734) + * refactor: Add boolean method Cairo1RunConfig::copy_to_output + Update Doc [#1778](https://github.com/lambdaclass/cairo-vm/pull/1778) * feat: Filter implicit arguments from return value in cairo1-run crate [#1775](https://github.com/lambdaclass/cairo-vm/pull/1775) diff --git a/Cargo.lock b/Cargo.lock index 6976dd01ec..25cc7845a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3068,12 +3068,11 @@ dependencies = [ [[package]] name = "starknet-types-core" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1051b4f4af0bb9b546388a404873ee1e6b9787b9d5b0b3319ecbfadf315ef276" +checksum = "b537ba94c95a6c320065653f2a784a395750650c86ef14779be91a233380e9b3" dependencies = [ "arbitrary", - "bitvec", "lambdaworks-crypto", "lambdaworks-math", "num-bigint", diff --git a/vm/Cargo.toml b/vm/Cargo.toml index 5f6bc49c16..6dd6918ac3 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -56,7 +56,7 @@ keccak = { workspace = true } hashbrown = { workspace = true } anyhow = { workspace = true } thiserror-no-std = { workspace = true } -starknet-types-core = { version = "0.1.0", default-features = false, features = ["serde", "curve", "num-traits", "hash"] } +starknet-types-core = { version = "0.1.2", default-features = false, features = ["serde", "curve", "num-traits", "hash"] } # only for std num-prime = { version = "0.4.3", features = ["big-int"], optional = true } diff --git a/vm/src/vm/runners/builtin_runner/poseidon.rs b/vm/src/vm/runners/builtin_runner/poseidon.rs index ee8d6c7e4f..7e6d229d9c 100644 --- a/vm/src/vm/runners/builtin_runner/poseidon.rs +++ b/vm/src/vm/runners/builtin_runner/poseidon.rs @@ -1,7 +1,6 @@ use crate::air_private_input::{PrivateInput, PrivateInputPoseidonState}; use crate::stdlib::{cell::RefCell, collections::HashMap, prelude::*}; use crate::types::builtin_name::BuiltinName; -use crate::types::errors::math_errors::MathError; use crate::types::instance_definitions::poseidon_instance_def::{ CELLS_PER_POSEIDON, INPUT_CELLS_PER_POSEIDON, }; @@ -12,7 +11,7 @@ use crate::vm::vm_memory::memory::Memory; use crate::vm::vm_memory::memory_segments::MemorySegmentManager; use crate::Felt252; use num_integer::div_ceil; -use starknet_crypto::{poseidon_permute_comp, FieldElement}; +use starknet_types_core::hash::Poseidon; #[derive(Debug, Clone)] pub struct PoseidonBuiltinRunner { @@ -76,28 +75,23 @@ impl PoseidonBuiltinRunner { for i in 0..INPUT_CELLS_PER_POSEIDON as usize { let m_index = (first_input_addr + i)?; let val = match memory.get(&m_index) { - Some(value) => { - let num = value - .get_int_ref() - .ok_or(RunnerError::BuiltinExpectedInteger(Box::new(( - BuiltinName::poseidon, - (first_input_addr + i)?, - ))))?; - FieldElement::from_bytes_be(&num.to_bytes_be()) - .map_err(|_| MathError::ByteConversionError)? - } + Some(value) => *value + .get_int_ref() + .ok_or(RunnerError::BuiltinExpectedInteger(Box::new(( + BuiltinName::poseidon, + m_index, + ))))?, _ => return Ok(None), }; input_felts.push(val) } // n_input_cells is fixed to 3, so this try_into will never fail - let mut poseidon_state: [FieldElement; 3] = input_felts.try_into().unwrap(); - poseidon_permute_comp(&mut poseidon_state); + let mut poseidon_state: [Felt252; 3] = input_felts.try_into().unwrap(); + Poseidon::hades_permutation(&mut poseidon_state); for (i, elem) in poseidon_state.iter().enumerate() { - self.cache.borrow_mut().insert( - (first_output_addr + i)?, - Felt252::from_bytes_be(&elem.to_bytes_be()), - ); + self.cache + .borrow_mut() + .insert((first_output_addr + i)?, *elem); } Ok(self.cache.borrow().get(&address).map(|x| x.into()))