Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump starknet-types-core version + Use the lib's pedersen hash #1692

Merged
merged 8 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

* BREAKING: Remove `CairoRunner::add_additional_hash_builtin` & `VirtualMachine::disable_trace`[#1658](https://github.com/lambdaclass/cairo-vm/pull/1658)

* feat: output builtin add_attribute method [#1691](https://github.com/lambdaclass/cairo-vm/pull/1691)
Expand Down
14 changes: 7 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 @@ -65,7 +65,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,6 +1,5 @@
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, INPUT_CELLS_PER_HASH,
};
Expand All @@ -10,9 +9,8 @@ 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;

use super::HASH_BUILTIN_NAME;

Expand Down Expand Up @@ -104,21 +102,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
Loading