Skip to content
Open
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
158 changes: 147 additions & 11 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2021"
ethereum-types = "0.13.1"
num-traits = "0.2.15"
paste = "1.0.7"
zkp-u256 = "0.2.1"

[profile.production]
incremental = false
Expand Down
25 changes: 21 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn fib<N: Number>(times: u32) -> N {

for _ in 0..times {
buffer = last;
last = current;
last = current.clone();
current = current.overflowing_add(buffer);
}

Expand All @@ -21,8 +21,8 @@ fn three_n_one<N: Number>(start: u32) -> N {
let mut current = N::from(start);

while current != N::from(1) {
if current % N::from(2) == N::from(0) {
current = current / N::from(2);
if current.clone() % N::from(2) == N::from(0) {
current = current.clone() / N::from(2);
} else {
current = current * N::from(3) + N::from(1);
}
Expand All @@ -32,7 +32,7 @@ fn three_n_one<N: Number>(start: u32) -> N {
}

trait Number:
Copy
Clone
+ PartialEq
+ std::ops::Div<Output = Self>
+ std::ops::Mul<Output = Self>
Expand Down Expand Up @@ -72,6 +72,15 @@ macro_rules! impl_num_eth {
};
}

impl Number for zkp_u256::U256 {
fn overflowing_add(self, rhs: Self) -> Self {
self + rhs
}
fn from(f: u32) -> Self {
<Self as From<u32>>::from(f)
}
}

impl_num_eth!(ethereum_types::U64);
impl_num_eth!(ethereum_types::U128);
impl_num_eth!(ethereum_types::U256);
Expand Down Expand Up @@ -125,6 +134,10 @@ mod fib {
impl_fib!(u128);
impl_fib!(u256);
}
mod zkp {
use zkp_u256::U256 as u256;
impl_fib!(u256);
}
}

#[cfg(test)]
Expand All @@ -146,4 +159,8 @@ mod three_n_one {
impl_three_n_one!(u128);
impl_three_n_one!(u256);
}
mod zkp {
use zkp_u256::U256 as u256;
impl_three_n_one!(u256);
}
}