Skip to content
Draft
Show file tree
Hide file tree
Changes from 14 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
1,746 changes: 1,561 additions & 185 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = ["bin/faucet", "bin/faucet-client", "crates/faucet"]
members = ["bin/faucet", "bin/faucet-client", "crates/faucet", "crates/pow", "crates/contracts/mint-tx", "crates/contracts/faucet-account"]
default-members = ["bin/faucet", "crates/faucet", "crates/pow"]

resolver = "2"

Expand All @@ -26,6 +27,8 @@ miden-pow-rate-limiter = { path = "crates/pow", version = "0.14.0" }
miden-client = { version = "0.14" }
miden-client-cli = { version = "0.14" }
miden-client-sqlite-store = { version = "0.14" }
miden = { version = "0.11" }
cargo-miden = { git = "https://github.com/0xMiden/compiler", branch = "next" }

# External dependencies
anyhow = { version = "1.0" }
Expand Down
17 changes: 6 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,32 @@ WARNINGS=RUSTDOCFLAGS="-D warnings"

.PHONY: clippy
clippy: ## Runs Clippy with configs
cargo clippy --locked --all-targets --all-features --workspace

cargo clippy --locked --all-targets --all-features

.PHONY: fix
fix: ## Runs Fix with configs
cargo fix --allow-staged --allow-dirty --all-targets --all-features --workspace
cargo fix --allow-staged --allow-dirty --all-targets --all-features

.PHONY: build
build: ## By default we should build in release mode
cargo build --release
cargo build --release

.PHONY: format
format: ## Runs Format using nightly toolchain
cargo +nightly fmt --all


.PHONY: format-check
format-check: ## Runs Format using nightly toolchain but only in check mode
cargo +nightly fmt --all --check


.PHONY: machete
machete: ## Runs machete to find unused dependencies
cargo machete


.PHONY: toml
toml: ## Runs Format for all TOML files
taplo fmt


.PHONY: toml-check
toml-check: ## Runs Format for all TOML files but only in check mode
taplo fmt --check --verbose
Expand All @@ -67,14 +62,14 @@ book: ## Builds the book & serves documentation site
# --- testing -------------------------------------------------------------------------------------

.PHONY: test
test: ## Runs all tests
cargo nextest run --release --all-features --workspace
test: ## Runs all tests
cargo nextest run --release --all-features

# --- checking ------------------------------------------------------------------------------------

.PHONY: check
check: ## Check all targets and features for errors without code generation
${BUILD_PROTO} cargo check --all-features --all-targets --locked --workspace
${BUILD_PROTO} cargo check --all-features --all-targets --locked

# --- installing ----------------------------------------------------------------------------------

Expand Down
5 changes: 5 additions & 0 deletions crates/contracts/faucet-account/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[build]
target = "wasm32-wasip2"

[target.wasm32-wasip2]
rustflags = ["--cfg", "miden"]
17 changes: 17 additions & 0 deletions crates/contracts/faucet-account/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "miden-faucet-account"
version = "0.1.0"
edition = "2024"

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

[dependencies]
miden = { workspace = true }

[package.metadata.component]
package = "miden:faucet-account"

[package.metadata.miden]
project-kind = "account"
supported-types = ["FungibleFaucet"]
27 changes: 27 additions & 0 deletions crates/contracts/faucet-account/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#![no_std]
#![feature(alloc_error_handler)]

use miden::{Felt, NoteIdx, NoteType, Recipient, Tag, component, faucet, output_note};

#[component]
struct FaucetAccount;

