-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
track with main | use bits_to_target fn
- Loading branch information
Showing
8 changed files
with
414 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
* @b-j-roberts @m-kus @maciejka | ||
* @m-kus @maciejka |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod utils; | ||
pub mod validation; | ||
|
||
mod state; | ||
mod validation; | ||
mod main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use core::traits::Into; | ||
use core::traits::TryInto; | ||
|
||
// Bitwise shift left for u256 | ||
pub fn shl(value: u256, shift: u32) -> u256 { | ||
value * fast_pow(2.into(), shift.into()) | ||
} | ||
|
||
// Bitwise shift right for u256 | ||
pub fn shr(value: u256, shift: u32) -> u256 { | ||
value / fast_pow(2.into(), shift.into()) | ||
} | ||
|
||
// Fast exponentiation using the square-and-multiply algorithm | ||
// Reference: | ||
// https://github.com/keep-starknet-strange/alexandria/blob/bcdca70afdf59c9976148e95cebad5cf63d75a7f/packages/math/src/fast_power.cairo#L12 | ||
pub fn fast_pow(base: u256, exp: u32) -> u256 { | ||
if exp == 0 { | ||
return 1_u256; | ||
} | ||
|
||
let mut res: u256 = 1_u256; | ||
let mut base: u256 = base; | ||
let mut exp: u32 = exp; | ||
|
||
loop { | ||
if exp % 2 == 1 { | ||
res = res * base; | ||
} | ||
exp = exp / 2; | ||
if exp == 0 { | ||
break res; | ||
} | ||
base = base * base; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.