Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ jobs:
run: cargo doc --no-deps

msrv:
name: Verify MSRV (1.96)
name: Verify MSRV (1.99)
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install Rust Toolchain (1.96)
uses: dtolnay/rust-toolchain@1.96.0
- name: Install Rust Toolchain (1.99)
uses: dtolnay/rust-toolchain@1.99.0

- name: Pin pkcs1 to 0.8.0-rc.4
# Same mitigation as in the build job: sad-rsa 0.2.3 fails to compile
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project are documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.3.0] - 2026-10-08

### Changed

- Migrated the crate to multi-hash 2.0. The three preimage-hash sites — the `check_preimage` binary and string arms in `vm/context.rs` and `MulticodecHashVerifier::verify_preimage` in `adapters/multicodec_crypto.rs` — moved from the removed `Builder::new_from_bytes` one-shot to the streaming shape (`Builder::new` plus `update` and `try_build`). Each site pins `.output_len(32)`, the digest length multi-hash 1.1 produced, so stored preimage hashes keep their bytes; blake3 is an extendable-output codec and requires the length, and fixed-output codecs ignore it. The `ALLOWED_HASH_CODECS` whitelist and its fail-closed behavior are unchanged.
- Updated dependencies: `multi-hash` 1.1 → 2.0, `multi-key` 2.1 → 2.2, `multi-cid` 0.2 → 0.3. The graph resolves a single multi-hash major: 2.0.1, which declares `rust-version = "1.99"`. The `multi-key` raise is required for type coherence: `check_preimage_value` compares `fingerprint()` results with this crate's multi-hash-2-typed `Multihash`. `Cid` is opaque in this crate, so the `multi-cid` raise is a coherence choice.
- Added two preimage regression tests: one asserts the recomputed blake3-256 multihash matches the bytes recorded under multi-hash 1.1; one asserts a truncated stored digest still fails closed. No public API changes.

## [2.2.1] - 2026-10-07

### Changed
Expand Down Expand Up @@ -103,6 +111,7 @@ different from 1.0.5.

- Previous standalone release. Used `wasmtime 19.0`, `thiserror 1.0`, and FSL-1.1 license. Git deps for `multicid`, `multihash`, `multikey`, `multisig`, `multitrait`, `multiutil`.

