-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
85 additions
and
85 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
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,63 @@ | ||
use cairo_verifier::common::flip_endiannes::FlipEndiannessU32; | ||
|
||
// 2^8 = 256 | ||
const U128maxU8: u128 = 256; | ||
const U64maxU8: u64 = 256; | ||
const U32maxU8: u32 = 256; | ||
const U16maxU8: u16 = 256; | ||
|
||
// 2^16 = 65536 | ||
const U128maxU16: u128 = 65536; | ||
const U64maxU16: u64 = 65536; | ||
const U32maxU16: u32 = 65536; | ||
|
||
// 2^32 = 4294967296 | ||
const U128maxU32: u128 = 4294967296; | ||
const U64maxU32: u64 = 4294967296; | ||
|
||
trait ArrayAppendTrait<ArrayElement, AppendElement> { | ||
fn append_little_endian(ref self: Array<ArrayElement>, element: AppendElement); | ||
fn append_big_endian(ref self: Array<ArrayElement>, element: AppendElement); | ||
} | ||
|
||
impl ArrayU32AppendU256 of ArrayAppendTrait<u32, u256> { | ||
fn append_little_endian(ref self: Array<u32>, element: u256) { | ||
self.append_little_endian(element.low); | ||
self.append_little_endian(element.high); | ||
} | ||
|
||
fn append_big_endian(ref self: Array<u32>, element: u256) { | ||
self.append_big_endian(element.high); | ||
self.append_big_endian(element.low); | ||
} | ||
} | ||
|
||
impl ArrayU32AppendU128 of ArrayAppendTrait<u32, u128> { | ||
fn append_little_endian(ref self: Array<u32>, mut element: u128) { | ||
let mut i = 4; | ||
loop { | ||
if i != 0 { | ||
i -= 1; | ||
let (q, r) = DivRem::div_rem(element, U128maxU32.try_into().unwrap()); | ||
self.append(r.try_into().unwrap()); | ||
element = q; | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
fn append_big_endian(ref self: Array<u32>, mut element: u128) { | ||
let mut array = ArrayTrait::<u32>::new(); | ||
array.append_little_endian(element); | ||
let mut i = array.len(); | ||
loop { | ||
if i != 0 { | ||
i -= 1; | ||
self.append((*array.at(i)).flip_endiannes()); | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
} |
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
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 was deleted.
Oops, something went wrong.