Skip to content

Commit

Permalink
Bump starknet-types-core version + Use the lib's pedersen hash (#1692)
Browse files Browse the repository at this point in the history
* Bump core types and use its pedersen hash func

* Add Changelog entry

* Fix param order

---------

Co-authored-by: Mario Rugiero <[email protected]>
  • Loading branch information
fmoletta and Oppen authored Apr 16, 2024
1 parent 6ff8126 commit e629428
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 25 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

* Bump `starknet-types-core` version + Use the lib's pedersen hash [#1692](https://github.com/lambdaclass/cairo-vm/pull/1692)

* refactor: Remove unused code & use constants whenever possible for builtin instance definitions[#1707](https://github.com/lambdaclass/cairo-vm/pull/1707)

* feat: missing EC hints for Starknet OS 0.13.1 [#1706](https://github.com/lambdaclass/cairo-vm/pull/1706)
Expand Down
13 changes: 6 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ keccak = { workspace = true }
hashbrown = { workspace = true }
anyhow = { workspace = true }
thiserror-no-std = { workspace = true }
starknet-types-core = { version = "0.0.9", default-features = false, features = ["serde", "curve", "num-traits"] }
starknet-types-core = { version = "0.1.0", default-features = false, features = ["serde", "curve", "num-traits", "hash"] }

# only for std
num-prime = { version = "0.4.3", features = ["big-int"], optional = true }
Expand Down
19 changes: 2 additions & 17 deletions vm/src/vm/runners/builtin_runner/hash.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use crate::air_private_input::{PrivateInput, PrivateInputPair};
use crate::stdlib::{cell::RefCell, prelude::*};
use crate::types::errors::math_errors::MathError;
use crate::types::instance_definitions::pedersen_instance_def::CELLS_PER_HASH;
use crate::types::relocatable::{MaybeRelocatable, Relocatable};
use crate::vm::errors::memory_errors::MemoryError;
use crate::vm::errors::runner_errors::RunnerError;
use crate::vm::runners::cairo_pie::BuiltinAdditionalData;
use crate::vm::vm_memory::memory::Memory;
use crate::vm::vm_memory::memory_segments::MemorySegmentManager;
use crate::Felt252;
use num_integer::{div_ceil, Integer};
use starknet_crypto::{pedersen_hash, FieldElement};
use starknet_types_core::hash::StarkHash;

#[derive(Debug, Clone)]
pub struct HashBuiltinRunner {
Expand Down Expand Up @@ -89,21 +87,8 @@ impl HashBuiltinRunner {
.resize(address.offset + 1, false);
}
self.verified_addresses.borrow_mut()[address.offset] = true;

//Convert MaybeRelocatable to FieldElement
let a_be_bytes = num_a.to_bytes_be();
let b_be_bytes = num_b.to_bytes_be();
let (y, x) = match (
FieldElement::from_bytes_be(&a_be_bytes),
FieldElement::from_bytes_be(&b_be_bytes),
) {
(Ok(field_element_a), Ok(field_element_b)) => (field_element_a, field_element_b),
_ => return Err(MathError::ByteConversionError.into()),
};
//Compute pedersen Hash
let fe_result = pedersen_hash(&x, &y);
//Convert result from FieldElement to MaybeRelocatable
let result = Felt252::from_bytes_be(&fe_result.to_bytes_be());
let result = starknet_types_core::hash::Pedersen::hash(num_b, num_a);
return Ok(Some(MaybeRelocatable::from(result)));
}
Ok(None)
Expand Down

0 comments on commit e629428

Please sign in to comment.