mirror of
https://github.com/arnaucube/miden-crypto.git
synced 2026-01-12 09:01:29 +01:00
Compare commits
4 Commits
v0.8.0
...
km/mkdocs-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03639148d7 | ||
|
|
d8cf98a0b5 | ||
|
|
4bc4bea0db | ||
|
|
dbab0e9aa9 |
12
.gitignore
vendored
12
.gitignore
vendored
@@ -14,3 +14,15 @@ cmake-build-*
|
|||||||
|
|
||||||
# VS Code
|
# VS Code
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
|
# Docs ignore
|
||||||
|
.code
|
||||||
|
.idea
|
||||||
|
site/
|
||||||
|
venv/
|
||||||
|
env/
|
||||||
|
*.out
|
||||||
|
node_modules/
|
||||||
|
*DS_Store
|
||||||
|
*.iml
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
## 0.8.1 (2024-02-21)
|
||||||
|
* Fixed clippy warnings (#280)
|
||||||
|
|
||||||
## 0.8.0 (2024-02-14)
|
## 0.8.0 (2024-02-14)
|
||||||
|
|
||||||
* Implemented the `PartialMmr` data structure (#195).
|
* Implemented the `PartialMmr` data structure (#195).
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "miden-crypto"
|
name = "miden-crypto"
|
||||||
version = "0.8.0"
|
version = "0.8.1"
|
||||||
description = "Miden Cryptographic primitives"
|
description = "Miden Cryptographic primitives"
|
||||||
authors = ["miden contributors"]
|
authors = ["miden contributors"]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/0xPolygonMiden/crypto"
|
repository = "https://github.com/0xPolygonMiden/crypto"
|
||||||
documentation = "https://docs.rs/miden-crypto/0.8.0"
|
documentation = "https://docs.rs/miden-crypto/0.8.1"
|
||||||
categories = ["cryptography", "no-std"]
|
categories = ["cryptography", "no-std"]
|
||||||
keywords = ["miden", "crypto", "hash", "merkle"]
|
keywords = ["miden", "crypto", "hash", "merkle"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use core::mem::swap;
|
use core::mem::swap;
|
||||||
|
|
||||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||||
use miden_crypto::{
|
use miden_crypto::{
|
||||||
merkle::{LeafIndex, SimpleSmt},
|
merkle::{LeafIndex, SimpleSmt},
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
use criterion::{black_box, criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
|
use criterion::{black_box, criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
|
||||||
use miden_crypto::merkle::{
|
use miden_crypto::{
|
||||||
DefaultMerkleStore as MerkleStore, LeafIndex, MerkleTree, NodeIndex, SimpleSmt, SMT_MAX_DEPTH,
|
hash::rpo::RpoDigest,
|
||||||
|
merkle::{
|
||||||
|
DefaultMerkleStore as MerkleStore, LeafIndex, MerkleTree, NodeIndex, SimpleSmt,
|
||||||
|
SMT_MAX_DEPTH,
|
||||||
|
},
|
||||||
|
Felt, Word,
|
||||||
};
|
};
|
||||||
use miden_crypto::Word;
|
|
||||||
use miden_crypto::{hash::rpo::RpoDigest, Felt};
|
|
||||||
use rand_utils::{rand_array, rand_value};
|
use rand_utils::{rand_array, rand_value};
|
||||||
|
|
||||||
/// Since MerkleTree can only be created when a power-of-two number of elements is used, the sample
|
/// Since MerkleTree can only be created when a power-of-two number of elements is used, the sample
|
||||||
|
|||||||
36
docs/README.md
Normal file
36
docs/README.md
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# Miden base documentation
|
||||||
|
|
||||||
|
Welcome to the Miden client repo docs.
|
||||||
|
|
||||||
|
## Running locally
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
1. [Python 3.12](https://www.python.org/downloads/).
|
||||||
|
2. [`virtualenv`](https://pypi.org/project/virtualenv/): Install using `pip3 install virtualenv`.
|
||||||
|
|
||||||
|
### Setup
|
||||||
|
|
||||||
|
1. Clone the repository.
|
||||||
|
2. `cd` to the root.
|
||||||
|
3. Run the `run.sh` script. You may need to make the script executable: `chmod +x run.sh`
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./run.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
The site comes up at http://127.0.0.1:8000/
|
||||||
|
|
||||||
|
## Style guide
|
||||||
|
|
||||||
|
We are using the [Microsoft Style Guide](https://learn.microsoft.com/en-us/style-guide/welcome/).
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
1. Fork the `main` branch into your own GitHub account and create a feature branch for your changes.
|
||||||
|
2. Commit changes and create a PR.
|
||||||
|
|
||||||
|
## Contact
|
||||||
|
|
||||||
|
- For docs issues (technical or language) open an issue here.
|
||||||
|
- For anything else, join our [Discord](https://discord.gg/0xpolygondevs).
|
||||||
1
docs/digital-signatures.md
Normal file
1
docs/digital-signatures.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
WIP
|
||||||
1
docs/hash-functions.md
Normal file
1
docs/hash-functions.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
WIP
|
||||||
1
docs/merkle-structures.md
Normal file
1
docs/merkle-structures.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
WIP
|
||||||
1
docs/welcome.md
Normal file
1
docs/welcome.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
WIP
|
||||||
79
mkdocs.yml
Normal file
79
mkdocs.yml
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
site_name: Miden client
|
||||||
|
theme:
|
||||||
|
name: material
|
||||||
|
features:
|
||||||
|
- search.suggest
|
||||||
|
- search.highlight
|
||||||
|
- search.share
|
||||||
|
# - navigation.instant
|
||||||
|
- navigation.instant.progress
|
||||||
|
- navigation.tracking
|
||||||
|
- navigation.integration
|
||||||
|
#- navigation.tabs
|
||||||
|
#- navigation.tabs.sticky
|
||||||
|
- navigation.indexes
|
||||||
|
#- navigation.sections
|
||||||
|
- navigation.path
|
||||||
|
- navigation.top
|
||||||
|
- navigation.footer
|
||||||
|
- toc.follow
|
||||||
|
- content.code.copy
|
||||||
|
- content.action.edit
|
||||||
|
|
||||||
|
|
||||||
|
nav:
|
||||||
|
- Welcome: welcome.md
|
||||||
|
- Hash functions: hash-functions.md
|
||||||
|
- Merkle structures: merkle-structures.md
|
||||||
|
- Digital signatures: digital-signatures.md
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
markdown_extensions:
|
||||||
|
- toc:
|
||||||
|
permalink: true
|
||||||
|
permalink_title: Link to this section
|
||||||
|
toc_depth: 4
|
||||||
|
- codehilite
|
||||||
|
- markdown_include.include:
|
||||||
|
base_path: src
|
||||||
|
- admonition
|
||||||
|
- footnotes
|
||||||
|
- def_list
|
||||||
|
- attr_list
|
||||||
|
- abbr
|
||||||
|
- pymdownx.tabbed
|
||||||
|
- pymdownx.superfences
|
||||||
|
- pymdownx.arithmatex:
|
||||||
|
generic: true
|
||||||
|
- pymdownx.betterem:
|
||||||
|
smart_enable: all
|
||||||
|
- pymdownx.keys
|
||||||
|
- pymdownx.details
|
||||||
|
- pymdownx.magiclink
|
||||||
|
- pymdownx.mark
|
||||||
|
- pymdownx.smartsymbols
|
||||||
|
- pymdownx.tasklist:
|
||||||
|
custom_checkbox: true
|
||||||
|
- pymdownx.tilde
|
||||||
|
- pymdownx.caret
|
||||||
|
- meta
|
||||||
|
- smarty
|
||||||
|
- pymdownx.extra
|
||||||
|
|
||||||
|
plugins:
|
||||||
|
- search
|
||||||
|
- open-in-new-tab
|
||||||
|
|
||||||
|
validation:
|
||||||
|
absolute_links: warn
|
||||||
|
|
||||||
|
extra_javascript:
|
||||||
|
- https://polyfill.io/v3/polyfill.min.js?features=es6
|
||||||
|
- https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js
|
||||||
|
- https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/katex.min.js
|
||||||
|
- https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/contrib/auto-render.min.js
|
||||||
|
|
||||||
|
extra_css:
|
||||||
|
- https://fonts.googleapis.com/icon?family=Material+Icons
|
||||||
|
- https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/katex.min.css
|
||||||
3
requirements.txt
Executable file
3
requirements.txt
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
mkdocs-material==9.4.8
|
||||||
|
markdown-include==0.8.1
|
||||||
|
mkdocs-open-in-new-tab==1.0.3
|
||||||
7
run-docs-site.sh
Executable file
7
run-docs-site.sh
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
virtualenv venv
|
||||||
|
source venv/bin/activate
|
||||||
|
pip3 install -r requirements.txt
|
||||||
|
mkdocs serve --strict
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
use super::{LOG_N, MODULUS, PK_LEN};
|
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
|
||||||
|
use super::{LOG_N, MODULUS, PK_LEN};
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum FalconError {
|
pub enum FalconError {
|
||||||
KeyGenerationFailed,
|
KeyGenerationFailed,
|
||||||
|
|||||||
@@ -96,9 +96,10 @@ pub struct Rpo128Context {
|
|||||||
|
|
||||||
#[cfg(all(test, feature = "std"))]
|
#[cfg(all(test, feature = "std"))]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use rand_utils::{rand_array, rand_value, rand_vector};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::dsa::rpo_falcon512::{NONCE_LEN, PK_LEN, SIG_LEN, SK_LEN};
|
use crate::dsa::rpo_falcon512::{NONCE_LEN, PK_LEN, SIG_LEN, SK_LEN};
|
||||||
use rand_utils::{rand_array, rand_value, rand_vector};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn falcon_ffi() {
|
fn falcon_ffi() {
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
|
#[cfg(feature = "std")]
|
||||||
|
use super::{ffi, NonceBytes, NONCE_LEN, PK_LEN, SIG_LEN, SK_LEN};
|
||||||
use super::{
|
use super::{
|
||||||
ByteReader, ByteWriter, Deserializable, DeserializationError, FalconError, Polynomial,
|
ByteReader, ByteWriter, Deserializable, DeserializationError, FalconError, Polynomial,
|
||||||
PublicKeyBytes, Rpo256, SecretKeyBytes, Serializable, Signature, Word,
|
PublicKeyBytes, Rpo256, SecretKeyBytes, Serializable, Signature, Word,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
use super::{ffi, NonceBytes, NONCE_LEN, PK_LEN, SIG_LEN, SK_LEN};
|
|
||||||
|
|
||||||
// PUBLIC KEY
|
// PUBLIC KEY
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
|
|
||||||
@@ -182,9 +181,10 @@ impl Deserializable for KeyPair {
|
|||||||
|
|
||||||
#[cfg(all(test, feature = "std"))]
|
#[cfg(all(test, feature = "std"))]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{super::Felt, KeyPair, NonceBytes, Word};
|
|
||||||
use rand_utils::{rand_array, rand_vector};
|
use rand_utils::{rand_array, rand_vector};
|
||||||
|
|
||||||
|
use super::{super::Felt, KeyPair, NonceBytes, Word};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_falcon_verification() {
|
fn test_falcon_verification() {
|
||||||
// generate random keys
|
// generate random keys
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
hash::rpo::Rpo256,
|
hash::rpo::Rpo256,
|
||||||
utils::{
|
utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable},
|
||||||
collections::Vec, ByteReader, ByteWriter, Deserializable, DeserializationError,
|
|
||||||
Serializable,
|
|
||||||
},
|
|
||||||
Felt, Word, ZERO,
|
Felt, Word, ZERO,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
use super::{FalconError, Felt, Vec, LOG_N, MODULUS, MODULUS_MINUS_1_OVER_TWO, N, PK_LEN};
|
|
||||||
use core::ops::{Add, Mul, Sub};
|
use core::ops::{Add, Mul, Sub};
|
||||||
|
|
||||||
|
use super::{FalconError, Felt, LOG_N, MODULUS, MODULUS_MINUS_1_OVER_TWO, N, PK_LEN};
|
||||||
|
use crate::utils::collections::*;
|
||||||
|
|
||||||
// FALCON POLYNOMIAL
|
// FALCON POLYNOMIAL
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
|
use core::cell::OnceCell;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
ByteReader, ByteWriter, Deserializable, DeserializationError, Felt, NonceBytes, NonceElements,
|
ByteReader, ByteWriter, Deserializable, DeserializationError, Felt, NonceBytes, NonceElements,
|
||||||
Polynomial, PublicKeyBytes, Rpo256, Serializable, SignatureBytes, Word, MODULUS, N,
|
Polynomial, PublicKeyBytes, Rpo256, Serializable, SignatureBytes, Word, MODULUS, N,
|
||||||
SIG_L2_BOUND, ZERO,
|
SIG_L2_BOUND, ZERO,
|
||||||
};
|
};
|
||||||
use crate::utils::string::ToString;
|
use crate::utils::string::*;
|
||||||
use core::cell::OnceCell;
|
|
||||||
|
|
||||||
// FALCON SIGNATURE
|
// FALCON SIGNATURE
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
@@ -195,13 +196,14 @@ fn decode_nonce(nonce: &NonceBytes) -> NonceElements {
|
|||||||
|
|
||||||
#[cfg(all(test, feature = "std"))]
|
#[cfg(all(test, feature = "std"))]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{
|
|
||||||
super::{ffi::*, Felt, KeyPair},
|
|
||||||
*,
|
|
||||||
};
|
|
||||||
use libc::c_void;
|
use libc::c_void;
|
||||||
use rand_utils::rand_vector;
|
use rand_utils::rand_vector;
|
||||||
|
|
||||||
|
use super::{
|
||||||
|
super::{ffi::*, KeyPair},
|
||||||
|
*,
|
||||||
|
};
|
||||||
|
|
||||||
// Wrappers for unsafe functions
|
// Wrappers for unsafe functions
|
||||||
impl Rpo128Context {
|
impl Rpo128Context {
|
||||||
/// Initializes the RPO state.
|
/// Initializes the RPO state.
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
use super::{Digest, ElementHasher, Felt, FieldElement, Hasher};
|
|
||||||
use crate::utils::{
|
|
||||||
bytes_to_hex_string, hex_to_bytes, string::String, ByteReader, ByteWriter, Deserializable,
|
|
||||||
DeserializationError, HexParseError, Serializable,
|
|
||||||
};
|
|
||||||
use core::{
|
use core::{
|
||||||
mem::{size_of, transmute, transmute_copy},
|
mem::{size_of, transmute, transmute_copy},
|
||||||
ops::Deref,
|
ops::Deref,
|
||||||
slice::from_raw_parts,
|
slice::from_raw_parts,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use super::{Digest, ElementHasher, Felt, FieldElement, Hasher};
|
||||||
|
use crate::utils::{
|
||||||
|
bytes_to_hex_string, hex_to_bytes, string::*, ByteReader, ByteWriter, Deserializable,
|
||||||
|
DeserializationError, HexParseError, Serializable,
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
use super::*;
|
|
||||||
use crate::utils::collections::Vec;
|
|
||||||
use proptest::prelude::*;
|
use proptest::prelude::*;
|
||||||
use rand_utils::rand_vector;
|
use rand_utils::rand_vector;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
use crate::utils::collections::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn blake3_hash_elements() {
|
fn blake3_hash_elements() {
|
||||||
// test multiple of 8
|
// test multiple of 8
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#[cfg(target_feature = "sve")]
|
#[cfg(target_feature = "sve")]
|
||||||
pub mod optimized {
|
pub mod optimized {
|
||||||
use crate::hash::rescue::STATE_WIDTH;
|
use crate::{hash::rescue::STATE_WIDTH, Felt};
|
||||||
use crate::Felt;
|
|
||||||
|
|
||||||
mod ffi {
|
mod ffi {
|
||||||
#[link(name = "rpo_sve", kind = "static")]
|
#[link(name = "rpo_sve", kind = "static")]
|
||||||
@@ -50,8 +49,10 @@ mod x86_64_avx2;
|
|||||||
#[cfg(target_feature = "avx2")]
|
#[cfg(target_feature = "avx2")]
|
||||||
pub mod optimized {
|
pub mod optimized {
|
||||||
use super::x86_64_avx2::{apply_inv_sbox, apply_sbox};
|
use super::x86_64_avx2::{apply_inv_sbox, apply_sbox};
|
||||||
use crate::hash::rescue::{add_constants, STATE_WIDTH};
|
use crate::{
|
||||||
use crate::Felt;
|
hash::rescue::{add_constants, STATE_WIDTH},
|
||||||
|
Felt,
|
||||||
|
};
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn add_constants_and_apply_sbox(
|
pub fn add_constants_and_apply_sbox(
|
||||||
@@ -80,8 +81,7 @@ pub mod optimized {
|
|||||||
|
|
||||||
#[cfg(not(any(target_feature = "avx2", target_feature = "sve")))]
|
#[cfg(not(any(target_feature = "avx2", target_feature = "sve")))]
|
||||||
pub mod optimized {
|
pub mod optimized {
|
||||||
use crate::hash::rescue::STATE_WIDTH;
|
use crate::{hash::rescue::STATE_WIDTH, Felt};
|
||||||
use crate::Felt;
|
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn add_constants_and_apply_sbox(
|
pub fn add_constants_and_apply_sbox(
|
||||||
|
|||||||
@@ -157,9 +157,10 @@ const fn block3(x: [i64; 3], y: [i64; 3]) -> [i64; 3] {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::super::{apply_mds, Felt, MDS, ZERO};
|
|
||||||
use proptest::prelude::*;
|
use proptest::prelude::*;
|
||||||
|
|
||||||
|
use super::super::{apply_mds, Felt, MDS, ZERO};
|
||||||
|
|
||||||
const STATE_WIDTH: usize = 12;
|
const STATE_WIDTH: usize = 12;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
use core::ops::Range;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
CubeExtension, Digest, ElementHasher, Felt, FieldElement, Hasher, StarkField, ONE, ZERO,
|
CubeExtension, Digest, ElementHasher, Felt, FieldElement, Hasher, StarkField, ONE, ZERO,
|
||||||
};
|
};
|
||||||
use core::ops::Range;
|
|
||||||
|
|
||||||
mod arch;
|
mod arch;
|
||||||
pub use arch::optimized::{add_constants_and_apply_inv_sbox, add_constants_and_apply_sbox};
|
pub use arch::optimized::{add_constants_and_apply_inv_sbox, add_constants_and_apply_sbox};
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
use super::{Digest, Felt, StarkField, DIGEST_BYTES, DIGEST_SIZE, ZERO};
|
|
||||||
use crate::utils::{
|
|
||||||
bytes_to_hex_string, hex_to_bytes, string::String, ByteReader, ByteWriter, Deserializable,
|
|
||||||
DeserializationError, HexParseError, Serializable,
|
|
||||||
};
|
|
||||||
use core::{cmp::Ordering, fmt::Display, ops::Deref};
|
use core::{cmp::Ordering, fmt::Display, ops::Deref};
|
||||||
use winter_utils::Randomizable;
|
|
||||||
|
use super::{Digest, Felt, StarkField, DIGEST_BYTES, DIGEST_SIZE, ZERO};
|
||||||
|
use crate::{
|
||||||
|
rand::Randomizable,
|
||||||
|
utils::{
|
||||||
|
bytes_to_hex_string, hex_to_bytes, string::*, ByteReader, ByteWriter, Deserializable,
|
||||||
|
DeserializationError, HexParseError, Serializable,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
// DIGEST TRAIT IMPLEMENTATIONS
|
// DIGEST TRAIT IMPLEMENTATIONS
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
@@ -320,10 +323,11 @@ impl IntoIterator for RpoDigest {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{Deserializable, Felt, RpoDigest, Serializable, DIGEST_BYTES, DIGEST_SIZE};
|
|
||||||
use crate::utils::{string::String, SliceReader};
|
|
||||||
use rand_utils::rand_value;
|
use rand_utils::rand_value;
|
||||||
|
|
||||||
|
use super::{Deserializable, Felt, RpoDigest, Serializable, DIGEST_BYTES, DIGEST_SIZE};
|
||||||
|
use crate::utils::{string::*, SliceReader};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn digest_serialization() {
|
fn digest_serialization() {
|
||||||
let e1 = Felt::new(rand_value());
|
let e1 = Felt::new(rand_value());
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
|
use core::ops::Range;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
add_constants, add_constants_and_apply_inv_sbox, add_constants_and_apply_sbox, apply_inv_sbox,
|
add_constants, add_constants_and_apply_inv_sbox, add_constants_and_apply_sbox, apply_inv_sbox,
|
||||||
apply_mds, apply_sbox, Digest, ElementHasher, Felt, FieldElement, Hasher, StarkField, ARK1,
|
apply_mds, apply_sbox, Digest, ElementHasher, Felt, FieldElement, Hasher, StarkField, ARK1,
|
||||||
ARK2, BINARY_CHUNK_SIZE, CAPACITY_RANGE, DIGEST_BYTES, DIGEST_RANGE, DIGEST_SIZE, INPUT1_RANGE,
|
ARK2, BINARY_CHUNK_SIZE, CAPACITY_RANGE, DIGEST_BYTES, DIGEST_RANGE, DIGEST_SIZE, INPUT1_RANGE,
|
||||||
INPUT2_RANGE, MDS, NUM_ROUNDS, ONE, RATE_RANGE, RATE_WIDTH, STATE_WIDTH, ZERO,
|
INPUT2_RANGE, MDS, NUM_ROUNDS, ONE, RATE_RANGE, RATE_WIDTH, STATE_WIDTH, ZERO,
|
||||||
};
|
};
|
||||||
use core::{convert::TryInto, ops::Range};
|
|
||||||
|
|
||||||
mod digest;
|
mod digest;
|
||||||
pub use digest::RpoDigest;
|
pub use digest::RpoDigest;
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
|
use proptest::prelude::*;
|
||||||
|
use rand_utils::rand_value;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
super::{apply_inv_sbox, apply_sbox, ALPHA, INV_ALPHA},
|
super::{apply_inv_sbox, apply_sbox, ALPHA, INV_ALPHA},
|
||||||
Felt, FieldElement, Hasher, Rpo256, RpoDigest, StarkField, ONE, STATE_WIDTH, ZERO,
|
Felt, FieldElement, Hasher, Rpo256, RpoDigest, StarkField, ONE, STATE_WIDTH, ZERO,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{utils::collections::*, Word};
|
||||||
utils::collections::{BTreeSet, Vec},
|
|
||||||
Word,
|
|
||||||
};
|
|
||||||
use core::convert::TryInto;
|
|
||||||
use proptest::prelude::*;
|
|
||||||
use rand_utils::rand_value;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_sbox() {
|
fn test_sbox() {
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
use super::{Digest, Felt, StarkField, DIGEST_BYTES, DIGEST_SIZE, ZERO};
|
|
||||||
use crate::utils::{
|
|
||||||
bytes_to_hex_string, hex_to_bytes, string::String, ByteReader, ByteWriter, Deserializable,
|
|
||||||
DeserializationError, HexParseError, Serializable,
|
|
||||||
};
|
|
||||||
use core::{cmp::Ordering, fmt::Display, ops::Deref};
|
use core::{cmp::Ordering, fmt::Display, ops::Deref};
|
||||||
use winter_utils::Randomizable;
|
|
||||||
|
use super::{Digest, Felt, StarkField, DIGEST_BYTES, DIGEST_SIZE, ZERO};
|
||||||
|
use crate::{
|
||||||
|
rand::Randomizable,
|
||||||
|
utils::{
|
||||||
|
bytes_to_hex_string, hex_to_bytes, string::*, ByteReader, ByteWriter, Deserializable,
|
||||||
|
DeserializationError, HexParseError, Serializable,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
// DIGEST TRAIT IMPLEMENTATIONS
|
// DIGEST TRAIT IMPLEMENTATIONS
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
@@ -309,10 +312,11 @@ impl Deserializable for RpxDigest {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{Deserializable, Felt, RpxDigest, Serializable, DIGEST_BYTES, DIGEST_SIZE};
|
|
||||||
use crate::utils::{string::String, SliceReader};
|
|
||||||
use rand_utils::rand_value;
|
use rand_utils::rand_value;
|
||||||
|
|
||||||
|
use super::{Deserializable, Felt, RpxDigest, Serializable, DIGEST_BYTES, DIGEST_SIZE};
|
||||||
|
use crate::utils::{string::*, SliceReader};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn digest_serialization() {
|
fn digest_serialization() {
|
||||||
let e1 = Felt::new(rand_value());
|
let e1 = Felt::new(rand_value());
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use core::ops::Range;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
add_constants, add_constants_and_apply_inv_sbox, add_constants_and_apply_sbox, apply_inv_sbox,
|
add_constants, add_constants_and_apply_inv_sbox, add_constants_and_apply_sbox, apply_inv_sbox,
|
||||||
apply_mds, apply_sbox, CubeExtension, Digest, ElementHasher, Felt, FieldElement, Hasher,
|
apply_mds, apply_sbox, CubeExtension, Digest, ElementHasher, Felt, FieldElement, Hasher,
|
||||||
@@ -5,7 +7,6 @@ use super::{
|
|||||||
DIGEST_SIZE, INPUT1_RANGE, INPUT2_RANGE, MDS, NUM_ROUNDS, RATE_RANGE, RATE_WIDTH, STATE_WIDTH,
|
DIGEST_SIZE, INPUT1_RANGE, INPUT2_RANGE, MDS, NUM_ROUNDS, RATE_RANGE, RATE_WIDTH, STATE_WIDTH,
|
||||||
ZERO,
|
ZERO,
|
||||||
};
|
};
|
||||||
use core::{convert::TryInto, ops::Range};
|
|
||||||
|
|
||||||
mod digest;
|
mod digest;
|
||||||
pub use digest::RpxDigest;
|
pub use digest::RpxDigest;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use super::{Felt, FieldElement, ALPHA, INV_ALPHA};
|
|
||||||
use rand_utils::rand_value;
|
use rand_utils::rand_value;
|
||||||
|
|
||||||
|
use super::{Felt, FieldElement, ALPHA, INV_ALPHA};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_alphas() {
|
fn test_alphas() {
|
||||||
let e: Felt = Felt::new(rand_value());
|
let e: Felt = Felt::new(rand_value());
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use miden_crypto::{
|
use miden_crypto::{
|
||||||
hash::rpo::{Rpo256, RpoDigest},
|
hash::rpo::{Rpo256, RpoDigest},
|
||||||
@@ -5,7 +7,6 @@ use miden_crypto::{
|
|||||||
Felt, Word, ONE,
|
Felt, Word, ONE,
|
||||||
};
|
};
|
||||||
use rand_utils::rand_value;
|
use rand_utils::rand_value;
|
||||||
use std::time::Instant;
|
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[clap(name = "Benchmark", about = "SMT benchmark", version, rename_all = "kebab-case")]
|
#[clap(name = "Benchmark", about = "SMT benchmark", version, rename_all = "kebab-case")]
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use super::{Felt, RpoDigest, EMPTY_WORD};
|
|
||||||
use core::slice;
|
use core::slice;
|
||||||
|
|
||||||
|
use super::{Felt, RpoDigest, EMPTY_WORD};
|
||||||
|
|
||||||
// EMPTY NODES SUBTREES
|
// EMPTY NODES SUBTREES
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
use crate::{
|
|
||||||
merkle::{MerklePath, NodeIndex, RpoDigest},
|
|
||||||
utils::collections::Vec,
|
|
||||||
};
|
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
|
||||||
use super::smt::SmtLeafError;
|
use super::{smt::SmtLeafError, MerklePath, NodeIndex, RpoDigest};
|
||||||
|
use crate::utils::collections::*;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum MerkleError {
|
pub enum MerkleError {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
use core::fmt::Display;
|
||||||
|
|
||||||
use super::{Felt, MerkleError, RpoDigest};
|
use super::{Felt, MerkleError, RpoDigest};
|
||||||
use crate::utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable};
|
use crate::utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable};
|
||||||
use core::fmt::Display;
|
|
||||||
|
|
||||||
// NODE INDEX
|
// NODE INDEX
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
@@ -181,9 +182,10 @@ impl Deserializable for NodeIndex {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
|
||||||
use proptest::prelude::*;
|
use proptest::prelude::*;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_node_index_value_too_high() {
|
fn test_node_index_value_too_high() {
|
||||||
assert_eq!(NodeIndex::new(0, 0).unwrap(), NodeIndex { depth: 0, value: 0 });
|
assert_eq!(NodeIndex::new(0, 0).unwrap(), NodeIndex { depth: 0, value: 0 });
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
use super::{InnerNodeInfo, MerkleError, MerklePath, NodeIndex, Rpo256, RpoDigest, Vec, Word};
|
|
||||||
use crate::utils::{string::String, uninit_vector, word_to_hex};
|
|
||||||
use core::{fmt, ops::Deref, slice};
|
use core::{fmt, ops::Deref, slice};
|
||||||
|
|
||||||
use winter_math::log2;
|
use winter_math::log2;
|
||||||
|
|
||||||
|
use super::{InnerNodeInfo, MerkleError, MerklePath, NodeIndex, Rpo256, RpoDigest, Word};
|
||||||
|
use crate::utils::{collections::*, string::*, uninit_vector, word_to_hex};
|
||||||
|
|
||||||
// MERKLE TREE
|
// MERKLE TREE
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
|
|
||||||
@@ -283,13 +285,15 @@ pub fn path_to_text(path: &MerklePath) -> Result<String, fmt::Error> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use core::mem::size_of;
|
||||||
|
|
||||||
|
use proptest::prelude::*;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
merkle::{digests_to_words, int_to_leaf, int_to_node, InnerNodeInfo},
|
merkle::{digests_to_words, int_to_leaf, int_to_node},
|
||||||
Felt, Word, WORD_SIZE,
|
Felt, WORD_SIZE,
|
||||||
};
|
};
|
||||||
use core::mem::size_of;
|
|
||||||
use proptest::prelude::*;
|
|
||||||
|
|
||||||
const LEAVES4: [RpoDigest; WORD_SIZE] =
|
const LEAVES4: [RpoDigest; WORD_SIZE] =
|
||||||
[int_to_node(1), int_to_node(2), int_to_node(3), int_to_node(4)];
|
[int_to_node(1), int_to_node(2), int_to_node(3), int_to_node(4)];
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use super::super::{RpoDigest, Vec};
|
use super::super::RpoDigest;
|
||||||
|
use crate::utils::collections::*;
|
||||||
|
|
||||||
/// Container for the update data of a [super::PartialMmr]
|
/// Container for the update data of a [super::PartialMmr]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use crate::merkle::MerkleError;
|
|
||||||
use core::fmt::{Display, Formatter};
|
use core::fmt::{Display, Formatter};
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
|
use crate::merkle::MerkleError;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
pub enum MmrError {
|
pub enum MmrError {
|
||||||
InvalidPosition(usize),
|
InvalidPosition(usize),
|
||||||
|
|||||||
@@ -11,11 +11,12 @@
|
|||||||
//! merged, creating a new tree with depth d+1, this process is continued until the property is
|
//! merged, creating a new tree with depth d+1, this process is continued until the property is
|
||||||
//! reestablished.
|
//! reestablished.
|
||||||
use super::{
|
use super::{
|
||||||
super::{InnerNodeInfo, MerklePath, Vec},
|
super::{InnerNodeInfo, MerklePath},
|
||||||
bit::TrueBitPositionIterator,
|
bit::TrueBitPositionIterator,
|
||||||
leaf_to_corresponding_tree, nodes_in_forest, MmrDelta, MmrError, MmrPeaks, MmrProof, Rpo256,
|
leaf_to_corresponding_tree, nodes_in_forest, MmrDelta, MmrError, MmrPeaks, MmrProof, Rpo256,
|
||||||
RpoDigest,
|
RpoDigest,
|
||||||
};
|
};
|
||||||
|
use crate::utils::collections::*;
|
||||||
|
|
||||||
// MMR
|
// MMR
|
||||||
// ===============================================================================================
|
// ===============================================================================================
|
||||||
|
|||||||
@@ -126,9 +126,10 @@ impl From<InOrderIndex> for u64 {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::InOrderIndex;
|
|
||||||
use proptest::prelude::*;
|
use proptest::prelude::*;
|
||||||
|
|
||||||
|
use super::InOrderIndex;
|
||||||
|
|
||||||
proptest! {
|
proptest! {
|
||||||
#[test]
|
#[test]
|
||||||
fn proptest_inorder_index_random(count in 1..1000usize) {
|
fn proptest_inorder_index_random(count in 1..1000usize) {
|
||||||
|
|||||||
@@ -4,10 +4,7 @@ use crate::{
|
|||||||
mmr::{leaf_to_corresponding_tree, nodes_in_forest},
|
mmr::{leaf_to_corresponding_tree, nodes_in_forest},
|
||||||
InOrderIndex, InnerNodeInfo, MerklePath, MmrError, MmrPeaks,
|
InOrderIndex, InnerNodeInfo, MerklePath, MmrError, MmrPeaks,
|
||||||
},
|
},
|
||||||
utils::{
|
utils::{collections::*, vec},
|
||||||
collections::{BTreeMap, BTreeSet, Vec},
|
|
||||||
vec,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// TYPE ALIASES
|
// TYPE ALIASES
|
||||||
@@ -616,10 +613,13 @@ fn forest_to_rightmost_index(forest: usize) -> InOrderIndex {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{
|
use super::{
|
||||||
forest_to_rightmost_index, forest_to_root_index, BTreeSet, InOrderIndex, MmrPeaks,
|
forest_to_rightmost_index, forest_to_root_index, InOrderIndex, MmrPeaks, PartialMmr,
|
||||||
PartialMmr, RpoDigest, Vec,
|
RpoDigest,
|
||||||
|
};
|
||||||
|
use crate::{
|
||||||
|
merkle::{int_to_node, MerkleStore, Mmr, NodeIndex},
|
||||||
|
utils::collections::*,
|
||||||
};
|
};
|
||||||
use crate::merkle::{int_to_node, MerkleStore, Mmr, NodeIndex};
|
|
||||||
|
|
||||||
const LEAVES: [RpoDigest; 7] = [
|
const LEAVES: [RpoDigest; 7] = [
|
||||||
int_to_node(0),
|
int_to_node(0),
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
use super::{
|
use super::{super::ZERO, Felt, MmrError, MmrProof, Rpo256, RpoDigest, Word};
|
||||||
super::{RpoDigest, Vec, ZERO},
|
use crate::utils::collections::*;
|
||||||
Felt, MmrError, MmrProof, Rpo256, Word,
|
|
||||||
};
|
|
||||||
|
|
||||||
// MMR PEAKS
|
// MMR PEAKS
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
use super::{
|
use super::{
|
||||||
super::{InnerNodeInfo, Rpo256, RpoDigest, Vec},
|
super::{InnerNodeInfo, Rpo256, RpoDigest},
|
||||||
bit::TrueBitPositionIterator,
|
bit::TrueBitPositionIterator,
|
||||||
full::high_bitmask,
|
full::high_bitmask,
|
||||||
leaf_to_corresponding_tree, nodes_in_forest, Mmr, MmrPeaks, PartialMmr,
|
leaf_to_corresponding_tree, nodes_in_forest, Mmr, MmrPeaks, PartialMmr,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
merkle::{int_to_node, InOrderIndex, MerklePath, MerkleTree, MmrProof, NodeIndex},
|
merkle::{int_to_node, InOrderIndex, MerklePath, MerkleTree, MmrProof, NodeIndex},
|
||||||
|
utils::collections::*,
|
||||||
Felt, Word,
|
Felt, Word,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -837,9 +838,10 @@ fn test_mmr_add_invalid_odd_leaf() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod property_tests {
|
mod property_tests {
|
||||||
use super::leaf_to_corresponding_tree;
|
|
||||||
use proptest::prelude::*;
|
use proptest::prelude::*;
|
||||||
|
|
||||||
|
use super::leaf_to_corresponding_tree;
|
||||||
|
|
||||||
proptest! {
|
proptest! {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_last_position_is_always_contained_in_the_last_tree(leaves in any::<usize>().prop_filter("cant have an empty tree", |v| *v != 0)) {
|
fn test_last_position_is_always_contained_in_the_last_tree(leaves in any::<usize>().prop_filter("cant have an empty tree", |v| *v != 0)) {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
hash::rpo::{Rpo256, RpoDigest},
|
hash::rpo::{Rpo256, RpoDigest},
|
||||||
utils::collections::{vec, BTreeMap, BTreeSet, KvMap, RecordingMap, Vec},
|
|
||||||
Felt, Word, EMPTY_WORD, ZERO,
|
Felt, Word, EMPTY_WORD, ZERO,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -45,6 +44,9 @@ pub use error::MerkleError;
|
|||||||
// HELPER FUNCTIONS
|
// HELPER FUNCTIONS
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
use crate::utils::collections::*;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
const fn int_to_node(value: u64) -> RpoDigest {
|
const fn int_to_node(value: u64) -> RpoDigest {
|
||||||
RpoDigest::new([Felt::new(value), ZERO, ZERO, ZERO])
|
RpoDigest::new([Felt::new(value), ZERO, ZERO, ZERO])
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
|
use core::fmt;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
BTreeMap, BTreeSet, InnerNodeInfo, MerkleError, MerklePath, NodeIndex, Rpo256, RpoDigest,
|
InnerNodeInfo, MerkleError, MerklePath, NodeIndex, Rpo256, RpoDigest, ValuePath, Word,
|
||||||
ValuePath, Vec, Word, EMPTY_WORD,
|
EMPTY_WORD,
|
||||||
};
|
};
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
format, string::String, vec, word_to_hex, ByteReader, ByteWriter, Deserializable,
|
collections::*, format, string::*, vec, word_to_hex, ByteReader, ByteWriter, Deserializable,
|
||||||
DeserializationError, Serializable,
|
DeserializationError, Serializable,
|
||||||
};
|
};
|
||||||
use core::fmt;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
use super::{
|
use super::{
|
||||||
super::{
|
super::{
|
||||||
digests_to_words, int_to_node, BTreeMap, DefaultMerkleStore as MerkleStore, MerkleTree,
|
digests_to_words, int_to_node, DefaultMerkleStore as MerkleStore, MerkleTree, NodeIndex,
|
||||||
NodeIndex, PartialMerkleTree,
|
PartialMerkleTree,
|
||||||
},
|
},
|
||||||
Deserializable, InnerNodeInfo, RpoDigest, Serializable, ValuePath, Vec,
|
Deserializable, InnerNodeInfo, RpoDigest, Serializable, ValuePath,
|
||||||
};
|
};
|
||||||
|
use crate::utils::collections::*;
|
||||||
|
|
||||||
// TEST DATA
|
// TEST DATA
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
use crate::Word;
|
|
||||||
|
|
||||||
use super::{vec, InnerNodeInfo, MerkleError, NodeIndex, Rpo256, RpoDigest, Vec};
|
|
||||||
use core::ops::{Deref, DerefMut};
|
use core::ops::{Deref, DerefMut};
|
||||||
use winter_utils::{ByteReader, Deserializable, DeserializationError, Serializable};
|
|
||||||
|
use super::{InnerNodeInfo, MerkleError, NodeIndex, Rpo256, RpoDigest};
|
||||||
|
use crate::{
|
||||||
|
utils::{collections::*, ByteReader, Deserializable, DeserializationError, Serializable},
|
||||||
|
Word,
|
||||||
|
};
|
||||||
|
|
||||||
// MERKLE PATH
|
// MERKLE PATH
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use core::fmt;
|
|||||||
use crate::{
|
use crate::{
|
||||||
hash::rpo::RpoDigest,
|
hash::rpo::RpoDigest,
|
||||||
merkle::{LeafIndex, SMT_DEPTH},
|
merkle::{LeafIndex, SMT_DEPTH},
|
||||||
utils::collections::Vec,
|
utils::collections::*,
|
||||||
Word,
|
Word,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
use core::cmp::Ordering;
|
use core::cmp::Ordering;
|
||||||
|
|
||||||
use crate::utils::{collections::Vec, string::ToString, vec};
|
|
||||||
use winter_utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable};
|
|
||||||
|
|
||||||
use super::{Felt, LeafIndex, Rpo256, RpoDigest, SmtLeafError, Word, EMPTY_WORD, SMT_DEPTH};
|
use super::{Felt, LeafIndex, Rpo256, RpoDigest, SmtLeafError, Word, EMPTY_WORD, SMT_DEPTH};
|
||||||
|
use crate::utils::{
|
||||||
|
collections::*, string::*, vec, ByteReader, ByteWriter, Deserializable, DeserializationError,
|
||||||
|
Serializable,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
use crate::hash::rpo::Rpo256;
|
|
||||||
use crate::merkle::{EmptySubtreeRoots, InnerNodeInfo};
|
|
||||||
use crate::utils::collections::{BTreeMap, BTreeSet};
|
|
||||||
use crate::{Felt, EMPTY_WORD};
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
InnerNode, LeafIndex, MerkleError, MerklePath, NodeIndex, RpoDigest, SparseMerkleTree, Word,
|
EmptySubtreeRoots, Felt, InnerNode, InnerNodeInfo, LeafIndex, MerkleError, MerklePath,
|
||||||
|
NodeIndex, Rpo256, RpoDigest, SparseMerkleTree, Word, EMPTY_WORD,
|
||||||
};
|
};
|
||||||
|
use crate::utils::collections::*;
|
||||||
|
|
||||||
mod error;
|
mod error;
|
||||||
pub use error::{SmtLeafError, SmtProofError};
|
pub use error::{SmtLeafError, SmtProofError};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::utils::string::ToString;
|
|
||||||
use winter_utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable};
|
|
||||||
|
|
||||||
use super::{MerklePath, RpoDigest, SmtLeaf, SmtProofError, Word, SMT_DEPTH};
|
use super::{MerklePath, RpoDigest, SmtLeaf, SmtProofError, Word, SMT_DEPTH};
|
||||||
|
use crate::utils::{
|
||||||
|
string::*, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
|
||||||
|
};
|
||||||
|
|
||||||
/// A proof which can be used to assert membership (or non-membership) of key-value pairs in a
|
/// A proof which can be used to assert membership (or non-membership) of key-value pairs in a
|
||||||
/// [`super::Smt`].
|
/// [`super::Smt`].
|
||||||
@@ -23,7 +23,8 @@ impl SmtProof {
|
|||||||
/// # Errors
|
/// # Errors
|
||||||
/// Returns an error if the path length is not [`SMT_DEPTH`].
|
/// Returns an error if the path length is not [`SMT_DEPTH`].
|
||||||
pub fn new(path: MerklePath, leaf: SmtLeaf) -> Result<Self, SmtProofError> {
|
pub fn new(path: MerklePath, leaf: SmtLeaf) -> Result<Self, SmtProofError> {
|
||||||
if path.len() != SMT_DEPTH.into() {
|
let depth: usize = SMT_DEPTH.into();
|
||||||
|
if path.len() != depth {
|
||||||
return Err(SmtProofError::InvalidPathLength(path.len()));
|
return Err(SmtProofError::InvalidPathLength(path.len()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
use winter_utils::{Deserializable, Serializable};
|
use super::{Felt, LeafIndex, NodeIndex, Rpo256, RpoDigest, Smt, SmtLeaf, EMPTY_WORD, SMT_DEPTH};
|
||||||
|
|
||||||
use super::*;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
merkle::{EmptySubtreeRoots, MerkleStore},
|
merkle::{EmptySubtreeRoots, MerkleStore},
|
||||||
utils::collections::Vec,
|
utils::{collections::*, Deserializable, Serializable},
|
||||||
ONE, WORD_SIZE,
|
Word, ONE, WORD_SIZE,
|
||||||
};
|
};
|
||||||
|
|
||||||
// SMT
|
// SMT
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
|
use super::{EmptySubtreeRoots, InnerNodeInfo, MerkleError, MerklePath, NodeIndex};
|
||||||
use crate::{
|
use crate::{
|
||||||
hash::rpo::{Rpo256, RpoDigest},
|
hash::rpo::{Rpo256, RpoDigest},
|
||||||
Word,
|
utils::collections::*,
|
||||||
|
Felt, Word, EMPTY_WORD,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{EmptySubtreeRoots, MerkleError, MerklePath, NodeIndex, Vec};
|
|
||||||
|
|
||||||
mod full;
|
mod full;
|
||||||
pub use full::{Smt, SmtLeaf, SmtLeafError, SmtProof, SmtProofError, SMT_DEPTH};
|
pub use full::{Smt, SmtLeaf, SmtLeafError, SmtProof, SmtProofError, SMT_DEPTH};
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
use crate::{
|
|
||||||
merkle::{EmptySubtreeRoots, InnerNodeInfo, MerklePath, ValuePath},
|
|
||||||
EMPTY_WORD,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
InnerNode, LeafIndex, MerkleError, NodeIndex, RpoDigest, SparseMerkleTree, Word, SMT_MAX_DEPTH,
|
super::ValuePath, EmptySubtreeRoots, InnerNode, InnerNodeInfo, LeafIndex, MerkleError,
|
||||||
|
MerklePath, NodeIndex, RpoDigest, SparseMerkleTree, Word, EMPTY_WORD, SMT_MAX_DEPTH,
|
||||||
SMT_MIN_DEPTH,
|
SMT_MIN_DEPTH,
|
||||||
};
|
};
|
||||||
use crate::utils::collections::{BTreeMap, BTreeSet};
|
use crate::utils::collections::*;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use crate::{
|
|||||||
digests_to_words, int_to_leaf, int_to_node, smt::SparseMerkleTree, EmptySubtreeRoots,
|
digests_to_words, int_to_leaf, int_to_node, smt::SparseMerkleTree, EmptySubtreeRoots,
|
||||||
InnerNodeInfo, LeafIndex, MerkleTree,
|
InnerNodeInfo, LeafIndex, MerkleTree,
|
||||||
},
|
},
|
||||||
utils::collections::Vec,
|
utils::collections::*,
|
||||||
Word, EMPTY_WORD,
|
Word, EMPTY_WORD,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
use super::{
|
|
||||||
mmr::Mmr, BTreeMap, EmptySubtreeRoots, InnerNodeInfo, KvMap, MerkleError, MerklePath,
|
|
||||||
MerkleTree, NodeIndex, PartialMerkleTree, RecordingMap, RootPath, Rpo256, RpoDigest, SimpleSmt,
|
|
||||||
Smt, ValuePath, Vec,
|
|
||||||
};
|
|
||||||
use crate::utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable};
|
|
||||||
use core::borrow::Borrow;
|
use core::borrow::Borrow;
|
||||||
|
|
||||||
|
use super::{
|
||||||
|
mmr::Mmr, EmptySubtreeRoots, InnerNodeInfo, MerkleError, MerklePath, MerkleTree, NodeIndex,
|
||||||
|
PartialMerkleTree, RootPath, Rpo256, RpoDigest, SimpleSmt, Smt, ValuePath,
|
||||||
|
};
|
||||||
|
use crate::utils::{
|
||||||
|
collections::*, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use seq_macro::seq;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
DefaultMerkleStore as MerkleStore, EmptySubtreeRoots, MerkleError, MerklePath, NodeIndex,
|
DefaultMerkleStore as MerkleStore, EmptySubtreeRoots, MerkleError, MerklePath, NodeIndex,
|
||||||
PartialMerkleTree, RecordingMerkleStore, Rpo256, RpoDigest,
|
PartialMerkleTree, RecordingMerkleStore, Rpo256, RpoDigest,
|
||||||
@@ -10,12 +12,10 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use super::{Deserializable, Serializable};
|
use {
|
||||||
|
super::{Deserializable, Serializable},
|
||||||
#[cfg(feature = "std")]
|
std::error::Error,
|
||||||
use std::error::Error;
|
};
|
||||||
|
|
||||||
use seq_macro::seq;
|
|
||||||
|
|
||||||
// TEST DATA
|
// TEST DATA
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
//! Pseudo-random element generation.
|
//! Pseudo-random element generation.
|
||||||
|
|
||||||
pub use winter_crypto::{DefaultRandomCoin as WinterRandomCoin, RandomCoin, RandomCoinError};
|
pub use winter_crypto::{DefaultRandomCoin as WinterRandomCoin, RandomCoin, RandomCoinError};
|
||||||
|
pub use winter_utils::Randomizable;
|
||||||
|
|
||||||
use crate::{Felt, FieldElement, Word, ZERO};
|
use crate::{Felt, FieldElement, Word, ZERO};
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
use super::{Felt, FeltRng, FieldElement, Word, ZERO};
|
use super::{Felt, FeltRng, FieldElement, RandomCoin, RandomCoinError, Word, ZERO};
|
||||||
use crate::{
|
use crate::{
|
||||||
hash::rpo::{Rpo256, RpoDigest},
|
hash::rpo::{Rpo256, RpoDigest},
|
||||||
utils::{
|
utils::{
|
||||||
collections::Vec, string::ToString, vec, ByteReader, ByteWriter, Deserializable,
|
collections::*, string::*, vec, ByteReader, ByteWriter, Deserializable,
|
||||||
DeserializationError, Serializable,
|
DeserializationError, Serializable,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
pub use winter_crypto::{RandomCoin, RandomCoinError};
|
|
||||||
|
|
||||||
// CONSTANTS
|
// CONSTANTS
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use core::cell::RefCell;
|
use core::cell::RefCell;
|
||||||
use winter_utils::{
|
|
||||||
collections::{btree_map::IntoIter, BTreeMap, BTreeSet},
|
use super::{
|
||||||
Box,
|
boxed::*,
|
||||||
|
collections::{btree_map::*, *},
|
||||||
};
|
};
|
||||||
|
|
||||||
// KEY-VALUE MAP TRAIT
|
// KEY-VALUE MAP TRAIT
|
||||||
|
|||||||
@@ -1,26 +1,29 @@
|
|||||||
//! Utilities used in this crate which can also be generally useful downstream.
|
//! Utilities used in this crate which can also be generally useful downstream.
|
||||||
|
|
||||||
use super::{utils::string::String, Word};
|
|
||||||
use core::fmt::{self, Display, Write};
|
use core::fmt::{self, Display, Write};
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
pub use std::{format, vec};
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
pub use alloc::{format, vec};
|
pub use alloc::{format, vec};
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
use super::Word;
|
||||||
pub use std::{format, vec};
|
use crate::utils::string::*;
|
||||||
|
|
||||||
mod kv_map;
|
mod kv_map;
|
||||||
|
|
||||||
// RE-EXPORTS
|
// RE-EXPORTS
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
pub use winter_utils::{
|
pub use winter_utils::{
|
||||||
string, uninit_vector, Box, ByteReader, ByteWriter, Deserializable, DeserializationError,
|
boxed, string, uninit_vector, Box, ByteReader, ByteWriter, Deserializable,
|
||||||
Serializable, SliceReader,
|
DeserializationError, Serializable, SliceReader,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod collections {
|
pub mod collections {
|
||||||
pub use super::kv_map::*;
|
|
||||||
pub use winter_utils::collections::*;
|
pub use winter_utils::collections::*;
|
||||||
|
|
||||||
|
pub use super::kv_map::*;
|
||||||
}
|
}
|
||||||
|
|
||||||
// UTILITY FUNCTIONS
|
// UTILITY FUNCTIONS
|
||||||
|
|||||||
Reference in New Issue
Block a user