#[component]
impl FaucetAccount {
/// Mints fungible assets and sends them to the provided recipient by creating a note.
///
/// This mirrors the `mint_and_send` procedure from the `BasicFungibleFaucet` MASM component.
pub fn mint_and_send(
&mut self,
amount: Felt,
tag: Tag,
note_type: NoteType,
recipient: Recipient,
) -> NoteIdx {
let asset = faucet::create_fungible_asset(amount);
faucet::mint(asset);
let note_idx = output_note::create(tag, note_type, recipient);
output_note::add_asset(asset, note_idx);
note_idx
}
}
Empty file.
5 changes: 5 additions & 0 deletions crates/contracts/mint-tx/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[build]
target = "wasm32-wasip2"

[target.wasm32-wasip2]
rustflags = ["--cfg", "miden"]
1 change: 1 addition & 0 deletions crates/contracts/mint-tx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
31 changes: 31 additions & 0 deletions crates/contracts/mint-tx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "miden-faucet-mint-tx"
authors.workspace = true
description = "Miden faucet's mint transaction script"
edition.workspace = true
homepage.workspace = true
keywords = ["mint", "miden", "faucet"]
license.workspace = true
readme = "README.md"
repository.workspace = true
rust-version.workspace = true
version.workspace = true

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

[dependencies]
miden = { workspace = true }

[package.metadata.component]
package = "miden:mint-tx"

[package.metadata.miden]
project-kind = "transaction-script"

# Miden dependencies for cargo-miden build/linking
[package.metadata.miden.dependencies]
"miden:faucet-account" = { path = "../faucet-account" }

[package.metadata.component.target.dependencies]
"miden:faucet-account" = { path = "../faucet-account/target/generated-wit/" }
9 changes: 9 additions & 0 deletions crates/contracts/mint-tx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# mint_tx

A Miden transaction script project.

## Build

```bash
cargo miden build --release
```
41 changes: 41 additions & 0 deletions crates/contracts/mint-tx/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#![no_std]
#![feature(alloc_error_handler)]

use miden::intrinsics::advice::adv_push_mapvaln;
use miden::tx::update_expiration_block_delta;
use miden::{Felt, Recipient, Word, pipe_words_to_memory, tx_script};

use crate::bindings::Account;

/// Number of felts per note: 4 (recipient) + 1 (note_type) + 1 (tag) + 1 (amount) = 7.
const NOTE_ARGS_SIZE: usize = 7;

#[tx_script]
fn run(arg: Word, account: &mut Account) {
Comment thread
TomasArrachea marked this conversation as resolved.
Outdated
update_expiration_block_delta(Felt::from_u32(10));

// Push note data from advice map onto the advice stack.
let num_felts = adv_push_mapvaln(arg);
let num_felts_u64 = num_felts.as_canonical_u64();

// Pop the data from the advice stack into memory.
let num_words = Felt::new((num_felts_u64 + 3) / 4);
let (_hash, input) = pipe_words_to_memory(num_words);

let num_notes = num_felts_u64 as usize / NOTE_ARGS_SIZE;

for idx in 0..num_notes {
let start = idx * NOTE_ARGS_SIZE;
let recipient = Recipient::from(Word::from([
input[start],
input[start + 1],
input[start + 2],
input[start + 3],
]));
let note_type = input[start + 4].into();
let tag = input[start + 5].into();
let amount = input[start + 6];

account.mint_and_send(amount, tag, note_type, recipient);
}
}
Empty file.
4 changes: 1 addition & 3 deletions crates/faucet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ workspace = true
# Miden dependencies.
miden-client = { features = ["tonic"], workspace = true }
miden-client-sqlite-store = { workspace = true }
cargo-miden = { workspace = true }

# External dependencies.
anyhow = { workspace = true }
Expand All @@ -28,9 +29,6 @@ tokio = { features = ["fs"], workspace = true }
tracing = { workspace = true }
url = { workspace = true }

[build-dependencies]
miden-client = { workspace = true }

[dev-dependencies]
miden-client = { features = ["testing", "tonic"], workspace = true }
uuid = { workspace = true }
75 changes: 0 additions & 75 deletions crates/faucet/asm/tx_scripts/mint.masm

This file was deleted.

Loading
Loading