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
17 changes: 17 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ jobs:
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
targets: wasm32-wasip2

- name: Pin pkcs1 to 0.8.0-rc.4
# sad-rsa 0.2.3 (pulled in through multi-key) fails to compile against
# pkcs1 0.8.0-rc.5, which added a type parameter to RsaPublicKey.
# Pin the last working pkcs1 pre-release until sad-rsa ships a release
# compatible with it, then remove this step.
run: cargo update -p pkcs1 --precise 0.8.0-rc.4

- name: Check Code Format
run: cargo fmt --all -- --check
Expand All @@ -30,6 +38,9 @@ jobs:
- name: Build
run: cargo build --verbose

- name: Build Script Fixtures
run: make -C examples/wacc/wast guests

- name: Run tests
run: cargo test --verbose

Expand All @@ -46,5 +57,11 @@ jobs:
- name: Install Rust Toolchain (1.96)
uses: dtolnay/rust-toolchain@1.96.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
# against pkcs1 0.8.0-rc.5. Remove this step when sad-rsa ships a
# compatible release.
run: cargo update -p pkcs1 --precise 0.8.0-rc.4

- name: Check
run: cargo check
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ 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.2.0] - 2026-10-06

### Added

- WASM Component Model support for scripts. An added `wit/wacc.wit` declares the WIT package `cryptid:wacc@1.0.0` with the typed `host` interface and the two script worlds `unlock-script` (export `for-great-justice`) and `lock-script` (export `move-every-zig`); the eight typed host functions carry the same semantics as the eight raw-ABI core-module imports, and the component path also accepts the legacy snake-case export names through the added export-name map.
- `ScriptKind` with the variants `Module` and `Component`, and `ScriptKind::detect(bytes)`: binary detection by the version byte after the `\0asm` magic and text detection by the leading WAT token. Re-exported from the crate root.
- A blake3-keyed component cache in the public `ModuleCache` (`insert_component_bytes` / `get_component_bytes`, a second bounded map) and the `Runtime::cached_component_count()` accessor; component compilation runs through the internal `Runtime::compile_component`, mirroring the internal `Runtime::compile` on the module path.
- `Builder::with_component_bytes` and `Builder::try_build_component`, producing a `vm::ComponentInstance` with a public `store`, `run`, and `log`, mirroring the module path's fuel and store-limit flow. Typed host imports are generated with `wasmtime::component::bindgen!` and registered once on the runtime's component linker for both worlds, so script components import only `cryptid:wacc/host@1.0.0`.

### Changed

- The `wasmtime` dependency gains the `component-model` feature; the dependency stays at version `48.0`.
- `Builder::try_build` now rejects detectable component bytes with `VmError::ScriptKindMismatch` instead of a generic compilation error, and `Builder::try_build_component` rejects detectable module bytes symmetrically.

### Notes

- 2.1.2 shipped without a changelog entry.

## [2.1.1] - 2026-09-02

### Changed
Expand Down Expand Up @@ -78,6 +96,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.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
[2.1.0]: https://github.com/cryptidtech/wacc/compare/v2.0.0...v2.1.0
[2.0.0]: https://github.com/cryptidtech/wacc/releases/tag/v2.0.0
Expand Down
18 changes: 12 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wacc"
version = "2.1.2"
version = "2.2.0"
edition = "2021"
rust-version = "1.96"
authors = ["Dave Grantham <dwg@linuxprogrammer.org>"]
Expand All @@ -12,18 +12,19 @@ keywords = ["wasm", "cryptographic", "vm", "provenance", "scripting"]
categories = ["cryptography", "wasm"]

