-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: separate OffsetToBytes trait from transpose module (PROOF-8…
…97) (#95) # Rationale for this change In an effort to support Blitzar's new `packed_msm` interface, we need to make a number of updates to the Dory commitment computation. A future PR will require the use of the `OffsetToBytes` trait. This PR separates the trait into a different file to make future usage easier. # What changes are included in this PR? - The `OffsetToBytes` trait is moved to its own file. # Are these changes tested? Yes.
- Loading branch information
1 parent
17b57a4
commit 5a554dd
Showing
4 changed files
with
118 additions
and
114 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
110 changes: 110 additions & 0 deletions
110
crates/proof-of-sql/src/proof_primitive/dory/offset_to_bytes.rs
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,110 @@ | ||
use super::F; | ||
use zerocopy::AsBytes; | ||
|
||
pub trait OffsetToBytes { | ||
const IS_SIGNED: bool; | ||
fn min_as_fr() -> F; | ||
fn offset_to_bytes(&self) -> Vec<u8>; | ||
} | ||
|
||
impl OffsetToBytes for u8 { | ||
const IS_SIGNED: bool = false; | ||
|
||
fn min_as_fr() -> F { | ||
F::from(0) | ||
} | ||
|
||
fn offset_to_bytes(&self) -> Vec<u8> { | ||
vec![*self] | ||
} | ||
} | ||
|
||
impl OffsetToBytes for i16 { | ||
const IS_SIGNED: bool = true; | ||
|
||
fn min_as_fr() -> F { | ||
F::from(i16::MIN) | ||
} | ||
|
||
fn offset_to_bytes(&self) -> Vec<u8> { | ||
let shifted = self.wrapping_sub(i16::MIN); | ||
shifted.to_le_bytes().to_vec() | ||
} | ||
} | ||
|
||
impl OffsetToBytes for i32 { | ||
const IS_SIGNED: bool = true; | ||
|
||
fn min_as_fr() -> F { | ||
F::from(i32::MIN) | ||
} | ||
|
||
fn offset_to_bytes(&self) -> Vec<u8> { | ||
let shifted = self.wrapping_sub(i32::MIN); | ||
shifted.to_le_bytes().to_vec() | ||
} | ||
} | ||
|
||
impl OffsetToBytes for i64 { | ||
const IS_SIGNED: bool = true; | ||
|
||
fn min_as_fr() -> F { | ||
F::from(i64::MIN) | ||
} | ||
|
||
fn offset_to_bytes(&self) -> Vec<u8> { | ||
let shifted = self.wrapping_sub(i64::MIN); | ||
shifted.to_le_bytes().to_vec() | ||
} | ||
} | ||
|
||
impl OffsetToBytes for i128 { | ||
const IS_SIGNED: bool = true; | ||
|
||
fn min_as_fr() -> F { | ||
F::from(i128::MIN) | ||
} | ||
|
||
fn offset_to_bytes(&self) -> Vec<u8> { | ||
let shifted = self.wrapping_sub(i128::MIN); | ||
shifted.to_le_bytes().to_vec() | ||
} | ||
} | ||
|
||
impl OffsetToBytes for bool { | ||
const IS_SIGNED: bool = false; | ||
|
||
fn min_as_fr() -> F { | ||
F::from(false) | ||
} | ||
|
||
fn offset_to_bytes(&self) -> Vec<u8> { | ||
vec![*self as u8] | ||
} | ||
} | ||
|
||
impl OffsetToBytes for u64 { | ||
const IS_SIGNED: bool = false; | ||
|
||
fn min_as_fr() -> F { | ||
F::from(0) | ||
} | ||
|
||
fn offset_to_bytes(&self) -> Vec<u8> { | ||
let bytes = self.to_le_bytes(); | ||
bytes.to_vec() | ||
} | ||
} | ||
|
||
impl OffsetToBytes for [u64; 4] { | ||
const IS_SIGNED: bool = false; | ||
|
||
fn min_as_fr() -> F { | ||
F::from(0) | ||
} | ||
|
||
fn offset_to_bytes(&self) -> Vec<u8> { | ||
let slice = self.as_bytes(); | ||
slice.to_vec() | ||
} | ||
} |
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