Skip to content

Commit

Permalink
Merge pull request #1 from 0xPolygonMiden/greenhat/i163-account-code-…
Browse files Browse the repository at this point in the history
…for-alpha

[1/x] Add Miden SDK dependency and update the sample code
  • Loading branch information
bitwalker authored Jun 24, 2024
2 parents 11be336 + b7107ee commit 073cc3c
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 23 deletions.
File renamed without changes.
26 changes: 26 additions & 0 deletions account/template/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "{{crate_name}}"
version = "0.1.0"
edition = "2021"

[lib]
# Build this crate as a self-contained, C-style dynamic library
# This is required to emit the proper Wasm module type
crate-type = ["cdylib"]

[dependencies]
# Miden SDK consists of a Prelude (intrinsic functions for VM opr, stdlib) and transaction kernel API for the Miden rollup
miden-sdk = { git = "https://github.com/0xPolygonMiden/compiler", rev = "10a05d8fa76106325e2497c2d1b10f1042c77340" }
# Use a tiny allocator in place of the default one, if we want
# to make use of types in the `alloc` crate, e.g. String. We
# don't need that now, but its good information to have in hand.
wee_alloc = { version = "0.4.5", default-features = false}

[profile.release]
# optimize the output for size
opt-level = "z"
# Explicitly disable panic infrastructure on Wasm, as
# there is no proper support for them anyway, and it
# ensures that panics do not pull in a bunch of standard
# library code unintentionally
panic = "abort"
6 changes: 4 additions & 2 deletions library/template/README.md → account/template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

`{{crate_name}}` is built using the [Miden compiler](https://github.com/0xPolygonMiden/compiler).

`cargo miden` is a `cargo` cargo extension. Check out its [documentation](https://github.com/0xPolygonMiden/compiler/cargo-ext)
`cargo miden` is a `cargo` cargo extension. Check out its [documentation](https://github.com/0xPolygonMiden/compiler/tree/main/tools/cargo-miden)
for more details.


Expand All @@ -13,5 +13,7 @@ for more details.
To build this project, run:

```bash
cargo miden compile -o ./target/{{crate_name}}.masm
cargo miden build --release
```

The compiled Miden artifact will be located in `target/miden/release`.
File renamed without changes.
5 changes: 5 additions & 0 deletions account/template/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[toolchain]
channel = "nightly-2024-03-10"
components = ["rustfmt", "rust-src"]
targets = ["wasm32-wasi"]
profile = "minimal"
40 changes: 40 additions & 0 deletions account/template/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Do not link against libstd (i.e. anything defined in `std::`)
#![no_std]

// However, we could still use some standard library types while
// remaining no-std compatible, if we uncommented the following lines:
//
// extern crate alloc;
// use alloc::vec::Vec;

// Global allocator to use heap memory in no-std environment
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

// Required for no-std crates
#[panic_handler]
fn my_panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}

use miden_sdk::*;

// Marking the function no_mangle ensures that it is exported
// from the compiled binary as `fib`, otherwise it would have
// a mangled name that has no stable form.
//
// You can specify a different name from the library than the
// name in the source code using the `#[export_name = "foo"]`
// attribute, which will make the function callable as `foo`
// externally (in this example)
#[no_mangle]
pub fn fib(n: u32) -> Felt {
let mut a = felt!(0);
let mut b = felt!(1);
for _ in 0..n {
let c = a + b;
a = b;
b = c;
}
a
}
10 changes: 0 additions & 10 deletions library/template/Cargo.toml

This file was deleted.

11 changes: 0 additions & 11 deletions library/template/src/lib.rs

This file was deleted.

0 comments on commit 073cc3c

Please sign in to comment.