[dependencies]
blake3 = { version = "1.8.1", features = ["traits-preview"] }
blake3 = { version = "1.8", features = ["traits-preview"] }
log = "0.4"
multi-cid = "0.2"
multi-codec = "1.3"
multi-codec = "1.5"
multi-hash = "1.1"
multi-key = "1.2"
multi-sig = "1.3"
multi-key = "2.0"
multi-sig = "1.4"
multi-trait = "1.0"
multi-util = "1.1"
thiserror = "2.0"
tracing = "0.1"
wasmtime = { version = "48.0", default-features = false, features = [
wasmtime = { version = "49.0", default-features = false, features = [
"component-model",
"cranelift",
"parallel-compilation",
"runtime",
Expand All @@ -35,6 +36,7 @@ wasmtime = { version = "48.0", default-features = false, features = [
hex = "0.4"
proptest = "1.11"
test-log = { version = "0.2", features = ["trace", "color"] }
wasmparser = "0.261"

[[test]]
name = "log"
Expand Down Expand Up @@ -80,6 +82,10 @@ path = "tests/edge_cases.rs"
name = "property_tests"
path = "tests/property_tests.rs"

[[test]]
name = "component"
path = "tests/component.rs"

[lints.clippy]
pedantic = { level = "warn", priority = -1 }
nursery = { level = "warn", priority = -1 }
Expand Down
2 changes: 2 additions & 0 deletions examples/wacc/abi/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
target = "wasm32-wasip2"
11 changes: 11 additions & 0 deletions examples/wacc/abi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "abi"
version = "0.7.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
wit-bindgen = { version = "0.46", default-features = false, features = ["macros", "realloc"] }
dlmalloc = { version = "0.2", features = ["global"] }
79 changes: 79 additions & 0 deletions examples/wacc/abi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#![no_std]

use dlmalloc::GlobalDlmalloc;

#[global_allocator]
static ALLOCATOR: GlobalDlmalloc = GlobalDlmalloc;

#[panic_handler]
fn panic(_: &core::panic::PanicInfo<'_>) -> ! {
core::arch::wasm32::unreachable()
}

// The component canonical ABI allocates host-to-guest return buffers through a
// `cabi_realloc` core export. wit-bindgen's runtime omits this export for
// wasm32-wasip2 targets, so the guest supplies it over its global allocator.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn cabi_realloc(
old_ptr: *mut u8,
old_len: usize,
align: usize,
new_len: usize,
) -> *mut u8 {
use core::alloc::{GlobalAlloc, Layout};

let ptr = if old_len == 0 {
if new_len == 0 {
return align as *mut u8;
}
ALLOCATOR.alloc(Layout::from_size_align_unchecked(new_len, align))
} else {
debug_assert_ne!(new_len, 0, "non-zero old_len requires non-zero new_len!");
ALLOCATOR.realloc(
old_ptr,
Layout::from_size_align_unchecked(old_len, align),
new_len,
)
};
if ptr.is_null() {
core::arch::wasm32::unreachable();
}
ptr
}

wit_bindgen::generate!({
world: "unlock-script",
path: "../../../wit/wacc.wit",
});

struct Component;

impl Guest for Component {
fn for_great_justice() -> i32 {
use crate::cryptid::wacc::host::{
branch, check_eq, check_preimage, check_preimage_value, check_signature, log, push,
push_value,
};

let push_ok = push("/abi/");
let push_value_ok = push_value(&[0xAB, 0xCD]);
let branch_result = branch("/abi/proof");
let log_branch_ok = log(&branch_result);

// Each check is expected to fail without matching state; the calls
// exercise the host-side lowering of every import signature.
let _ = check_eq("/abi/nonexistent");
let _ = check_preimage("/abi/nonexistent");
let _ = check_preimage_value(&[0x00, 0x12, 0x34], "/abi/nonexistent");
let _ = check_signature("/abi/nonexistent", "/abi/nonexistent-msg");

let log_ok = log("/abi/log-line");
if push_ok && push_value_ok && log_branch_ok && log_ok && !branch_result.is_empty() {
1
} else {
0
}
}
}

export!(Component);
2 changes: 1 addition & 1 deletion examples/wacc/log/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[build]
target = "wasm32-unknown-unknown"
target = "wasm32-wasip2"
4 changes: 4 additions & 0 deletions examples/wacc/log/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
wit-bindgen = { version = "0.46", default-features = false, features = ["macros", "realloc"] }
dlmalloc = { version = "0.2", features = ["global"] }
66 changes: 58 additions & 8 deletions examples/wacc/log/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,63 @@
#[link(wasm_import_module = "wacc")]
extern "C" {
fn _log(ptr: *const u8, len: usize) -> bool;
#![no_std]

use dlmalloc::GlobalDlmalloc;

#[global_allocator]
static ALLOCATOR: GlobalDlmalloc = GlobalDlmalloc;

#[panic_handler]
fn panic(_: &core::panic::PanicInfo<'_>) -> ! {
core::arch::wasm32::unreachable()
}

fn log(s: &str) -> bool {
unsafe { _log(s.as_ptr(), s.len()) }
// The component canonical ABI allocates host-to-guest return buffers through a
// `cabi_realloc` core export. wit-bindgen's runtime omits this export for
// wasm32-wasip2 targets, so the guest supplies it over its global allocator.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn cabi_realloc(
old_ptr: *mut u8,
old_len: usize,
align: usize,
new_len: usize,
) -> *mut u8 {
use core::alloc::{GlobalAlloc, Layout};

let ptr = if old_len == 0 {
if new_len == 0 {
return align as *mut u8;
}
ALLOCATOR.alloc(Layout::from_size_align_unchecked(new_len, align))
} else {
debug_assert_ne!(new_len, 0, "non-zero old_len requires non-zero new_len!");
ALLOCATOR.realloc(
old_ptr,
Layout::from_size_align_unchecked(old_len, align),
new_len,
)
};
if ptr.is_null() {
core::arch::wasm32::unreachable();
}
ptr
}

#[no_mangle]
pub fn move_every_zig() -> bool {
log("Hello World!")
wit_bindgen::generate!({
world: "lock-script",
path: "../../../wit/wacc.wit",
});

struct Component;

impl Guest for Component {
fn move_every_zig() -> i32 {
use crate::cryptid::wacc::host::log;

if log("Hello World!") {
1
} else {
0
}
}
}

export!(Component);
2 changes: 1 addition & 1 deletion examples/wacc/signature_first/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[build]
target = "wasm32-unknown-unknown"
target = "wasm32-wasip2"
6 changes: 5 additions & 1 deletion examples/wacc/signature_first/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
[package]
name = "signature-first"
name = "signature_first"
version = "0.7.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
wit-bindgen = { version = "0.46", default-features = false, features = ["macros", "realloc"] }
dlmalloc = { version = "0.2", features = ["global"] }
69 changes: 57 additions & 12 deletions examples/wacc/signature_first/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,63 @@
#[link(wasm_import_module = "wacc")]
extern "C" {
fn _check_version(expected: i64) -> i32;
fn _check_signature(ptr: *const u8, len: usize) -> i32;
}
#![no_std]

use dlmalloc::GlobalDlmalloc;

fn check_version(expected: usize) -> bool {
unsafe { _check_version(expected as i64) != 0 }
#[global_allocator]
static ALLOCATOR: GlobalDlmalloc = GlobalDlmalloc;

#[panic_handler]
fn panic(_: &core::panic::PanicInfo<'_>) -> ! {
core::arch::wasm32::unreachable()
}

fn check_signature(key: &str) -> bool {
unsafe { _check_signature(key.as_ptr(), key.len()) != 0 }
// The component canonical ABI allocates host-to-guest return buffers through a
// `cabi_realloc` core export. wit-bindgen's runtime omits this export for
// wasm32-wasip2 targets, so the guest supplies it over its global allocator.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn cabi_realloc(
old_ptr: *mut u8,
old_len: usize,
align: usize,
new_len: usize,
) -> *mut u8 {
use core::alloc::{GlobalAlloc, Layout};

let ptr = if old_len == 0 {
if new_len == 0 {
return align as *mut u8;
}
ALLOCATOR.alloc(Layout::from_size_align_unchecked(new_len, align))
} else {
debug_assert_ne!(new_len, 0, "non-zero old_len requires non-zero new_len!");
ALLOCATOR.realloc(
old_ptr,
Layout::from_size_align_unchecked(old_len, align),
new_len,
)
};
if ptr.is_null() {
core::arch::wasm32::unreachable();
}
ptr
}

#[no_mangle]
pub fn move_zig() -> bool {
check_version(0) && check_signature("ephemeral")
wit_bindgen::generate!({
world: "lock-script",
path: "../../../wit/wacc.wit",
});

struct Component;

impl Guest for Component {
fn move_every_zig() -> i32 {
use crate::cryptid::wacc::host::check_signature;

if check_signature("ephemeral", "/entry/") {
1
} else {
0
}
}
}

export!(Component);
Loading
Loading