Skip to content

Add examples/counter-contract and expose incr_nonce in the Miden SDK #492

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

Open
wants to merge 8 commits into
base: i431-acc-storage-high
Choose a base branch
from

Conversation

greenhat
Copy link
Contributor

@greenhat greenhat commented Apr 25, 2025

Close #482
Close #491

This PR is stacked on the #436 and should be merged after it

This PR adds:

  • examples/counter-contract and counter_contract integration test;
  • incr_nonce in the Miden SDK;
  • Project type (library or program) detection in cargo-miden projects.

@greenhat greenhat marked this pull request as ready for review April 25, 2025 09:46
@greenhat greenhat requested a review from bitwalker April 25, 2025 09:46
@greenhat
Copy link
Contributor Author

@partylikeits1983 Please check if I got everything right. I cannot request a review from you.

@bobbinth, please add @partylikeits1983 to this repo.

@greenhat
Copy link
Contributor Author

@partylikeits1983 I put only the build instructions in the README file. We should probably link a relevant part of your tutorial. What do you think?

@partylikeits1983
Copy link
Contributor

@greenhat I’m trying to build the counter-contract example from your greenhat/i482-counter-contract-example branch and ran into an ABI panic. Here’s exactly what I’ve done:

  1. Set Rust toolchain
    rustup default nightly-2025-03-20
  2. Installed cargo miden
    cd <compiler-root>
    cargo make install
    # → cargo miden v0.0.8
  3. Built the example
    cd examples/counter-contract
    cargo miden build --release

Resulting error:

thread 'main' panicked at '/Users/riemann/.cargo/registry/.../midenc-frontend-wasm-0.0.8/src/miden_abi/mod.rs:62:28:
No Miden ABI function type found for function miden/account/incr_nonce'
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I noticed the counter-contract integration test uses these midenc build flags:

midenc build --debug --verbose --target rollup

What additional flags or steps should I include when running cargo miden build --release inside examples/counter-contract to mirror the setup in the integration test and avoid the ABI panic?

@greenhat
Copy link
Contributor Author

@partylikeits1983 Thanks for checking this out! The cargo-miden should be built from this branch. But even then, it does not work yet, since cargo-miden only knows how to build programs and not libraries. I'm working on the fix.

@greenhat greenhat marked this pull request as draft April 25, 2025 16:42
@greenhat greenhat marked this pull request as ready for review April 28, 2025 08:22
@greenhat
Copy link
Contributor Author

@partylikeits1983 Done. Please build cargo-miden from this branch when testing. No extra flags necessary. I implemented the project type detection from our metadata in the Cargo.toml file.

@partylikeits1983
Copy link
Contributor

This is awesome, was able to install cargo miden by running cargo install --path tools/cargo-miden, and then build the counter_contract example.

I think the next step after this is merged would be to test this end to end, by deploying the rust counter contract to testnet and executing transactions against the account.

I think it might be useful to open a PR on miden-base to extend the AccountBuilder api with a .with_package method. Or is there a way right now to convert a miden package into an AccountComponent type? If it is possible to convert a miden package into an AccountComponent type, there would be no need to make any changes in miden-base.

This is how I've been initializing a counter contract written in masm:

let (counter_contract, counter_seed) = AccountBuilder::new(seed)
        .anchor((&anchor_block).try_into().unwrap())
        .account_type(AccountType::RegularAccountImmutableCode)
        .storage_mode(AccountStorageMode::Public)
        .with_component(counter_component.clone())
        .build()
        .unwrap();

@greenhat
Copy link
Contributor Author

greenhat commented Apr 28, 2025

I think the next step after this is merged would be to test this end to end, by deploying the rust counter contract to testnet and executing transactions against the account.

Sounds great!

I think it might be useful to open a PR on miden-base to extend the AccountBuilder api with a .with_package method. Or is there a way right now to convert a miden package into an AccountComponent type? If it is possible to convert a miden package into an AccountComponent type, there would be no need to make any changes in miden-base.

This is how I've been initializing a counter contract written in masm:

let (counter_contract, counter_seed) = AccountBuilder::new(seed)
        .anchor((&anchor_block).try_into().unwrap())
        .account_type(AccountType::RegularAccountImmutableCode)
        .storage_mode(AccountStorageMode::Public)
        .with_component(counter_component.clone())
        .build()
        .unwrap();

I would start with an issue. My plan was to add the AccountComponentTemplate::from_package method, which will parse a Miden package .masp file, and then use the AccountComponent::from_template constructor to make a component out of it. But there might be a better way.

@greenhat
Copy link
Contributor Author

I think the next step after this is merged would be to test this end to end, by deploying the rust counter contract to testnet and executing transactions against the account.

For this to work, we're still missing one piece: the proper transaction kernel library linking. Currently, we are linking against the stubbed-out transaction kernel library

We have an issue for that - #307
@bitwalker mentioned that he has already taken care of it in one of his branches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose incr_nonce in the Miden SDK (base) Add Counter Contract project to examples
2 participants