Skip to content

Commit

Permalink
Update starknet-core-types to version 0.0.4 (#405)
Browse files Browse the repository at this point in the history
* Update starknet-types-core version

* Update code

* Update code

* fix
  • Loading branch information
fmoletta authored Dec 22, 2023
1 parent 6b244ff commit 1ff2f02
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
19 changes: 17 additions & 2 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ melior = { version = "0.14.1", features = ["ods-dialects"] }
mlir-sys = "0.2.1"
num-bigint = "0.4.4"
num-traits = "0.2"
starknet-types-core = { git = "https://github.com/starknet-io/types-rs.git", rev = "4bc8a5db3c86f017e8be7dc43531a2cb6db011c0", default-features = false, features = ["serde"] }
starknet-types-core = { version = "0.0.4", default-features = false, features = ["serde"] }
tempfile = "3.6"
thiserror = "1.0"
tracing = "0.1"
Expand Down
18 changes: 9 additions & 9 deletions src/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use cairo_lang_sierra::{
};
use educe::Educe;
use num_bigint::{BigInt, Sign};
use starknet_types_core::felt::{biguint_to_felt, felt_to_bigint, Felt};
use starknet_types_core::felt::Felt;
use std::{alloc::Layout, collections::HashMap, ops::Neg, ptr::NonNull};

/// A JitValue is a value that can be passed to the JIT engine as an argument or received as a result.
Expand Down Expand Up @@ -177,7 +177,7 @@ impl JitValue {
Self::Felt252(value) => {
let ptr = arena.alloc_layout(get_integer_layout(252)).cast();

let data = felt252_bigint(felt_to_bigint(*value));
let data = felt252_bigint(value.to_bigint());
ptr.cast::<[u32; 8]>().as_mut().copy_from_slice(&data);
ptr
}
Expand Down Expand Up @@ -452,8 +452,8 @@ impl JitValue {
.alloc_layout(layout_repeat(&get_integer_layout(252), 2).unwrap().0)
.cast();

let a = felt252_bigint(felt_to_bigint(*a));
let b = felt252_bigint(felt_to_bigint(*b));
let a = felt252_bigint(a.to_bigint());
let b = felt252_bigint(b.to_bigint());
let data = [a, b];

ptr.cast::<[[u32; 8]; 2]>().as_mut().copy_from_slice(&data);
Expand All @@ -465,10 +465,10 @@ impl JitValue {
.alloc_layout(layout_repeat(&get_integer_layout(252), 4).unwrap().0)
.cast();

let a = felt252_bigint(felt_to_bigint(*a));
let b = felt252_bigint(felt_to_bigint(*b));
let c = felt252_bigint(felt_to_bigint(*c));
let d = felt252_bigint(felt_to_bigint(*d));
let a = felt252_bigint(a.to_bigint());
let b = felt252_bigint(b.to_bigint());
let c = felt252_bigint(c.to_bigint());
let d = felt252_bigint(d.to_bigint());
let data = [a, b, c, d];

ptr.cast::<[[u32; 8]; 4]>().as_mut().copy_from_slice(&data);
Expand Down Expand Up @@ -710,6 +710,6 @@ impl JitValue {
_ => value.to_biguint().unwrap(),
};

Self::Felt252(biguint_to_felt(&value))
Self::Felt252(Felt::from(&value))
}
}
8 changes: 4 additions & 4 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use melior::{
use num_bigint::{BigInt, BigUint, Sign};
use num_traits::identities::Zero;
use proptest::{strategy::Strategy, test_runner::TestCaseError};
use starknet_types_core::felt::{felt_to_biguint, Felt};
use starknet_types_core::felt::Felt;
use std::{
env::var,
fs,
Expand Down Expand Up @@ -399,8 +399,8 @@ pub fn compare_outputs(
let vm_a = BigUint::from_str(vm_rets.next().unwrap()).unwrap();
let vm_b = BigUint::from_str(vm_rets.next().unwrap()).unwrap();

let native_value_a = felt_to_biguint(*a);
let native_value_b = felt_to_biguint(*b);
let native_value_a = a.to_biguint();
let native_value_b = b.to_biguint();
prop_assert_eq!(vm_a, native_value_a, "felt value mismatch in ecpoint");
prop_assert_eq!(vm_b, native_value_b, "felt value mismatch in ecpoint");
} else {
Expand All @@ -417,7 +417,7 @@ pub fn compare_outputs(
let vm_value = vm_rets.next().unwrap();

if let JitValue::Felt252(felt) = native_rets.next().unwrap() {
let native_value = felt_to_biguint(*felt);
let native_value = felt.to_biguint();
let vm_value = BigUint::from_str(vm_value).unwrap();
prop_assert_eq!(vm_value, native_value, "felt value mismatch");
} else {
Expand Down

0 comments on commit 1ff2f02

Please sign in to comment.