mirror of
https://github.com/arnaucube/miden-crypto.git
synced 2026-01-12 17:11:28 +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
|
||||
.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)
|
||||
|
||||
* Implemented the `PartialMmr` data structure (#195).
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
[package]
|
||||
name = "miden-crypto"
|
||||
version = "0.8.0"
|
||||
version = "0.8.1"
|
||||
description = "Miden Cryptographic primitives"
|
||||
authors = ["miden contributors"]
|
||||
readme = "README.md"
|
||||
license = "MIT"
|
||||
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"]
|
||||
keywords = ["miden", "crypto", "hash", "merkle"]
|
||||
edition = "2021"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use core::mem::swap;
|
||||
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use miden_crypto::{
|
||||
merkle::{LeafIndex, SimpleSmt},
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
use criterion::{black_box, criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
|
||||
use miden_crypto::merkle::{
|
||||
DefaultMerkleStore as MerkleStore, LeafIndex, MerkleTree, NodeIndex, SimpleSmt, SMT_MAX_DEPTH,
|
||||
use miden_crypto::{
|
||||
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};
|
||||
|
||||
/// 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 super::{LOG_N, MODULUS, PK_LEN};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum FalconError {
|
||||
KeyGenerationFailed,
|
||||
|
||||
@@ -96,9 +96,10 @@ pub struct Rpo128Context {
|
||||
|
||||
#[cfg(all(test, feature = "std"))]
|
||||
mod tests {
|
||||
use rand_utils::{rand_array, rand_value, rand_vector};
|
||||
|
||||
use super::*;
|
||||
use crate::dsa::rpo_falcon512::{NONCE_LEN, PK_LEN, SIG_LEN, SK_LEN};
|
||||
use rand_utils::{rand_array, rand_value, rand_vector};
|
||||
|
||||
#[test]
|
||||
fn falcon_ffi() {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#[cfg(feature = "std")]
|
||||
use super::{ffi, NonceBytes, NONCE_LEN, PK_LEN, SIG_LEN, SK_LEN};
|
||||
use super::{
|
||||
ByteReader, ByteWriter, Deserializable, DeserializationError, FalconError, Polynomial,
|
||||
PublicKeyBytes, Rpo256, SecretKeyBytes, Serializable, Signature, Word,
|
||||
};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use super::{ffi, NonceBytes, NONCE_LEN, PK_LEN, SIG_LEN, SK_LEN};
|
||||
|
||||
// PUBLIC KEY
|
||||
// ================================================================================================
|
||||
|
||||
@@ -182,9 +181,10 @@ impl Deserializable for KeyPair {
|
||||
|
||||
#[cfg(all(test, feature = "std"))]
|
||||
mod tests {
|
||||
use super::{super::Felt, KeyPair, NonceBytes, Word};
|
||||
use rand_utils::{rand_array, rand_vector};
|
||||
|
||||
use super::{super::Felt, KeyPair, NonceBytes, Word};
|
||||
|
||||
#[test]
|
||||
fn test_falcon_verification() {
|
||||
// generate random keys
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
use crate::{
|
||||
hash::rpo::Rpo256,
|
||||
utils::{
|
||||
collections::Vec, ByteReader, ByteWriter, Deserializable, DeserializationError,
|
||||
Serializable,
|
||||
},
|
||||
utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable},
|
||||
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 super::{FalconError, Felt, LOG_N, MODULUS, MODULUS_MINUS_1_OVER_TWO, N, PK_LEN};
|
||||
use crate::utils::collections::*;
|
||||
|
||||
// FALCON POLYNOMIAL
|
||||
// ================================================================================================
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
use core::cell::OnceCell;
|
||||
|
||||
use super::{
|
||||
ByteReader, ByteWriter, Deserializable, DeserializationError, Felt, NonceBytes, NonceElements,
|
||||
Polynomial, PublicKeyBytes, Rpo256, Serializable, SignatureBytes, Word, MODULUS, N,
|
||||
SIG_L2_BOUND, ZERO,
|
||||
};
|
||||
use crate::utils::string::ToString;
|
||||
use core::cell::OnceCell;
|
||||
use crate::utils::string::*;
|
||||
|
||||
// FALCON SIGNATURE
|
||||
// ================================================================================================
|
||||
@@ -195,13 +196,14 @@ fn decode_nonce(nonce: &NonceBytes) -> NonceElements {
|
||||
|
||||
#[cfg(all(test, feature = "std"))]
|
||||
mod tests {
|
||||
use super::{
|
||||
super::{ffi::*, Felt, KeyPair},
|
||||
*,
|
||||
};
|
||||
use libc::c_void;
|
||||
use rand_utils::rand_vector;
|
||||
|
||||
use super::{
|
||||
super::{ffi::*, KeyPair},
|
||||
*,
|
||||
};
|
||||
|
||||
// Wrappers for unsafe functions
|
||||
impl Rpo128Context {
|
||||
/// 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::{
|
||||
mem::{size_of, transmute, transmute_copy},
|
||||
ops::Deref,
|
||||
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)]
|
||||
mod tests;
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
use super::*;
|
||||
use crate::utils::collections::Vec;
|
||||
use proptest::prelude::*;
|
||||
use rand_utils::rand_vector;
|
||||
|
||||
use super::*;
|
||||
use crate::utils::collections::*;
|
||||
|
||||
#[test]
|
||||
fn blake3_hash_elements() {
|
||||
// test multiple of 8
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#[cfg(target_feature = "sve")]
|
||||
pub mod optimized {
|
||||
use crate::hash::rescue::STATE_WIDTH;
|
||||
use crate::Felt;
|
||||
use crate::{hash::rescue::STATE_WIDTH, Felt};
|
||||
|
||||
mod ffi {
|
||||
#[link(name = "rpo_sve", kind = "static")]
|
||||
@@ -50,8 +49,10 @@ mod x86_64_avx2;
|
||||
#[cfg(target_feature = "avx2")]
|
||||
pub mod optimized {
|
||||
use super::x86_64_avx2::{apply_inv_sbox, apply_sbox};
|
||||
use crate::hash::rescue::{add_constants, STATE_WIDTH};
|
||||
use crate::Felt;
|
||||
use crate::{
|
||||
hash::rescue::{add_constants, STATE_WIDTH},
|
||||
Felt,
|
||||
};
|
||||
|
||||
#[inline(always)]
|
||||
pub fn add_constants_and_apply_sbox(
|
||||
@@ -80,8 +81,7 @@ pub mod optimized {
|
||||
|
||||
#[cfg(not(any(target_feature = "avx2", target_feature = "sve")))]
|
||||
pub mod optimized {
|
||||
use crate::hash::rescue::STATE_WIDTH;
|
||||
use crate::Felt;
|
||||
use crate::{hash::rescue::STATE_WIDTH, Felt};
|
||||
|
||||
#[inline(always)]
|
||||
pub fn add_constants_and_apply_sbox(
|
||||
|
||||
@@ -157,9 +157,10 @@ const fn block3(x: [i64; 3], y: [i64; 3]) -> [i64; 3] {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::{apply_mds, Felt, MDS, ZERO};
|
||||
use proptest::prelude::*;
|
||||
|
||||
use super::super::{apply_mds, Felt, MDS, ZERO};
|
||||
|
||||
const STATE_WIDTH: usize = 12;
|
||||
|
||||
#[inline(always)]
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use core::ops::Range;
|
||||
|
||||
use super::{
|
||||
CubeExtension, Digest, ElementHasher, Felt, FieldElement, Hasher, StarkField, ONE, ZERO,
|
||||
};
|
||||
use core::ops::Range;
|
||||
|
||||
mod arch;
|
||||
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 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
|
||||
// ================================================================================================
|
||||
@@ -320,10 +323,11 @@ impl IntoIterator for RpoDigest {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{Deserializable, Felt, RpoDigest, Serializable, DIGEST_BYTES, DIGEST_SIZE};
|
||||
use crate::utils::{string::String, SliceReader};
|
||||
use rand_utils::rand_value;
|
||||
|
||||
use super::{Deserializable, Felt, RpoDigest, Serializable, DIGEST_BYTES, DIGEST_SIZE};
|
||||
use crate::utils::{string::*, SliceReader};
|
||||
|
||||
#[test]
|
||||
fn digest_serialization() {
|
||||
let e1 = Felt::new(rand_value());
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
use core::ops::Range;
|
||||
|
||||
use super::{
|
||||
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,
|
||||
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,
|
||||
};
|
||||
use core::{convert::TryInto, ops::Range};
|
||||
|
||||
mod digest;
|
||||
pub use digest::RpoDigest;
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
use proptest::prelude::*;
|
||||
use rand_utils::rand_value;
|
||||
|
||||
use super::{
|
||||
super::{apply_inv_sbox, apply_sbox, ALPHA, INV_ALPHA},
|
||||
Felt, FieldElement, Hasher, Rpo256, RpoDigest, StarkField, ONE, STATE_WIDTH, ZERO,
|
||||
};
|
||||
use crate::{
|
||||
utils::collections::{BTreeSet, Vec},
|
||||
Word,
|
||||
};
|
||||
use core::convert::TryInto;
|
||||
use proptest::prelude::*;
|
||||
use rand_utils::rand_value;
|
||||
use crate::{utils::collections::*, Word};
|
||||
|
||||
#[test]
|
||||
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 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
|
||||
// ================================================================================================
|
||||
@@ -309,10 +312,11 @@ impl Deserializable for RpxDigest {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{Deserializable, Felt, RpxDigest, Serializable, DIGEST_BYTES, DIGEST_SIZE};
|
||||
use crate::utils::{string::String, SliceReader};
|
||||
use rand_utils::rand_value;
|
||||
|
||||
use super::{Deserializable, Felt, RpxDigest, Serializable, DIGEST_BYTES, DIGEST_SIZE};
|
||||
use crate::utils::{string::*, SliceReader};
|
||||
|
||||
#[test]
|
||||
fn digest_serialization() {
|
||||
let e1 = Felt::new(rand_value());
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use core::ops::Range;
|
||||
|
||||
use super::{
|
||||
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,
|
||||
@@ -5,7 +7,6 @@ use super::{
|
||||
DIGEST_SIZE, INPUT1_RANGE, INPUT2_RANGE, MDS, NUM_ROUNDS, RATE_RANGE, RATE_WIDTH, STATE_WIDTH,
|
||||
ZERO,
|
||||
};
|
||||
use core::{convert::TryInto, ops::Range};
|
||||
|
||||
mod digest;
|
||||
pub use digest::RpxDigest;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use super::{Felt, FieldElement, ALPHA, INV_ALPHA};
|
||||
use rand_utils::rand_value;
|
||||
|
||||
use super::{Felt, FieldElement, ALPHA, INV_ALPHA};
|
||||
|
||||
#[test]
|
||||
fn test_alphas() {
|
||||
let e: Felt = Felt::new(rand_value());
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::time::Instant;
|
||||
|
||||
use clap::Parser;
|
||||
use miden_crypto::{
|
||||
hash::rpo::{Rpo256, RpoDigest},
|
||||
@@ -5,7 +7,6 @@ use miden_crypto::{
|
||||
Felt, Word, ONE,
|
||||
};
|
||||
use rand_utils::rand_value;
|
||||
use std::time::Instant;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[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 super::{Felt, RpoDigest, EMPTY_WORD};
|
||||
|
||||
// EMPTY NODES SUBTREES
|
||||
// ================================================================================================
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
use crate::{
|
||||
merkle::{MerklePath, NodeIndex, RpoDigest},
|
||||
utils::collections::Vec,
|
||||
};
|
||||
use core::fmt;
|
||||
|
||||
use super::smt::SmtLeafError;
|
||||
use super::{smt::SmtLeafError, MerklePath, NodeIndex, RpoDigest};
|
||||
use crate::utils::collections::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum MerkleError {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use core::fmt::Display;
|
||||
|
||||
use super::{Felt, MerkleError, RpoDigest};
|
||||
use crate::utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable};
|
||||
use core::fmt::Display;
|
||||
|
||||
// NODE INDEX
|
||||
// ================================================================================================
|
||||
@@ -181,9 +182,10 @@ impl Deserializable for NodeIndex {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use proptest::prelude::*;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_node_index_value_too_high() {
|
||||
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 winter_math::log2;
|
||||
|
||||
use super::{InnerNodeInfo, MerkleError, MerklePath, NodeIndex, Rpo256, RpoDigest, Word};
|
||||
use crate::utils::{collections::*, string::*, uninit_vector, word_to_hex};
|
||||
|
||||
// MERKLE TREE
|
||||
// ================================================================================================
|
||||
|
||||
@@ -283,13 +285,15 @@ pub fn path_to_text(path: &MerklePath) -> Result<String, fmt::Error> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use core::mem::size_of;
|
||||
|
||||
use proptest::prelude::*;
|
||||
|
||||
use super::*;
|
||||
use crate::{
|
||||
merkle::{digests_to_words, int_to_leaf, int_to_node, InnerNodeInfo},
|
||||
Felt, Word, WORD_SIZE,
|
||||
merkle::{digests_to_words, int_to_leaf, int_to_node},
|
||||
Felt, WORD_SIZE,
|
||||
};
|
||||
use core::mem::size_of;
|
||||
use proptest::prelude::*;
|
||||
|
||||
const LEAVES4: [RpoDigest; WORD_SIZE] =
|
||||
[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]
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::merkle::MerkleError;
|
||||
use core::fmt::{Display, Formatter};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use std::error::Error;
|
||||
|
||||
use crate::merkle::MerkleError;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub enum MmrError {
|
||||
InvalidPosition(usize),
|
||||
|
||||
@@ -11,11 +11,12 @@
|
||||
//! merged, creating a new tree with depth d+1, this process is continued until the property is
|
||||
//! reestablished.
|
||||
use super::{
|
||||
super::{InnerNodeInfo, MerklePath, Vec},
|
||||
super::{InnerNodeInfo, MerklePath},
|
||||
bit::TrueBitPositionIterator,
|
||||
leaf_to_corresponding_tree, nodes_in_forest, MmrDelta, MmrError, MmrPeaks, MmrProof, Rpo256,
|
||||
RpoDigest,
|
||||
};
|
||||
use crate::utils::collections::*;
|
||||
|
||||
// MMR
|
||||
// ===============================================================================================
|
||||
|
||||
@@ -126,9 +126,10 @@ impl From<InOrderIndex> for u64 {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::InOrderIndex;
|
||||
use proptest::prelude::*;
|
||||
|
||||
use super::InOrderIndex;
|
||||
|
||||
proptest! {
|
||||
#[test]
|
||||
fn proptest_inorder_index_random(count in 1..1000usize) {
|
||||
|
||||
@@ -4,10 +4,7 @@ use crate::{
|
||||
mmr::{leaf_to_corresponding_tree, nodes_in_forest},
|
||||
InOrderIndex, InnerNodeInfo, MerklePath, MmrError, MmrPeaks,
|
||||
},
|
||||
utils::{
|
||||
collections::{BTreeMap, BTreeSet, Vec},
|
||||
vec,
|
||||
},
|
||||
utils::{collections::*, vec},
|
||||
};
|
||||
|
||||
// TYPE ALIASES
|
||||
@@ -616,10 +613,13 @@ fn forest_to_rightmost_index(forest: usize) -> InOrderIndex {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
forest_to_rightmost_index, forest_to_root_index, BTreeSet, InOrderIndex, MmrPeaks,
|
||||
PartialMmr, RpoDigest, Vec,
|
||||
forest_to_rightmost_index, forest_to_root_index, InOrderIndex, MmrPeaks, PartialMmr,
|
||||
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] = [
|
||||
int_to_node(0),
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use super::{
|
||||
super::{RpoDigest, Vec, ZERO},
|
||||
Felt, MmrError, MmrProof, Rpo256, Word,
|
||||
};
|
||||
use super::{super::ZERO, Felt, MmrError, MmrProof, Rpo256, RpoDigest, Word};
|
||||
use crate::utils::collections::*;
|
||||
|
||||
// MMR PEAKS
|
||||
// ================================================================================================
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
use super::{
|
||||
super::{InnerNodeInfo, Rpo256, RpoDigest, Vec},
|
||||
super::{InnerNodeInfo, Rpo256, RpoDigest},
|
||||
bit::TrueBitPositionIterator,
|
||||
full::high_bitmask,
|
||||
leaf_to_corresponding_tree, nodes_in_forest, Mmr, MmrPeaks, PartialMmr,
|
||||
};
|
||||
use crate::{
|
||||
merkle::{int_to_node, InOrderIndex, MerklePath, MerkleTree, MmrProof, NodeIndex},
|
||||
utils::collections::*,
|
||||
Felt, Word,
|
||||
};
|
||||
|
||||
@@ -837,9 +838,10 @@ fn test_mmr_add_invalid_odd_leaf() {
|
||||
}
|
||||
|
||||
mod property_tests {
|
||||
use super::leaf_to_corresponding_tree;
|
||||
use proptest::prelude::*;
|
||||
|
||||
use super::leaf_to_corresponding_tree;
|
||||
|
||||
proptest! {
|
||||
#[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)) {
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
use super::{
|
||||
hash::rpo::{Rpo256, RpoDigest},
|
||||
utils::collections::{vec, BTreeMap, BTreeSet, KvMap, RecordingMap, Vec},
|
||||
Felt, Word, EMPTY_WORD, ZERO,
|
||||
};
|
||||
|
||||
@@ -45,6 +44,9 @@ pub use error::MerkleError;
|
||||
// HELPER FUNCTIONS
|
||||
// ================================================================================================
|
||||
|
||||
#[cfg(test)]
|
||||
use crate::utils::collections::*;
|
||||
|
||||
#[cfg(test)]
|
||||
const fn int_to_node(value: u64) -> RpoDigest {
|
||||
RpoDigest::new([Felt::new(value), ZERO, ZERO, ZERO])
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
use core::fmt;
|
||||
|
||||
use super::{
|
||||
BTreeMap, BTreeSet, InnerNodeInfo, MerkleError, MerklePath, NodeIndex, Rpo256, RpoDigest,
|
||||
ValuePath, Vec, Word, EMPTY_WORD,
|
||||
InnerNodeInfo, MerkleError, MerklePath, NodeIndex, Rpo256, RpoDigest, ValuePath, Word,
|
||||
EMPTY_WORD,
|
||||
};
|
||||
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,
|
||||
};
|
||||
use core::fmt;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
use super::{
|
||||
super::{
|
||||
digests_to_words, int_to_node, BTreeMap, DefaultMerkleStore as MerkleStore, MerkleTree,
|
||||
NodeIndex, PartialMerkleTree,
|
||||
digests_to_words, int_to_node, DefaultMerkleStore as MerkleStore, MerkleTree, NodeIndex,
|
||||
PartialMerkleTree,
|
||||
},
|
||||
Deserializable, InnerNodeInfo, RpoDigest, Serializable, ValuePath, Vec,
|
||||
Deserializable, InnerNodeInfo, RpoDigest, Serializable, ValuePath,
|
||||
};
|
||||
use crate::utils::collections::*;
|
||||
|
||||
// TEST DATA
|
||||
// ================================================================================================
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
use crate::Word;
|
||||
|
||||
use super::{vec, InnerNodeInfo, MerkleError, NodeIndex, Rpo256, RpoDigest, Vec};
|
||||
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
|
||||
// ================================================================================================
|
||||
|
||||
@@ -3,7 +3,7 @@ use core::fmt;
|
||||
use crate::{
|
||||
hash::rpo::RpoDigest,
|
||||
merkle::{LeafIndex, SMT_DEPTH},
|
||||
utils::collections::Vec,
|
||||
utils::collections::*,
|
||||
Word,
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
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 crate::utils::{
|
||||
collections::*, string::*, vec, ByteReader, ByteWriter, Deserializable, DeserializationError,
|
||||
Serializable,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[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::{
|
||||
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;
|
||||
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 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
|
||||
/// [`super::Smt`].
|
||||
@@ -23,7 +23,8 @@ impl SmtProof {
|
||||
/// # Errors
|
||||
/// Returns an error if the path length is not [`SMT_DEPTH`].
|
||||
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()));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
use winter_utils::{Deserializable, Serializable};
|
||||
|
||||
use super::*;
|
||||
use super::{Felt, LeafIndex, NodeIndex, Rpo256, RpoDigest, Smt, SmtLeaf, EMPTY_WORD, SMT_DEPTH};
|
||||
use crate::{
|
||||
merkle::{EmptySubtreeRoots, MerkleStore},
|
||||
utils::collections::Vec,
|
||||
ONE, WORD_SIZE,
|
||||
utils::{collections::*, Deserializable, Serializable},
|
||||
Word, ONE, WORD_SIZE,
|
||||
};
|
||||
|
||||
// SMT
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use super::{EmptySubtreeRoots, InnerNodeInfo, MerkleError, MerklePath, NodeIndex};
|
||||
use crate::{
|
||||
hash::rpo::{Rpo256, RpoDigest},
|
||||
Word,
|
||||
utils::collections::*,
|
||||
Felt, Word, EMPTY_WORD,
|
||||
};
|
||||
|
||||
use super::{EmptySubtreeRoots, MerkleError, MerklePath, NodeIndex, Vec};
|
||||
|
||||
mod full;
|
||||
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::{
|
||||
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,
|
||||
};
|
||||
use crate::utils::collections::{BTreeMap, BTreeSet};
|
||||
use crate::utils::collections::*;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{
|
||||
digests_to_words, int_to_leaf, int_to_node, smt::SparseMerkleTree, EmptySubtreeRoots,
|
||||
InnerNodeInfo, LeafIndex, MerkleTree,
|
||||
},
|
||||
utils::collections::Vec,
|
||||
utils::collections::*,
|
||||
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 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)]
|
||||
mod tests;
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use seq_macro::seq;
|
||||
|
||||
use super::{
|
||||
DefaultMerkleStore as MerkleStore, EmptySubtreeRoots, MerkleError, MerklePath, NodeIndex,
|
||||
PartialMerkleTree, RecordingMerkleStore, Rpo256, RpoDigest,
|
||||
@@ -10,12 +12,10 @@ use crate::{
|
||||
};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use super::{Deserializable, Serializable};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use std::error::Error;
|
||||
|
||||
use seq_macro::seq;
|
||||
use {
|
||||
super::{Deserializable, Serializable},
|
||||
std::error::Error,
|
||||
};
|
||||
|
||||
// TEST DATA
|
||||
// ================================================================================================
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Pseudo-random element generation.
|
||||
|
||||
pub use winter_crypto::{DefaultRandomCoin as WinterRandomCoin, RandomCoin, RandomCoinError};
|
||||
pub use winter_utils::Randomizable;
|
||||
|
||||
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::{
|
||||
hash::rpo::{Rpo256, RpoDigest},
|
||||
utils::{
|
||||
collections::Vec, string::ToString, vec, ByteReader, ByteWriter, Deserializable,
|
||||
collections::*, string::*, vec, ByteReader, ByteWriter, Deserializable,
|
||||
DeserializationError, Serializable,
|
||||
},
|
||||
};
|
||||
pub use winter_crypto::{RandomCoin, RandomCoinError};
|
||||
|
||||
// CONSTANTS
|
||||
// ================================================================================================
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use core::cell::RefCell;
|
||||
use winter_utils::{
|
||||
collections::{btree_map::IntoIter, BTreeMap, BTreeSet},
|
||||
Box,
|
||||
|
||||
use super::{
|
||||
boxed::*,
|
||||
collections::{btree_map::*, *},
|
||||
};
|
||||
|
||||
// KEY-VALUE MAP TRAIT
|
||||
|
||||
@@ -1,26 +1,29 @@
|
||||
//! Utilities used in this crate which can also be generally useful downstream.
|
||||
|
||||
use super::{utils::string::String, Word};
|
||||
use core::fmt::{self, Display, Write};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::{format, vec};
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
pub use alloc::{format, vec};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::{format, vec};
|
||||
use super::Word;
|
||||
use crate::utils::string::*;
|
||||
|
||||
mod kv_map;
|
||||
|
||||
// RE-EXPORTS
|
||||
// ================================================================================================
|
||||
pub use winter_utils::{
|
||||
string, uninit_vector, Box, ByteReader, ByteWriter, Deserializable, DeserializationError,
|
||||
Serializable, SliceReader,
|
||||
boxed, string, uninit_vector, Box, ByteReader, ByteWriter, Deserializable,
|
||||
DeserializationError, Serializable, SliceReader,
|
||||
};
|
||||
|
||||
pub mod collections {
|
||||
pub use super::kv_map::*;
|
||||
pub use winter_utils::collections::*;
|
||||
|
||||
pub use super::kv_map::*;
|
||||
}
|
||||
|
||||
// UTILITY FUNCTIONS
|
||||
|
||||
Reference in New Issue
Block a user