refactor: refactor crypto APIs to use RpoDigest instead of Word

This commit is contained in:
tohrnii
2023-06-09 21:18:13 +01:00
parent 59f7723221
commit fe9aa8c28c
16 changed files with 590 additions and 376 deletions

View File

@@ -10,7 +10,6 @@ use core::fmt;
mod empty_roots;
pub use empty_roots::EmptySubtreeRoots;
use empty_roots::EMPTY_WORD;
mod index;
pub use index::NodeIndex;
@@ -44,7 +43,7 @@ pub use node::InnerNodeInfo;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum MerkleError {
ConflictingRoots(Vec<Word>),
ConflictingRoots(Vec<RpoDigest>),
DepthTooSmall(u8),
DepthTooBig(u64),
DuplicateValuesForIndex(u64),
@@ -54,9 +53,9 @@ pub enum MerkleError {
InvalidPath(MerklePath),
InvalidNumEntries(usize, usize),
NodeNotInSet(NodeIndex),
NodeNotInStore(Word, NodeIndex),
NodeNotInStore(RpoDigest, NodeIndex),
NumLeavesNotPowerOfTwo(usize),
RootNotInStore(Word),
RootNotInStore(RpoDigest),
}
impl fmt::Display for MerkleError {
@@ -95,6 +94,11 @@ impl std::error::Error for MerkleError {}
// ================================================================================================
#[cfg(test)]
const fn int_to_node(value: u64) -> Word {
const fn int_to_node(value: u64) -> RpoDigest {
RpoDigest::new([Felt::new(value), ZERO, ZERO, ZERO])
}
#[cfg(test)]
const fn int_to_leaf(value: u64) -> Word {
[Felt::new(value), ZERO, ZERO, ZERO]
}