Browse Source

fix nits

al-gkr-basic-workflow
Al-Kindi-0 2 years ago
parent
commit
17f13dbe9f
5 changed files with 48 additions and 31 deletions
  1. +11
    -3
      crypto/Cargo.toml
  2. +31
    -0
      crypto/src/hash/mod.rs
  3. +3
    -2
      crypto/src/merkle/merkle_path_set.rs
  4. +2
    -5
      crypto/src/merkle/merkle_tree.rs
  5. +1
    -21
      crypto/src/merkle/mod.rs

+ 11
- 3
crypto/Cargo.toml

@ -1,12 +1,20 @@
[package] [package]
name = "crypto" name = "crypto"
version = "0.1.0" version = "0.1.0"
description="Miden Cryptographic primitives"
authors = ["miden contributors"]
readme="README.md"
license = "MIT"
repository = "https://github.com/0xPolygonMiden/crypto"
categories = ["cryptography", "no-std"]
keywords = ["miden", "crypto", "hash", "merkle"]
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
winterfell = { git = "https://github.com/novifinancial/winterfell"} winterfell = { git = "https://github.com/novifinancial/winterfell"}
winter_utils = { version = "0.4", package = "winter-utils" } winter_utils = { version = "0.4", package = "winter-utils" }
rand_utils = { version = "0.4", package = "winter-rand-utils" } rand_utils = { version = "0.4", package = "winter-rand-utils" }
proptest = "1.0.0"
[dev-dependencies]
proptest = "1.0.0"

+ 31
- 0
crypto/src/hash/mod.rs

@ -1 +1,32 @@
use winterfell::crypto::{ElementHasher};
use winterfell::math::StarkField;
use winterfell::crypto::Hasher as HashFn;
use winterfell::crypto::hashers::Rp64_256 as Hasher;
mod rpo;
pub use rpo::Rpo;
// TYPE ALIASES
// ================================================================================================
pub type Digest = <Hasher as HashFn>::Digest;
// HELPER FUNCTIONS
// ================================================================================================
#[inline(always)]
fn exp_acc<B: StarkField, const N: usize, const M: usize>(base: [B; N], tail: [B; N]) -> [B; N] {
let mut result = base;
for _ in 0..M {
result.iter_mut().for_each(|r| *r = r.square());
}
result.iter_mut().zip(tail).for_each(|(r, t)| *r *= t);
result
}
#[inline(always)]
pub fn merge(values: &[Digest; 2]) -> Digest {
Hasher::merge(values)
}

+ 3
- 2
crypto/src/merkle/merkle_path_set.rs

@ -1,6 +1,7 @@
use std::collections::BTreeMap;
use winter_utils::collections::BTreeMap;
use super::{merge, Felt, FieldElement, MerkleError, Word};
use super::{Felt, FieldElement, MerkleError, Word};
use crate::hash::merge;
// MERKLE PATH SET // MERKLE PATH SET
// ================================================================================================ // ================================================================================================

+ 2
- 5
crypto/src/merkle/merkle_tree.rs

@ -1,12 +1,9 @@
use core::slice; use core::slice;
use super::Digest;
use winter_utils::uninit_vector; use winter_utils::uninit_vector;
use winterfell::math::log2; use winterfell::math::log2;
use crate::{Felt, FieldElement, Word};
use super::{merge, MerkleError};
use crate::{Felt, FieldElement, Word, hash::{merge,Digest}};
use super::MerkleError;
// MERKLE TREE // MERKLE TREE
// ================================================================================================ // ================================================================================================

+ 1
- 21
crypto/src/merkle/mod.rs

@ -1,28 +1,8 @@
pub mod merkle_path_set; pub mod merkle_path_set;
pub mod merkle_tree; pub mod merkle_tree;
use winterfell::crypto::Hasher as HashFn;
use crate::{Felt, FieldElement, Word};
pub use winterfell::crypto::hashers::Rp64_256 as Hasher;
pub use winterfell::math::{
fields::{f64::BaseElement as Felt, QuadExtension},
ExtensionOf, FieldElement, StarkField,
};
// TYPE ALIASES
// ================================================================================================
pub type Word = [Felt; 4];
pub type Digest = <Hasher as HashFn>::Digest;
// PASS-THROUGH FUNCTIONS
// ================================================================================================
/// Returns a hash of two digests. This method is intended for use in construction of Merkle trees.
#[inline(always)]
pub fn merge(values: &[Digest; 2]) -> Digest {
Hasher::merge(values)
}
// ERRORS // ERRORS
// ================================================================================================ // ================================================================================================

Loading…
Cancel
Save