-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from 0xPolygonMiden/greenhat/i163-account-code-…
…for-alpha [1/x] Add Miden SDK dependency and update the sample code
- Loading branch information
Showing
8 changed files
with
75 additions
and
23 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains 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,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" |
This file contains 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
File renamed without changes.
This file contains 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 @@ | ||
[toolchain] | ||
channel = "nightly-2024-03-10" | ||
components = ["rustfmt", "rust-src"] | ||
targets = ["wasm32-wasi"] | ||
profile = "minimal" |
This file contains 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,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 | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.