-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add mint-script crate #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
TomasArrachea
wants to merge
20
commits into
next
Choose a base branch
from
tomasarrachea-tx-script-crate
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
84c86b7
feat: add mint-script crate
TomasArrachea a57f6a3
feat: read compiled package
TomasArrachea 6fa0b6f
feat: parse transaction script at build time
TomasArrachea e7389f8
feat: use cargo miden
TomasArrachea 8c5316e
feat: use miden v0.8
TomasArrachea 3f46464
feat: compile on faucet load
TomasArrachea cf0e49f
fix: build
TomasArrachea 55d2787
feat: makefile and lints
TomasArrachea fd36806
wip
TomasArrachea faeb418
Merge branch 'next' into tomasarrachea-tx-script-crate
TomasArrachea 0b6501d
chore: bump miden compiler deps
TomasArrachea 257490d
feat: use faucet::mint binding
TomasArrachea c4194b0
feat: workaround to link kernel
TomasArrachea edf3100
feat: add faucet account component
TomasArrachea d70bae8
feat: renames and comments
TomasArrachea b4c1e6f
wip: link std package
TomasArrachea bd14e37
feat: remove custom account component
TomasArrachea daf46cd
merge next
TomasArrachea 6fe9821
wip: compiler version
TomasArrachea be99efc
fix: rust tx script
TomasArrachea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| [build] | ||
| target = "wasm32-wasip2" | ||
|
|
||
| [target.wasm32-wasip2] | ||
| rustflags = ["--cfg", "miden"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| [build] | ||
| target = "wasm32-wasip2" | ||
|
|
||
| [target.wasm32-wasip2] | ||
| rustflags = ["--cfg", "miden"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| target/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { | ||
| 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.