Smart contract development framework for the Dusk network. Provides a #[contract] proc-macro that generates WASM exports and contract schemas, a CLI for scaffolding and building contract projects, and integration tests exercising every macro code path.
forge/
├── src/ # dusk-forge — re-exports and schema types
├── contract-macro/ # dusk-forge-contract — proc-macro (#[contract])
├── cli/ # dusk-forge-cli — CLI binary (new, build, test, schema, call, verify)
├── tests/types/ # types — helper types for integration tests
├── tests/test-contract/ # test-contract — general-purpose macro exerciser
├── contract-template/ # Template for scaffolding new contract projects
├── docs/ # Design documents
├── Makefile # Workspace-level targets
└── rust-toolchain.toml # Stable toolchain with wasm32 target
| Directory | Crate | Kind |
|---|---|---|
/ (root) |
dusk-forge |
Library |
contract-macro/ |
dusk-forge-contract |
Proc-macro |
cli/ |
dusk-forge-cli |
Binary |
tests/types/ |
types |
Library (test helper) |
tests/test-contract/ |
test-contract |
Contract (integration test) |
Run make help to see all available targets.
The #[contract] attribute macro (in contract-macro/) transforms a Rust module into a Dusk WASM smart contract:
- Parsing (
extract.rs,resolve.rs) — extracts method signatures, trait impls, and state types from the annotated module - Validation (
validate.rs) — enforces contract rules (e.g., mutually exclusive feature gates forcontractvsdata-driver) - Code generation (
generate.rs) — emits#[no_mangle]WASM export wrappers with rkyv (de)serialization - Schema generation (
data_driver.rs) — produces aCONTRACT_SCHEMAconstant describing the contract's ABI for data-driver builds
Trait methods with empty bodies signal the macro to use trait defaults.
The dusk-forge CLI (cli/) provides project management commands:
new— scaffold a contract project from the templatebuild— compile contract and data-driver WASM binariestest/check/clean/expand— development workflow wrappersschema— extract and display the contract schema from a data-driver WASMcall/verify— invoke contract methods and verify results via wasmtime
tests/test-contract/ is a general-purpose macro exerciser that covers every #[contract] code path: owned methods, borrowed methods, trait implementations, associated functions, and schema generation.
no_stdfor contract crates. The proc-macro and CLI arestd.--releasefor tests: integration tests intests/test-contract/build WASM binaries, which require release mode.- Edition 2024 with MSRV 1.85 (stable toolchain).
- Serialization:
rkyvfor contract state and arguments,serdefor schema JSON. - Feature gates: Contracts use mutually exclusive features (
contractvsdata-driver/data-driver-js) to produce different WASM binaries from the same source.
| Changed | Also verify |
|---|---|
dusk-forge / contract-macro |
tests/test-contract, duskevm-contracts, downstream contract repos |
- Default branch:
main - License: MPL-2.0
Format: <scope>: <Description> — imperative mood, capitalize first word after colon.
One commit per scope per concern. Each commit touches one logical scope and one concern. Don't bundle unrelated changes.
Canonical scopes:
| Scope | Directory |
|---|---|
forge |
Root crate (src/) |
macro |
contract-macro/ |
cli |
cli/ |
test-contract |
tests/test-contract/ |
types |
tests/types/ |
workspace |
Root Cargo.toml, Makefile, rust-toolchain.toml |
ci |
.github/workflows/ |
chore |
Formatting, config files, tooling |
Examples:
macro: Add support for generic trait implscli: Fix data-driver feature detectiontest-contract: Add borrowed-state method testworkspace: Update dusk-core dependency
Maintain CHANGELOG.md with entries under [Unreleased] using keep-a-changelog format. If a change traces to a GitHub issue, reference it as a link: [#42](https://github.com/dusk-network/forge/issues/42). Only link to GitHub issues.