mirror of
https://github.com/arnaucube/miden-crypto.git
synced 2026-01-12 17:11:28 +01:00
Compare commits
2 Commits
v0.8.2
...
km/mkdocs-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03639148d7 | ||
|
|
d8cf98a0b5 |
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,9 +1,4 @@
|
||||
# 0.8.2 (2024-03-17)
|
||||
|
||||
* Updated `no-std` approach to be in sync with winterfell v0.8.3 release (#290).
|
||||
|
||||
## 0.8.1 (2024-02-21)
|
||||
|
||||
* Fixed clippy warnings (#280)
|
||||
|
||||
## 0.8.0 (2024-02-14)
|
||||
|
||||
10
Cargo.toml
10
Cargo.toml
@@ -1,12 +1,12 @@
|
||||
[package]
|
||||
name = "miden-crypto"
|
||||
version = "0.8.2"
|
||||
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.2"
|
||||
documentation = "https://docs.rs/miden-crypto/0.8.1"
|
||||
categories = ["cryptography", "no-std"]
|
||||
keywords = ["miden", "crypto", "hash", "merkle"]
|
||||
edition = "2021"
|
||||
@@ -38,6 +38,7 @@ serde = ["dep:serde", "serde?/alloc", "winter_math/serde"]
|
||||
std = [
|
||||
"blake3/std",
|
||||
"dep:cc",
|
||||
"dep:libc",
|
||||
"winter_crypto/std",
|
||||
"winter_math/std",
|
||||
"winter_utils/std",
|
||||
@@ -46,10 +47,9 @@ std = [
|
||||
[dependencies]
|
||||
blake3 = { version = "1.5", default-features = false }
|
||||
clap = { version = "4.5", features = ["derive"], optional = true }
|
||||
libc = { version = "0.2", default-features = false, optional = true }
|
||||
rand_utils = { version = "0.8", package = "winter-rand-utils", optional = true }
|
||||
serde = { version = "1.0", features = [
|
||||
"derive",
|
||||
], default-features = false, optional = true }
|
||||
serde = { version = "1.0", features = ["derive"], default-features = false, optional = true }
|
||||
winter_crypto = { version = "0.8", package = "winter-crypto", default-features = false }
|
||||
winter_math = { version = "0.8", package = "winter-math", default-features = false }
|
||||
winter_utils = { version = "0.8", package = "winter-utils", default-features = false }
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 Polygon Miden
|
||||
Copyright (c) 2023 Polygon Miden
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
# Miden Crypto
|
||||
<a href="https://github.com/0xPolygonMiden/miden-crypto/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
|
||||
<a href="https://github.com/0xPolygonMiden/crypto/actions/workflows/ci.yml"><img src="https://github.com/0xPolygonMiden/crypto/actions/workflows/ci.yml/badge.svg?branch=main"></a>
|
||||
<img src="https://img.shields.io/badge/rustc-1.75+-lightgray.svg">
|
||||
<a href="https://crates.io/crates/miden-crypto"><img src="https://img.shields.io/crates/v/miden-crypto"></a>
|
||||
|
||||
This crate contains cryptographic primitives used in Polygon Miden.
|
||||
|
||||
## Hash
|
||||
|
||||
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,4 +1,4 @@
|
||||
use core::ffi::c_int;
|
||||
use libc::c_int;
|
||||
|
||||
// C IMPLEMENTATION INTERFACE
|
||||
// ================================================================================================
|
||||
@@ -77,11 +77,8 @@ extern "C" {
|
||||
#[cfg(test)]
|
||||
pub fn rpo128_absorb(
|
||||
sc: *mut Rpo128Context,
|
||||
data: *const core::ffi::c_void,
|
||||
// TODO: When #![feature(c_size_t)] stabilizes, switch this to `core::ffi::size_t` to be
|
||||
// more accurate. Currently, however, all Rust targets as of this writing are such that
|
||||
// `core::ffi::size_t` and `usize` are the same size.
|
||||
len: usize,
|
||||
data: *const ::std::os::raw::c_void,
|
||||
len: libc::size_t,
|
||||
);
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -99,7 +96,6 @@ pub struct Rpo128Context {
|
||||
|
||||
#[cfg(all(test, feature = "std"))]
|
||||
mod tests {
|
||||
use alloc::vec::Vec;
|
||||
use rand_utils::{rand_array, rand_value, rand_vector};
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
#[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},
|
||||
alloc::vec::Vec,
|
||||
};
|
||||
|
||||
// PUBLIC KEY
|
||||
// ================================================================================================
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use alloc::vec::Vec;
|
||||
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,4 +1,3 @@
|
||||
use alloc::string::ToString;
|
||||
use core::cell::OnceCell;
|
||||
|
||||
use super::{
|
||||
@@ -6,6 +5,7 @@ use super::{
|
||||
Polynomial, PublicKeyBytes, Rpo256, Serializable, SignatureBytes, Word, MODULUS, N,
|
||||
SIG_L2_BOUND, ZERO,
|
||||
};
|
||||
use crate::utils::string::*;
|
||||
|
||||
// FALCON SIGNATURE
|
||||
// ================================================================================================
|
||||
@@ -196,7 +196,7 @@ fn decode_nonce(nonce: &NonceBytes) -> NonceElements {
|
||||
|
||||
#[cfg(all(test, feature = "std"))]
|
||||
mod tests {
|
||||
use core::ffi::c_void;
|
||||
use libc::c_void;
|
||||
use rand_utils::rand_vector;
|
||||
|
||||
use super::{
|
||||
@@ -236,10 +236,7 @@ mod tests {
|
||||
fn test_hash_to_point() {
|
||||
// Create a random message and transform it into a u8 vector
|
||||
let msg_felts: Word = rand_vector::<Felt>(4).try_into().unwrap();
|
||||
let msg_bytes = msg_felts
|
||||
.iter()
|
||||
.flat_map(|e| e.as_int().to_le_bytes())
|
||||
.collect::<alloc::vec::Vec<_>>();
|
||||
let msg_bytes = msg_felts.iter().flat_map(|e| e.as_int().to_le_bytes()).collect::<Vec<_>>();
|
||||
|
||||
// Create a nonce i.e. a [u8; 40] array and pack into a [Felt; 8] array.
|
||||
let nonce: [u8; 40] = rand_vector::<u8>(40).try_into().unwrap();
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use alloc::string::String;
|
||||
use core::{
|
||||
mem::{size_of, transmute, transmute_copy},
|
||||
ops::Deref,
|
||||
@@ -7,7 +6,7 @@ use core::{
|
||||
|
||||
use super::{Digest, ElementHasher, Felt, FieldElement, Hasher};
|
||||
use crate::utils::{
|
||||
bytes_to_hex_string, hex_to_bytes, ByteReader, ByteWriter, Deserializable,
|
||||
bytes_to_hex_string, hex_to_bytes, string::*, ByteReader, ByteWriter, Deserializable,
|
||||
DeserializationError, HexParseError, Serializable,
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ use proptest::prelude::*;
|
||||
use rand_utils::rand_vector;
|
||||
|
||||
use super::*;
|
||||
use alloc::vec::Vec;
|
||||
use crate::utils::collections::*;
|
||||
|
||||
#[test]
|
||||
fn blake3_hash_elements() {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
use alloc::string::String;
|
||||
use core::{cmp::Ordering, fmt::Display, ops::Deref};
|
||||
|
||||
use super::{Digest, Felt, StarkField, DIGEST_BYTES, DIGEST_SIZE, ZERO};
|
||||
use crate::{
|
||||
rand::Randomizable,
|
||||
utils::{
|
||||
bytes_to_hex_string, hex_to_bytes, ByteReader, ByteWriter, Deserializable,
|
||||
bytes_to_hex_string, hex_to_bytes, string::*, ByteReader, ByteWriter, Deserializable,
|
||||
DeserializationError, HexParseError, Serializable,
|
||||
},
|
||||
};
|
||||
@@ -324,11 +323,10 @@ impl IntoIterator for RpoDigest {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use alloc::string::String;
|
||||
use rand_utils::rand_value;
|
||||
|
||||
use super::{Deserializable, Felt, RpoDigest, Serializable, DIGEST_BYTES, DIGEST_SIZE};
|
||||
use crate::utils::SliceReader;
|
||||
use crate::utils::{string::*, SliceReader};
|
||||
|
||||
#[test]
|
||||
fn digest_serialization() {
|
||||
|
||||
@@ -5,8 +5,7 @@ use super::{
|
||||
super::{apply_inv_sbox, apply_sbox, ALPHA, INV_ALPHA},
|
||||
Felt, FieldElement, Hasher, Rpo256, RpoDigest, StarkField, ONE, STATE_WIDTH, ZERO,
|
||||
};
|
||||
use crate::Word;
|
||||
use alloc::{collections::BTreeSet, vec::Vec};
|
||||
use crate::{utils::collections::*, Word};
|
||||
|
||||
#[test]
|
||||
fn test_sbox() {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
use alloc::string::String;
|
||||
use core::{cmp::Ordering, fmt::Display, ops::Deref};
|
||||
|
||||
use super::{Digest, Felt, StarkField, DIGEST_BYTES, DIGEST_SIZE, ZERO};
|
||||
use crate::{
|
||||
rand::Randomizable,
|
||||
utils::{
|
||||
bytes_to_hex_string, hex_to_bytes, ByteReader, ByteWriter, Deserializable,
|
||||
bytes_to_hex_string, hex_to_bytes, string::*, ByteReader, ByteWriter, Deserializable,
|
||||
DeserializationError, HexParseError, Serializable,
|
||||
},
|
||||
};
|
||||
@@ -313,11 +312,10 @@ impl Deserializable for RpxDigest {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use alloc::string::String;
|
||||
use rand_utils::rand_value;
|
||||
|
||||
use super::{Deserializable, Felt, RpxDigest, Serializable, DIGEST_BYTES, DIGEST_SIZE};
|
||||
use crate::utils::SliceReader;
|
||||
use crate::utils::{string::*, SliceReader};
|
||||
|
||||
#[test]
|
||||
fn digest_serialization() {
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#![no_std]
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
#[macro_use]
|
||||
#[cfg(not(feature = "std"))]
|
||||
#[cfg_attr(test, macro_use)]
|
||||
extern crate alloc;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
extern crate std;
|
||||
|
||||
pub mod dsa;
|
||||
pub mod hash;
|
||||
pub mod merkle;
|
||||
|
||||
@@ -74,7 +74,7 @@ pub fn insertion(tree: &mut Smt, size: u64) -> Result<(), MerkleError> {
|
||||
println!(
|
||||
"An average insertion time measured by 20 inserts into a SMT with {} key-value pairs is {:.3} milliseconds\n",
|
||||
size,
|
||||
// calculate the average by dividing by 20 and convert to milliseconds by multiplying by
|
||||
// calculate the average by dividing by 20 and convert to milliseconds by multiplying by
|
||||
// 1000. As a result, we can only multiply by 50
|
||||
insertion_times.iter().sum::<f32>() * 50f32,
|
||||
);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use alloc::vec::Vec;
|
||||
use core::fmt;
|
||||
|
||||
use super::{smt::SmtLeafError, MerklePath, NodeIndex, RpoDigest};
|
||||
use crate::utils::collections::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum MerkleError {
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
use alloc::{string::String, vec::Vec};
|
||||
use core::{fmt, ops::Deref, slice};
|
||||
|
||||
use winter_math::log2;
|
||||
|
||||
use super::{InnerNodeInfo, MerkleError, MerklePath, NodeIndex, Rpo256, RpoDigest, Word};
|
||||
use crate::utils::{uninit_vector, word_to_hex};
|
||||
use crate::utils::{collections::*, string::*, uninit_vector, word_to_hex};
|
||||
|
||||
// MERKLE TREE
|
||||
// ================================================================================================
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::super::RpoDigest;
|
||||
use alloc::vec::Vec;
|
||||
use crate::utils::collections::*;
|
||||
|
||||
/// Container for the update data of a [super::PartialMmr]
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -16,7 +16,7 @@ use super::{
|
||||
leaf_to_corresponding_tree, nodes_in_forest, MmrDelta, MmrError, MmrPeaks, MmrProof, Rpo256,
|
||||
RpoDigest,
|
||||
};
|
||||
use alloc::vec::Vec;
|
||||
use crate::utils::collections::*;
|
||||
|
||||
// MMR
|
||||
// ===============================================================================================
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
use super::{MmrDelta, MmrProof, Rpo256, RpoDigest};
|
||||
use crate::merkle::{
|
||||
mmr::{leaf_to_corresponding_tree, nodes_in_forest},
|
||||
InOrderIndex, InnerNodeInfo, MerklePath, MmrError, MmrPeaks,
|
||||
};
|
||||
use alloc::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
vec::Vec,
|
||||
use crate::{
|
||||
merkle::{
|
||||
mmr::{leaf_to_corresponding_tree, nodes_in_forest},
|
||||
InOrderIndex, InnerNodeInfo, MerklePath, MmrError, MmrPeaks,
|
||||
},
|
||||
utils::{collections::*, vec},
|
||||
};
|
||||
|
||||
// TYPE ALIASES
|
||||
@@ -617,8 +616,10 @@ mod tests {
|
||||
forest_to_rightmost_index, forest_to_root_index, InOrderIndex, MmrPeaks, PartialMmr,
|
||||
RpoDigest,
|
||||
};
|
||||
use crate::merkle::{int_to_node, MerkleStore, Mmr, NodeIndex};
|
||||
use alloc::{collections::BTreeSet, vec::Vec};
|
||||
use crate::{
|
||||
merkle::{int_to_node, MerkleStore, Mmr, NodeIndex},
|
||||
utils::collections::*,
|
||||
};
|
||||
|
||||
const LEAVES: [RpoDigest; 7] = [
|
||||
int_to_node(0),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::{super::ZERO, Felt, MmrError, MmrProof, Rpo256, RpoDigest, Word};
|
||||
use alloc::vec::Vec;
|
||||
use crate::utils::collections::*;
|
||||
|
||||
// MMR PEAKS
|
||||
// ================================================================================================
|
||||
|
||||
@@ -6,9 +6,9 @@ use super::{
|
||||
};
|
||||
use crate::{
|
||||
merkle::{int_to_node, InOrderIndex, MerklePath, MerkleTree, MmrProof, NodeIndex},
|
||||
utils::collections::*,
|
||||
Felt, Word,
|
||||
};
|
||||
use alloc::vec::Vec;
|
||||
|
||||
#[test]
|
||||
fn test_position_equal_or_higher_than_leafs_is_never_contained() {
|
||||
|
||||
@@ -44,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])
|
||||
@@ -55,6 +58,6 @@ const fn int_to_leaf(value: u64) -> Word {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn digests_to_words(digests: &[RpoDigest]) -> alloc::vec::Vec<Word> {
|
||||
fn digests_to_words(digests: &[RpoDigest]) -> Vec<Word> {
|
||||
digests.iter().map(|d| d.into()).collect()
|
||||
}
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
use alloc::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
string::String,
|
||||
vec::Vec,
|
||||
};
|
||||
use core::fmt;
|
||||
|
||||
use super::{
|
||||
@@ -10,7 +5,8 @@ use super::{
|
||||
EMPTY_WORD,
|
||||
};
|
||||
use crate::utils::{
|
||||
word_to_hex, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
|
||||
collections::*, format, string::*, vec, word_to_hex, ByteReader, ByteWriter, Deserializable,
|
||||
DeserializationError, Serializable,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -5,7 +5,7 @@ use super::{
|
||||
},
|
||||
Deserializable, InnerNodeInfo, RpoDigest, Serializable, ValuePath,
|
||||
};
|
||||
use alloc::{collections::BTreeMap, vec::Vec};
|
||||
use crate::utils::collections::*;
|
||||
|
||||
// TEST DATA
|
||||
// ================================================================================================
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use alloc::vec::Vec;
|
||||
use core::ops::{Deref, DerefMut};
|
||||
|
||||
use super::{InnerNodeInfo, MerkleError, NodeIndex, Rpo256, RpoDigest};
|
||||
use crate::{
|
||||
utils::{ByteReader, Deserializable, DeserializationError, Serializable},
|
||||
utils::{collections::*, ByteReader, Deserializable, DeserializationError, Serializable},
|
||||
Word,
|
||||
};
|
||||
|
||||
@@ -129,7 +128,7 @@ impl FromIterator<RpoDigest> for MerklePath {
|
||||
|
||||
impl IntoIterator for MerklePath {
|
||||
type Item = RpoDigest;
|
||||
type IntoIter = alloc::vec::IntoIter<RpoDigest>;
|
||||
type IntoIter = vec::IntoIter<RpoDigest>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.nodes.into_iter()
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use alloc::vec::Vec;
|
||||
use core::fmt;
|
||||
|
||||
use crate::{
|
||||
hash::rpo::RpoDigest,
|
||||
merkle::{LeafIndex, SMT_DEPTH},
|
||||
utils::collections::*,
|
||||
Word,
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
use alloc::{string::ToString, vec::Vec};
|
||||
use core::cmp::Ordering;
|
||||
|
||||
use super::{Felt, LeafIndex, Rpo256, RpoDigest, SmtLeafError, Word, EMPTY_WORD, SMT_DEPTH};
|
||||
use crate::utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable};
|
||||
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))]
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::{
|
||||
EmptySubtreeRoots, Felt, InnerNode, InnerNodeInfo, LeafIndex, MerkleError, MerklePath,
|
||||
NodeIndex, Rpo256, RpoDigest, SparseMerkleTree, Word, EMPTY_WORD,
|
||||
};
|
||||
use alloc::collections::{BTreeMap, BTreeSet};
|
||||
use crate::utils::collections::*;
|
||||
|
||||
mod error;
|
||||
pub use error::{SmtLeafError, SmtProofError};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use super::{MerklePath, RpoDigest, SmtLeaf, SmtProofError, Word, SMT_DEPTH};
|
||||
use crate::utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable};
|
||||
use alloc::string::ToString;
|
||||
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`].
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
use super::{Felt, LeafIndex, NodeIndex, Rpo256, RpoDigest, Smt, SmtLeaf, EMPTY_WORD, SMT_DEPTH};
|
||||
use crate::{
|
||||
merkle::{EmptySubtreeRoots, MerkleStore},
|
||||
utils::{Deserializable, Serializable},
|
||||
utils::{collections::*, Deserializable, Serializable},
|
||||
Word, ONE, WORD_SIZE,
|
||||
};
|
||||
use alloc::vec::Vec;
|
||||
|
||||
// SMT
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use super::{EmptySubtreeRoots, InnerNodeInfo, MerkleError, MerklePath, NodeIndex};
|
||||
use crate::{
|
||||
hash::rpo::{Rpo256, RpoDigest},
|
||||
utils::collections::*,
|
||||
Felt, Word, EMPTY_WORD,
|
||||
};
|
||||
use alloc::vec::Vec;
|
||||
|
||||
mod full;
|
||||
pub use full::{Smt, SmtLeaf, SmtLeafError, SmtProof, SmtProofError, SMT_DEPTH};
|
||||
|
||||
@@ -3,7 +3,7 @@ use super::{
|
||||
MerklePath, NodeIndex, RpoDigest, SparseMerkleTree, Word, EMPTY_WORD, SMT_MAX_DEPTH,
|
||||
SMT_MIN_DEPTH,
|
||||
};
|
||||
use alloc::collections::{BTreeMap, BTreeSet};
|
||||
use crate::utils::collections::*;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
@@ -8,9 +8,9 @@ use crate::{
|
||||
digests_to_words, int_to_leaf, int_to_node, smt::SparseMerkleTree, EmptySubtreeRoots,
|
||||
InnerNodeInfo, LeafIndex, MerkleTree,
|
||||
},
|
||||
utils::collections::*,
|
||||
Word, EMPTY_WORD,
|
||||
};
|
||||
use alloc::vec::Vec;
|
||||
|
||||
// TEST DATA
|
||||
// ================================================================================================
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use alloc::{collections::BTreeMap, vec::Vec};
|
||||
use core::borrow::Borrow;
|
||||
|
||||
use super::{
|
||||
@@ -6,8 +5,7 @@ use super::{
|
||||
PartialMerkleTree, RootPath, Rpo256, RpoDigest, SimpleSmt, Smt, ValuePath,
|
||||
};
|
||||
use crate::utils::{
|
||||
collections::{KvMap, RecordingMap},
|
||||
ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
|
||||
collections::*, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -14,7 +14,6 @@ use crate::{
|
||||
#[cfg(feature = "std")]
|
||||
use {
|
||||
super::{Deserializable, Serializable},
|
||||
alloc::boxed::Box,
|
||||
std::error::Error,
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
use super::{Felt, FeltRng, FieldElement, RandomCoin, RandomCoinError, Word, ZERO};
|
||||
use crate::{
|
||||
hash::rpo::{Rpo256, RpoDigest},
|
||||
utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable},
|
||||
utils::{
|
||||
collections::*, string::*, vec, ByteReader, ByteWriter, Deserializable,
|
||||
DeserializationError, Serializable,
|
||||
},
|
||||
};
|
||||
use alloc::{string::ToString, vec::Vec};
|
||||
|
||||
// CONSTANTS
|
||||
// ================================================================================================
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use alloc::{
|
||||
boxed::Box,
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
};
|
||||
use core::cell::RefCell;
|
||||
|
||||
use super::{
|
||||
boxed::*,
|
||||
collections::{btree_map::*, *},
|
||||
};
|
||||
|
||||
// KEY-VALUE MAP TRAIT
|
||||
// ================================================================================================
|
||||
|
||||
@@ -201,7 +202,7 @@ impl<K: Clone + Ord, V: Clone> FromIterator<(K, V)> for RecordingMap<K, V> {
|
||||
|
||||
impl<K: Clone + Ord, V: Clone> IntoIterator for RecordingMap<K, V> {
|
||||
type Item = (K, V);
|
||||
type IntoIter = alloc::collections::btree_map::IntoIter<K, V>;
|
||||
type IntoIter = IntoIter<K, V>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.data.into_iter()
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
//! Utilities used in this crate which can also be generally useful downstream.
|
||||
|
||||
use alloc::string::String;
|
||||
use core::fmt::{self, Display, Write};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use std::{format, vec};
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
pub use alloc::{format, vec};
|
||||
|
||||
use super::Word;
|
||||
use crate::utils::string::*;
|
||||
|
||||
mod kv_map;
|
||||
|
||||
@@ -15,6 +21,8 @@ pub use winter_utils::{
|
||||
};
|
||||
|
||||
pub mod collections {
|
||||
pub use winter_utils::collections::*;
|
||||
|
||||
pub use super::kv_map::*;
|
||||
}
|
||||
|
||||
@@ -94,11 +102,12 @@ pub fn hex_to_bytes<const N: usize>(value: &str) -> Result<[u8; N], HexParseErro
|
||||
});
|
||||
|
||||
let mut decoded = [0u8; N];
|
||||
for byte in decoded.iter_mut() {
|
||||
#[allow(clippy::needless_range_loop)]
|
||||
for pos in 0..N {
|
||||
// These `unwrap` calls are okay because the length was checked above
|
||||
let high: u8 = data.next().unwrap()?;
|
||||
let low: u8 = data.next().unwrap()?;
|
||||
*byte = (high << 4) + low;
|
||||
decoded[pos] = (high << 4) + low;
|
||||
}
|
||||
|
||||
Ok(decoded)
|
||||
|
||||
Reference in New Issue
Block a user