[2.3.0]: https://github.com/cryptidtech/wacc/compare/v2.2.1...v2.3.0
[2.2.1]: https://github.com/cryptidtech/wacc/compare/v2.2.0...v2.2.1
[2.2.0]: https://github.com/cryptidtech/wacc/compare/v2.1.2...v2.2.0
[2.1.1]: https://github.com/cryptidtech/wacc/compare/v2.1.0...v2.1.1
Expand Down
18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "wacc"
version = "2.2.1"
version = "2.3.0"
edition = "2021"
rust-version = "1.96"
rust-version = "1.99"
authors = ["Dave Grantham <dwg@linuxprogrammer.org>"]
description = "Web Assembly Cryptographic Constructs VM implementation"
repository = "https://github.com/cryptidtech/wacc.git"
Expand All @@ -14,13 +14,13 @@ categories = ["cryptography", "wasm"]
[dependencies]
blake3 = { version = "1.8", features = ["traits-preview"] }
log = "0.4"
multi-cid = "0.2"
multi-codec = "1.5"
multi-hash = "1.1"
multi-key = "2.1"
multi-sig = "1.5"
multi-trait = "1.0"
multi-util = "1.1"
multi-cid = "0.3"
multi-codec = "1.6"
multi-hash = "2.0"
multi-key = "2.2"
multi-sig = "1.6"
multi-trait = "1.1"
multi-util = "1.2"
thiserror = "2.0"
tracing = "0.1"
wasmtime = { version = "49.0", default-features = false, features = [
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Add this to your `Cargo.toml`:
wacc = "0.1"
```

MSRV: Rust 1.85.
MSRV: Rust 1.99.

## Usage

Expand Down
12 changes: 9 additions & 3 deletions src/adapters/multicodec_crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ impl HashVerifier for MulticodecHashVerifier {
)));
}

// Compute hash of preimage using same algorithm
let computed = mh::Builder::new_from_bytes(hash.codec(), preimage)
.map_err(|e| CryptoError::Other(format!("Failed to hash preimage: {e}")))?
// Compute hash of preimage using same algorithm. The builder pins a
// 32-byte digest: extendable-output codecs require a length, and 32 is
// the length multi-hash 1.x produced, so stored hashes keep their
// bytes. Fixed-output codecs ignore the setting.
let mut builder = mh::Builder::new(hash.codec())
.map_err(|e| CryptoError::Other(format!("Failed to hash preimage: {e}")))?;
builder.update(preimage);
builder.output_len(32);
let computed = builder
.try_build()
.map_err(|e| CryptoError::Other(format!("Failed to build hash: {e}")))?;

Expand Down
33 changes: 20 additions & 13 deletions src/vm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,27 +291,34 @@ impl Context {
));
}

// get the preimage data from the stack
// get the preimage data from the stack. The builder pins a 32-byte
// digest: extendable-output codecs require a length, and 32 is the
// length multi-hash 1.x produced, so stored hashes keep their bytes.
// Fixed-output codecs ignore the setting.
let preimage = {
match self.pstack.top() {
Some(Value::Bin { hint: _, data }) => {
match mh::Builder::new_from_bytes(hash.codec(), data.as_ref()) {
Ok(builder) => match builder.try_build() {
Some(Value::Bin { hint: _, data }) => match mh::Builder::new(hash.codec()) {
Ok(mut builder) => {
builder.update(data.as_ref());
builder.output_len(32);
match builder.try_build() {
Ok(hash) => hash,
Err(e) => return self.check_fail(&e.to_string()),
},
Err(e) => return self.check_fail(&e.to_string()),
}
}
}
Some(Value::Str { hint: _, data }) => {
match mh::Builder::new_from_bytes(hash.codec(), data.as_ref().as_bytes()) {
Ok(builder) => match builder.try_build() {
Err(e) => return self.check_fail(&e.to_string()),
},
Some(Value::Str { hint: _, data }) => match mh::Builder::new(hash.codec()) {
Ok(mut builder) => {
builder.update(data.as_ref().as_bytes());
builder.output_len(32);
match builder.try_build() {
Ok(hash) => hash,
Err(e) => return self.check_fail(&e.to_string()),
},
Err(e) => return self.check_fail(&e.to_string()),
}
}
}
Err(e) => return self.check_fail(&e.to_string()),
},
_ => return self.check_fail("no multihash data on stack"),
}
};
Expand Down
39 changes: 39 additions & 0 deletions tests/preimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,42 @@ fn test_preimage_wasm() {
assert_eq!(context.rstack.top(), Some(Value::Success(0)));
}
}

/// A blake3-256 preimage recorded under multi-hash 1.x. The `1e 20` prefix
/// pins the codec and the 32-byte digest that version produced. The stored
/// bytes must stay identical after the streaming-builder migration so stored
/// preimage checks keep succeeding against stored hashes.
const BLAKE3_PREIMAGE: &[u8] = b"for great justice";
const BLAKE3_PREIMAGE_MH_HEX: &str =
"1e203968072b77e9d76ef401cceb94daccf582c928cde470fac6505200f35e7a8c7b";

#[test]
fn test_blake3_preimage_bytes_preserved() {
use multi_codec::Codec;
use multi_hash::mh;

// The streaming builder must pin the digest length for an
// extendable-output codec. 32 bytes is the length multi-hash 1.x produced.
let mut builder = mh::Builder::new(Codec::Blake3).expect("blake3 is a hash codec");
builder.update(BLAKE3_PREIMAGE);
builder.output_len(32);
let computed = builder.try_build().expect("the digest length is valid");
let recorded = hex::decode(BLAKE3_PREIMAGE_MH_HEX).expect("recorded bytes parse");
assert_eq!(Vec::<u8>::from(computed), recorded);
}

#[test]
fn test_truncated_blake3_digest_fails_closed() {
use wacc::adapters::multicodec_crypto::MulticodecHashVerifier;
use wacc::ports::crypto::HashVerifier;

// A stored blake3 digest cut short must keep failing the check, exactly as
// under multi-hash 1.x: the length prefix still claims 32 digest bytes.
let mut stored = hex::decode(BLAKE3_PREIMAGE_MH_HEX).expect("recorded bytes parse");
stored.pop();
let verifier = MulticodecHashVerifier;
assert!(
verifier.verify_preimage(&stored, BLAKE3_PREIMAGE).is_err(),
"a truncated stored digest must fail closed"
);
}
Loading