Skip to content

Commit

Permalink
BigUint renamed value
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Jun 25, 2024
1 parent b762f60 commit cbebcb1
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 76 deletions.
2 changes: 1 addition & 1 deletion framework/base/src/io/finish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ where
FA::finish_api_impl().finish_managed_buffer_raw(managed_buffer.handle.clone());
Ok(())
} else if let Some(big_uint) = value.try_cast_ref::<BigUint<FA>>() {
FA::finish_api_impl().finish_big_uint_raw(big_uint.data.handle.clone());
FA::finish_api_impl().finish_big_uint_raw(big_uint.value.handle.clone());
Ok(())
} else if let Some(big_int) = value.try_cast_ref::<BigInt<FA>>() {
FA::finish_api_impl().finish_big_int_raw(big_int.handle.clone());
Expand Down
2 changes: 1 addition & 1 deletion framework/base/src/types/managed/basic/big_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<M: ManagedTypeApi> BigFloat<M> {
pub fn from_big_uint(big_uint: &BigUint<M>) -> Self {
let new_bf_handle: M::BigFloatHandle =
use_raw_handle(M::static_var_api_impl().next_handle());
M::managed_type_impl().bf_set_bi(new_bf_handle.clone(), big_uint.data.handle.clone());
M::managed_type_impl().bf_set_bi(new_bf_handle.clone(), big_uint.value.handle.clone());
BigFloat::from_handle(new_bf_handle)
}

Expand Down
4 changes: 2 additions & 2 deletions framework/base/src/types/managed/basic/big_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ impl<M: ManagedTypeApi> BigInt<M> {
pub fn from_biguint(sign: Sign, unsigned: BigUint<M>) -> Self {
let api = M::managed_type_impl();
if sign.is_minus() {
api.bi_neg(unsigned.data.handle.clone(), unsigned.data.handle.clone());
api.bi_neg(unsigned.value.handle.clone(), unsigned.value.handle.clone());
}
BigInt::from_handle(unsigned.data.handle)
BigInt::from_handle(unsigned.value.handle)
}

/// Returns the sign of the `BigInt` as a `Sign`.
Expand Down
42 changes: 23 additions & 19 deletions framework/base/src/types/managed/basic/elliptic_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ impl<M: ManagedTypeApi> EllipticCurve<M> {
x_result_handle.clone(),
y_result_handle.clone(),
self.handle.clone(),
x_first_point.data.handle,
y_first_point.data.handle,
x_second_point.data.handle,
y_second_point.data.handle,
x_first_point.value.handle,
y_first_point.value.handle,
x_second_point.value.handle,
y_second_point.value.handle,
);
(
BigUint::from_handle(x_result_handle),
Expand All @@ -137,8 +137,8 @@ impl<M: ManagedTypeApi> EllipticCurve<M> {
x_result_handle.clone(),
y_result_handle.clone(),
self.handle.clone(),
x_point.data.handle,
y_point.data.handle,
x_point.value.handle,
y_point.value.handle,
);
(
BigUint::from_handle(x_result_handle),
Expand All @@ -150,8 +150,8 @@ impl<M: ManagedTypeApi> EllipticCurve<M> {
let api = M::managed_type_impl();
api.ec_is_on_curve(
self.handle.clone(),
x_point.data.handle,
y_point.data.handle,
x_point.value.handle,
y_point.value.handle,
)
}

Expand All @@ -169,8 +169,8 @@ impl<M: ManagedTypeApi> EllipticCurve<M> {
x_result_handle.clone(),
y_result_handle.clone(),
self.handle.clone(),
x_point.data.handle,
y_point.data.handle,
x_point.value.handle,
y_point.value.handle,
data,
);
(
Expand All @@ -192,8 +192,8 @@ impl<M: ManagedTypeApi> EllipticCurve<M> {
x_result_handle.clone(),
y_result_handle.clone(),
self.handle.clone(),
x_point.data.handle,
y_point.data.handle,
x_point.value.handle,
y_point.value.handle,
data.get_handle(),
);
(
Expand Down Expand Up @@ -246,16 +246,20 @@ impl<M: ManagedTypeApi> EllipticCurve<M> {
y_pair: BigUint<M>,
) -> crate::types::heap::BoxedBytes {
let api = M::managed_type_impl();
api.ec_marshal_legacy(self.handle.clone(), x_pair.data.handle, y_pair.data.handle)
api.ec_marshal_legacy(
self.handle.clone(),
x_pair.value.handle,
y_pair.value.handle,
)
}

pub fn marshal(&self, x_pair: BigUint<M>, y_pair: BigUint<M>) -> ManagedBuffer<M> {
let result_handle: M::ManagedBufferHandle =
use_raw_handle(M::static_var_api_impl().next_handle());
M::managed_type_impl().ec_marshal(
self.handle.clone(),
x_pair.data.handle,
y_pair.data.handle,
x_pair.value.handle,
y_pair.value.handle,
result_handle.clone(),
);
ManagedBuffer::from_handle(result_handle)
Expand All @@ -274,8 +278,8 @@ impl<M: ManagedTypeApi> EllipticCurve<M> {
let api = M::managed_type_impl();
api.ec_marshal_compressed_legacy(
self.handle.clone(),
x_pair.data.handle,
y_pair.data.handle,
x_pair.value.handle,
y_pair.value.handle,
)
}

Expand All @@ -284,8 +288,8 @@ impl<M: ManagedTypeApi> EllipticCurve<M> {
use_raw_handle(M::static_var_api_impl().next_handle());
M::managed_type_impl().ec_marshal_compressed(
self.handle.clone(),
x_pair.data.handle,
y_pair.data.handle,
x_pair.value.handle,
y_pair.value.handle,
result_handle.clone(),
);
ManagedBuffer::from_handle(result_handle)
Expand Down
26 changes: 13 additions & 13 deletions framework/base/src/types/managed/wrapped/big_uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ use crate::{

#[repr(transparent)]
pub struct BigUint<M: ManagedTypeApi> {
pub(crate) data: BigInt<M>,
pub(crate) value: BigInt<M>,
}

impl<M: ManagedTypeApi> ManagedType<M> for BigUint<M> {
type OwnHandle = M::BigIntHandle;

fn from_handle(handle: M::BigIntHandle) -> Self {
BigUint {
data: BigInt::from_handle(handle),
value: BigInt::from_handle(handle),
}
}

fn get_handle(&self) -> M::BigIntHandle {
self.data.handle.clone()
self.value.handle.clone()
}

fn transmute_from_handle_ref(handle_ref: &M::BigIntHandle) -> &Self {
Expand Down Expand Up @@ -175,12 +175,12 @@ impl<M: ManagedTypeApi> BigUint<M> {
#[inline]
pub fn to_u64(&self) -> Option<u64> {
let api = M::managed_type_impl();
api.bi_to_i64(self.data.handle.clone()).map(|bi| bi as u64)
api.bi_to_i64(self.value.handle.clone()).map(|bi| bi as u64)
}

#[inline]
pub fn overwrite_u64(&mut self, value: u64) {
Self::set_value(self.data.handle.clone(), value);
Self::set_value(self.value.handle.clone(), value);
}

#[inline]
Expand All @@ -196,7 +196,7 @@ impl<M: ManagedTypeApi> BigUint<M> {
pub fn to_bytes_be(&self) -> BoxedBytes {
let mb_handle: M::ManagedBufferHandle = use_raw_handle(const_handles::MBUF_TEMPORARY_1);
M::managed_type_impl()
.mb_from_big_int_unsigned(self.data.handle.clone(), mb_handle.clone());
.mb_from_big_int_unsigned(self.value.handle.clone(), mb_handle.clone());
M::managed_type_impl().mb_to_boxed_bytes(mb_handle)
}

Expand All @@ -213,7 +213,7 @@ impl<M: ManagedTypeApi> BigUint<M> {
let mb_handle: M::ManagedBufferHandle =
use_raw_handle(M::static_var_api_impl().next_handle());
M::managed_type_impl()
.mb_from_big_int_unsigned(self.data.handle.clone(), mb_handle.clone());
.mb_from_big_int_unsigned(self.value.handle.clone(), mb_handle.clone());
ManagedBuffer::from_handle(mb_handle)
}
}
Expand All @@ -224,7 +224,7 @@ impl<M: ManagedTypeApi> BigUint<M> {
pub fn sqrt(&self) -> Self {
let api = M::managed_type_impl();
let result_handle: M::BigIntHandle = use_raw_handle(M::static_var_api_impl().next_handle());
api.bi_sqrt(result_handle.clone(), self.data.handle.clone());
api.bi_sqrt(result_handle.clone(), self.value.handle.clone());
BigUint::from_handle(result_handle)
}

Expand All @@ -234,7 +234,7 @@ impl<M: ManagedTypeApi> BigUint<M> {
let big_int_temp_1 = BigUint::<M>::make_temp(const_handles::BIG_INT_TEMPORARY_1, exp);
M::managed_type_impl().bi_pow(
result_handle.clone(),
self.data.handle.clone(),
self.value.handle.clone(),
big_int_temp_1,
);
BigUint::from_handle(result_handle)
Expand All @@ -243,7 +243,7 @@ impl<M: ManagedTypeApi> BigUint<M> {
#[inline]
pub fn log2(&self) -> u32 {
let api = M::managed_type_impl();
api.bi_log2(self.data.handle.clone())
api.bi_log2(self.value.handle.clone())
}

/// Natural logarithm of a number.
Expand Down Expand Up @@ -305,7 +305,7 @@ impl<M: ManagedTypeApi> Clone for BigUint<M> {
api.bi_add(
clone_handle.clone(),
clone_handle.clone(),
self.data.handle.clone(),
self.value.handle.clone(),
);
BigUint::from_handle(clone_handle)
}
Expand Down Expand Up @@ -372,7 +372,7 @@ impl<M: ManagedTypeApi> TopDecode for BigUint<M> {
impl<M: ManagedTypeApi> SCDisplay for BigUint<M> {
fn fmt<F: FormatByteReceiver>(&self, f: &mut F) {
let str_handle: M::ManagedBufferHandle = use_raw_handle(const_handles::MBUF_TEMPORARY_1);
M::managed_type_impl().bi_to_string(self.data.handle.clone(), str_handle.clone());
M::managed_type_impl().bi_to_string(self.value.handle.clone(), str_handle.clone());
f.append_managed_buffer(&ManagedBuffer::from_handle(
str_handle.cast_or_signal_error::<M, _>(),
));
Expand All @@ -391,7 +391,7 @@ impl<M: ManagedTypeApi> BigUint<M> {
impl<M: ManagedTypeApi> core::fmt::Debug for BigUint<M> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("BigUint")
.field("handle", &self.data.handle.clone())
.field("handle", &self.value.handle.clone())
.field(
"hex-value-be",
&encode_bytes_as_hex(self.to_bytes_be().as_slice()),
Expand Down
8 changes: 4 additions & 4 deletions framework/base/src/types/managed/wrapped/big_uint_cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ impl<M: ManagedTypeApi> PartialEq for BigUint<M> {
#[inline]
fn eq(&self, other: &Self) -> bool {
M::managed_type_impl()
.bi_cmp(self.data.handle.clone(), other.data.handle.clone())
.bi_cmp(self.value.handle.clone(), other.value.handle.clone())
.is_eq()
}
}
Expand All @@ -27,7 +27,7 @@ impl<M: ManagedTypeApi> PartialOrd for BigUint<M> {
impl<M: ManagedTypeApi> Ord for BigUint<M> {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
M::managed_type_impl().bi_cmp(self.data.handle.clone(), other.data.handle.clone())
M::managed_type_impl().bi_cmp(self.value.handle.clone(), other.value.handle.clone())
}
}

Expand All @@ -36,14 +36,14 @@ macro_rules! partial_eq_and_ord {
impl<M: ManagedTypeApi> PartialEq<$small_int_type> for BigUint<M> {
#[inline]
fn eq(&self, other: &$small_int_type) -> bool {
self.data.eq(&cast_to_i64::<M, _>(*other))
self.value.eq(&cast_to_i64::<M, _>(*other))
}
}

impl<M: ManagedTypeApi> PartialOrd<$small_int_type> for BigUint<M> {
#[inline]
fn partial_cmp(&self, other: &$small_int_type) -> Option<Ordering> {
self.data.partial_cmp(&cast_to_i64::<M, _>(*other))
self.value.partial_cmp(&cast_to_i64::<M, _>(*other))
}
}
};
Expand Down
Loading

0 comments on commit cbebcb1

Please sign in to comment.