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

Remove felt new trait #734

Merged
merged 8 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 4 additions & 6 deletions felt/src/bigint_felt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::{
},
};

use crate::{FeltOps, NewFelt, ParseFeltError, FIELD_HIGH, FIELD_LOW};
use crate::{FeltOps, ParseFeltError, FIELD_HIGH, FIELD_LOW};

lazy_static! {
pub static ref CAIRO_PRIME: BigUint =
Expand Down Expand Up @@ -125,13 +125,11 @@ impl<const PH: u128, const PL: u128> From<&BigInt> for FeltBigInt<PH, PL> {
}
}

impl<const PH: u128, const PL: u128> NewFelt<PH, PL> for FeltBigInt<PH, PL> {
impl<const PH: u128, const PL: u128> FeltOps<PH, PL> for FeltBigInt<PH, PL> {
fn new<T: Into<Self>>(value: T) -> Self {
value.into()
}
}

impl<const PH: u128, const PL: u128> FeltOps<PH, PL> for FeltBigInt<PH, PL> {
fn modpow(&self, exponent: &FeltBigInt<PH, PL>, modulus: &FeltBigInt<PH, PL>) -> Self {
FeltBigInt {
val: self.val.modpow(&exponent.val, &modulus.val),
Expand Down Expand Up @@ -825,12 +823,12 @@ impl fmt::Display for ParseFeltError {
#[macro_export]
macro_rules! felt_str {
($val: expr) => {
<felt::Felt as felt::NewFelt<{ felt::FIELD_HIGH }, { felt::FIELD_LOW }>>::new(
<felt::Felt as felt::FeltOps<{ felt::FIELD_HIGH }, { felt::FIELD_LOW }>>::new(
num_bigint::BigInt::parse_bytes($val.as_bytes(), 10_u32).expect("Couldn't parse bytes"),
)
};
($val: expr, $opt: expr) => {
<felt::Felt as felt::NewFelt<{ felt::FIELD_HIGH }, { felt::FIELD_LOW }>>::new(
<felt::Felt as felt::FeltOps<{ felt::FIELD_HIGH }, { felt::FIELD_LOW }>>::new(
num_bigint::BigInt::parse_bytes($val.as_bytes(), $opt as u32)
.expect("Couldn't parse bytes"),
)
Expand Down
7 changes: 1 addition & 6 deletions felt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ pub type Felt = FeltBigInt<FIELD_HIGH, FIELD_LOW>;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ParseFeltError;

pub trait NewFelt<const PH: u128, const PL: u128> {
fn new<T: Into<FeltBigInt<PH, PL>>>(value: T) -> Self;
}

pub trait FeltOps<const PH: u128, const PL: u128> {
fn new<T: Into<FeltBigInt<PH, PL>>>(value: T) -> Self;
fn modpow(&self, exponent: &FeltBigInt<PH, PL>, modulus: &FeltBigInt<PH, PL>) -> Self;
fn iter_u64_digits(&self) -> U64Digits;
fn to_signed_bytes_le(&self) -> Vec<u8>;
Expand All @@ -44,7 +41,6 @@ pub trait FeltOps<const PH: u128, const PL: u128> {
macro_rules! assert_felt_impl {
($type:ty) => {
const _: () = {
fn assert_new_felt<T: NewFelt<FIELD_HIGH, FIELD_LOW>>() {}
fn assert_felt_ops<T: FeltOps<FIELD_HIGH, FIELD_LOW>>() {}
fn assert_add<T: Add>() {}
fn assert_add_ref<'a, T: Add<&'a $type>>() {}
Expand Down Expand Up @@ -92,7 +88,6 @@ macro_rules! assert_felt_impl {
// RFC 2056
#[allow(dead_code)]
fn assert_all() {
assert_new_felt::<$type>();
assert_felt_ops::<$type>();
assert_add::<$type>();
assert_add::<&$type>();
Expand Down
2 changes: 1 addition & 1 deletion src/cairo_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ mod tests {
},
utils::test_utils::*,
};
use felt::NewFelt;
use felt::FeltOps;
use std::io::Read;

fn run_test_program(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
vm_core::VirtualMachine,
},
};
use felt::{Felt, NewFelt};
use felt::{Felt, FeltOps};
use num_traits::ToPrimitive;
use std::{borrow::Cow, collections::HashMap};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ mod tests {
vm_memory::memory::Memory,
},
};
use felt::NewFelt;
use felt::FeltOps;
use num_traits::{One, Zero};
use std::any::Any;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
vm_core::VirtualMachine,
},
};
use felt::{Felt, NewFelt};
use felt::{Felt, FeltOps};
use num_traits::{ToPrimitive, Zero};
use std::{borrow::Cow, collections::HashMap, ops::Add};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
vm_core::VirtualMachine,
},
};
use felt::{Felt, NewFelt};
use felt::{Felt, FeltOps};
use num_traits::{Signed, ToPrimitive};
use std::collections::HashMap;

Expand Down
2 changes: 1 addition & 1 deletion src/hint_processor/builtin_hint_processor/hint_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub fn get_reference_from_var_name<'a>(

#[cfg(test)]
mod tests {
use felt::NewFelt;
use felt::FeltOps;

use super::*;
use crate::{
Expand Down
2 changes: 1 addition & 1 deletion src/hint_processor/builtin_hint_processor/math_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
vm_core::VirtualMachine,
},
};
use felt::{Felt, FeltOps, NewFelt, PRIME_STR};
use felt::{Felt, FeltOps, PRIME_STR};
use num_bigint::BigUint;
use num_integer::Integer;
use num_traits::One;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ mod tests {
vm_memory::memory::Memory,
},
};
use felt::NewFelt;
use felt::FeltOps;

#[test]
fn get_integer_from_var_name_valid() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
types::exec_scope::ExecutionScopes,
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
};
use felt::{Felt, NewFelt};
use felt::{Felt, FeltOps};
use num_traits::Signed;
use std::{any::Any, collections::HashMap};

Expand Down
2 changes: 1 addition & 1 deletion src/hint_processor/builtin_hint_processor/pow_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
serde::deserialize_program::ApTracking,
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
};
use felt::{Felt, NewFelt};
use felt::{Felt, FeltOps};
use num_integer::Integer;
use std::collections::HashMap;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
vm_core::VirtualMachine,
},
};
use felt::{Felt, NewFelt};
use felt::{Felt, FeltOps};
use std::collections::HashMap;
/*
Implements hint:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
types::exec_scope::ExecutionScopes,
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
};
use felt::{Felt, FeltOps, NewFelt};
use felt::{Felt, FeltOps};
use num_bigint::BigInt;
use num_integer::Integer;
use num_traits::{One, Zero};
Expand Down Expand Up @@ -175,7 +175,7 @@ mod tests {
vm_memory::memory::Memory,
},
};
use felt::NewFelt;
use felt::FeltOps;
use std::any::Any;

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn pack_from_relocatable(rel: Relocatable, vm: &VirtualMachine) -> Result<Bi
mod tests {
use super::*;
use crate::utils::test_utils::*;
use felt::{felt_str, NewFelt};
use felt::{felt_str, FeltOps};
use num_bigint::BigUint;
use num_traits::One;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ mod tests {
vm_memory::memory::Memory,
},
};
use felt::NewFelt;
use felt::FeltOps;
use num_traits::Zero;
use std::{any::Any, ops::Shl};

Expand Down
2 changes: 1 addition & 1 deletion src/hint_processor/builtin_hint_processor/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
vm_core::VirtualMachine,
},
};
use felt::{Felt, NewFelt};
use felt::{Felt, FeltOps};
use num_traits::{One, ToPrimitive, Zero};
use std::collections::HashMap;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
vm::errors::{hint_errors::HintError, vm_errors::VirtualMachineError},
vm::vm_core::VirtualMachine,
};
use felt::{Felt, NewFelt};
use felt::{Felt, FeltOps};
use generic_array::GenericArray;
use num_traits::{One, Zero};
use sha2::compress256;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
vm_core::VirtualMachine,
},
};
use felt::{Felt, NewFelt};
use felt::{Felt, FeltOps};
use num_integer::Integer;
use num_traits::{One, ToPrimitive, Zero};
use std::collections::HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
serde::deserialize_program::ApTracking,
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
};
use felt::{Felt, FeltOps, NewFelt};
use felt::{Felt, FeltOps};
use num_integer::div_rem;
use num_traits::{One, Signed, Zero};
use std::{
Expand Down
2 changes: 1 addition & 1 deletion src/hint_processor/builtin_hint_processor/usort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
types::exec_scope::ExecutionScopes,
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
};
use felt::{Felt, NewFelt};
use felt::{Felt, FeltOps};
use num_traits::{ToPrimitive, Zero};
use std::{any::Any, collections::HashMap};

Expand Down
2 changes: 1 addition & 1 deletion src/hint_processor/hint_processor_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ mod tests {
errors::memory_errors::MemoryError, vm_core::VirtualMachine, vm_memory::memory::Memory,
},
};
use felt::NewFelt;
use felt::FeltOps;

#[test]
fn get_integer_from_reference_with_immediate_value() {
Expand Down
2 changes: 1 addition & 1 deletion src/math_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub fn ec_double_slope(point: &(BigInt, BigInt), alpha: &BigInt, prime: &BigInt)
mod tests {
use super::*;
use crate::utils::test_utils::*;
use felt::NewFelt;
use felt::FeltOps;
use num_traits::Num;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/serde/deserialize_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ pub fn deserialize_program(
#[cfg(test)]
mod tests {
use super::*;
use felt::{felt_str, NewFelt};
use felt::{felt_str, FeltOps};
use num_traits::Zero;
use std::{fs::File, io::BufReader};

Expand Down
2 changes: 1 addition & 1 deletion src/serde/deserialize_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
serde::deserialize_program::{OffsetValue, ValueAddress},
types::instruction::Register,
};
use felt::{Felt, NewFelt, ParseFeltError};
use felt::{Felt, FeltOps, ParseFeltError};
use nom::{
branch::alt,
bytes::{
Expand Down
2 changes: 1 addition & 1 deletion src/types/exec_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl Default for ExecutionScopes {
#[cfg(test)]
mod tests {
use super::*;
use felt::{Felt, NewFelt};
use felt::{Felt, FeltOps};
use num_traits::One;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/types/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub(crate) fn is_call_instruction(encoded_instruction: &Felt, imm: Option<&Felt>
#[cfg(test)]
mod tests {
use super::*;
use felt::NewFelt;
use felt::FeltOps;

#[test]
fn is_call_instruction_true() {
Expand Down
2 changes: 1 addition & 1 deletion src/types/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ mod tests {
use super::*;
use crate::serde::deserialize_program::{ApTracking, FlowTrackingData};
use crate::utils::test_utils::mayberelocatable;
use felt::{felt_str, NewFelt};
use felt::{felt_str, FeltOps};
use num_traits::Zero;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/types/relocatable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
relocatable,
vm::errors::{memory_errors::MemoryError, vm_errors::VirtualMachineError},
};
use felt::{Felt, NewFelt};
use felt::{Felt, FeltOps};
use num_traits::{FromPrimitive, ToPrimitive, Zero};
use serde::{Deserialize, Serialize};
use std::{
Expand Down
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub mod test_utils {
MaybeRelocatable::from(($val1, $val2))
};
($val1 : expr) => {
MaybeRelocatable::from(<felt::Felt as felt::NewFelt<
MaybeRelocatable::from(<felt::Felt as felt::FeltOps<
{ felt::FIELD_HIGH },
{ felt::FIELD_LOW },
>>::new($val1 as i128))
Expand Down Expand Up @@ -531,7 +531,7 @@ mod test {
vm_core::VirtualMachine, vm_memory::memory::Memory,
},
};
use felt::{Felt, NewFelt};
use felt::{Felt, FeltOps};
use num_traits::One;
use std::{any::Any, cell::RefCell, collections::HashMap, rc::Rc};

Expand Down
2 changes: 1 addition & 1 deletion src/vm/context/run_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ mod tests {
use crate::types::instruction::{ApUpdate, FpUpdate, Opcode, PcUpdate, Res};
use crate::utils::test_utils::mayberelocatable;
use crate::vm::errors::memory_errors::MemoryError;
use felt::{Felt, NewFelt};
use felt::{Felt, FeltOps};

#[test]
fn compute_dst_addr_for_ap_register() {
Expand Down
2 changes: 1 addition & 1 deletion src/vm/decoding/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn decode_offset(offset: i64) -> isize {
#[cfg(test)]
mod decoder_test {
use super::*;
use felt::NewFelt;
use felt::FeltOps;

#[test]
fn invalid_op1_reg() {
Expand Down
2 changes: 1 addition & 1 deletion src/vm/runners/builtin_runner/bitwise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ mod tests {
hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor,
types::program::Program, utils::test_utils::*, vm::runners::cairo_runner::CairoRunner,
};
use felt::{Felt, NewFelt};
use felt::{Felt, FeltOps};

#[test]
fn get_used_instances() {
Expand Down
2 changes: 1 addition & 1 deletion src/vm/runners/builtin_runner/ec_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::vm::errors::runner_errors::RunnerError;
use crate::vm::vm_core::VirtualMachine;
use crate::vm::vm_memory::memory::Memory;
use crate::vm::vm_memory::memory_segments::MemorySegmentManager;
use felt::{Felt, FeltOps, NewFelt};
use felt::{Felt, FeltOps};
use num_bigint::{BigInt, ToBigInt};
use num_integer::{div_ceil, Integer};
use num_traits::{Num, One, Pow, Zero};
Expand Down
2 changes: 1 addition & 1 deletion src/vm/runners/builtin_runner/keccak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ mod tests {
runners::builtin_runner::BuiltinRunner,
vm_core::VirtualMachine,
};
use felt::NewFelt;
use felt::FeltOps;
use std::path::Path;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/vm/runners/builtin_runner/range_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
},
},
};
use felt::{Felt, NewFelt};
use felt::{Felt, FeltOps};
use num_integer::Integer;
use num_traits::{One, ToPrimitive, Zero};
use std::{
Expand Down
Loading