diff --git a/README.md b/README.md index b8711dd..26c1a29 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,14 @@ Playground for example programs for the [Miden VM](https://github.com/0xPolygonM The goal of this playground is for developers to see how easy it is to write and execute code in Miden assembly. The examples come from the community and the team. If you come up with an example of your own, we are happy to include it in the list below. You can simply open a PR with your example adding the `.masm` and `.inputs` files. -Examples are written in Miden assembly, see [Miden assembly documentation](https://wiki.polygon.technology/docs/miden/user_docs/assembly/main/). External inputs can be provided to the examples and the Miden VM in two ways as public inputs and via the advice provider, see [here](https://wiki.polygon.technology/docs/miden/intro/overview/#inputs-and-outputs). Currently, in the playground you can use `operand_stack` as public input and the `advice_stack` as secret input. +Examples are written in Miden assembly, see [Miden assembly documentation](https://wiki.polygon.technology/docs/miden/user_docs/assembly/main/). External inputs can be provided to the examples and the Miden VM in two ways as public inputs and via the advice provider, see [here](https://wiki.polygon.technology/docs/miden/intro/overview/#inputs-and-outputs). Currently, in the playground you can use `operand_stack` as public input and the `advice_stack` as secret input. -In addition to running existing examples you can also write your own program and execute it. The examples can then serve as inspiration. +In addition to running existing examples you can also write your own program and execute it. The examples can then serve as inspiration. --- + ## Available examples + There are several examples in our repo and we hope we get more in the future. The examples range from simple to complex and aim to show how Miden assembly can be used. ### Simple examples - to see how the code works @@ -20,22 +22,23 @@ There are several examples in our repo and we hope we get more in the future. Th - **Conditional**: A program which either adds or multiplies two numbers - 3 and 5 - based on the value provided via the advice tape as secret input. -### Math examples - see more complex numerical calculations +### Math examples - see more complex numerical calculations - **Collatz**: A program which executes an unbounded loop to compute a Collatz sequence which starts with the provided value; the output of the program is the number of steps needed to reach 1 - the end of the sequence. -- **Fibonnacci**: Elegant way to calculate the 1001st fibonacci number. +- **Fibonnacci**: Elegant way to calculate the 1001st fibonacci number. -- **nPrime**: Program to calculate the n-th prime number. It will return all prime numbers up to the n-th prime number which is on top of the stack. +- **nPrime**: Program to calculate the n-th prime number. It will return all prime numbers up to the n-th prime number which is on top of the stack. ### Complex examples - larger complex nested operations - **Game-of-Life**: Implementation of Conway's Game of Life. But we can prove it. The static example runs on a 4x4 cell universe and 1000 generations. --- + ## Running the playground locally -You can also run the playground locally on your machine. +You can also run the playground locally on your machine. ### Starting site @@ -55,6 +58,6 @@ Test rust code: cd miden-wasm && wasm-pack test --node ``` -### Acknowledgement +### Acknowledgement We use a fork of https://github.com/timgestson/miden-assembly-playground diff --git a/benchmarking-cli/README.md b/benchmarking-cli/README.md index 6ecb5ab..23b2455 100644 --- a/benchmarking-cli/README.md +++ b/benchmarking-cli/README.md @@ -1,27 +1,28 @@ # Benchmarking CLI for Miden Examples -This is a simple CLI that enables users to benchmark the Miden examples. You can run any example in https://github.com/0xPolygonMiden/examples/tree/main/examples. +This is a simple CLI that enables users to benchmark the Miden examples. You can run any example in https://github.com/0xPolygonMiden/examples/tree/main/examples. ## Usage + To run the fibonacci example, you can either run ``` cargo build ``` -and then +and then ``` ./target/debug/miden-benchmarking-cli --example fibonacci ``` -OR you run +OR you run ``` -cargo run --release -- -e fibonacci +cargo run --release -- -e fibonacci ``` -You can pass two additional parameters to the CLI `security` and `output`. `security` can be `"high"` for 128-bit security and will default to 96-bit. `output` defines the number of stack outputs the program returns. It defaults to 1. +You can pass two additional parameters to the CLI `security` and `output`. `security` can be `"high"` for 128-bit security and will default to 96-bit. `output` defines the number of stack outputs the program returns. It defaults to 1. In general the CLI works as follows: diff --git a/playground/.pre-commit-config.yaml b/playground/.pre-commit-config.yaml index 5707b97..b871ec6 100644 --- a/playground/.pre-commit-config.yaml +++ b/playground/.pre-commit-config.yaml @@ -5,6 +5,7 @@ repos: rev: v3.0.3 hooks: - id: prettier + exclude: ^src/utils/helper_functions.tsx - repo: https://github.com/hackaugusto/pre-commit-cargo rev: v1.0.0 @@ -14,25 +15,25 @@ repos: name: Cargo fmt args: ['+stable', 'fmt', '--all'] stages: [commit] - files: ^examples/playground/miden-wasm/src/ + files: ^examples/playground/miden-wasm/.*\.rs$ # Requires code to be properly formatted prior to pushing upstream - id: cargo name: Cargo fmt --check args: ['+stable', 'fmt', '--all', '--check'] stages: [push, manual] - files: ^examples/playground/miden-wasm/src/ + files: ^examples/playground/miden-wasm/.*\.rs$ - id: cargo name: Cargo check --all-targets args: ['+stable', 'check', '--all-targets'] - files: ^examples/playground/miden-wasm/ + files: ^examples/playground/miden-wasm/.*\.rs$ - id: cargo name: Cargo check --all-targets --no-default-features args: ['+stable', 'check', '--all-targets', '--no-default-features'] - files: ^examples/playground/miden-wasm/src/ + files: ^examples/playground/miden-wasm/.*\.rs$ - id: cargo name: Cargo check --all-targets --all-features args: ['+stable', 'check', '--all-targets', '--all-features'] - files: ^examples/playground/miden-wasm/ + files: ^examples/playground/miden-wasm/.*\.rs$ # Unlike fmt, clippy will not be automatically applied - id: cargo name: Cargo clippy @@ -47,4 +48,4 @@ repos: '--deny', 'warnings' ] - files: ^examples/playground/miden-wasm/src/ + files: ^examples/playground/miden-wasm/.*\.rs$ diff --git a/playground/.prettierignore b/playground/.prettierignore index 9f106f1..0a1c38c 100644 --- a/playground/.prettierignore +++ b/playground/.prettierignore @@ -1,4 +1,4 @@ # Ignore artifacts: build coverage -miden-wasm +src/utils/helper_functions.tsx \ No newline at end of file diff --git a/playground/src/utils/helper_functions.tsx b/playground/src/utils/helper_functions.tsx index 13f23be..55c7351 100644 --- a/playground/src/utils/helper_functions.tsx +++ b/playground/src/utils/helper_functions.tsx @@ -1,3 +1,4 @@ +// prettier-ignore-file import * as yup from 'yup'; import type { DebugOutput } from 'miden-wasm'; @@ -140,8 +141,7 @@ export const checkInputs = (inputString: string): checkedData => { let input: JSON; try { input = JSON.parse(inputString); - } catch (error: any) { - // eslint-disable-line @typescript-eslint/no-explicit-any + } catch (error: any) { // eslint-disable-line @typescript-eslint/no-explicit-any const errorMessage = `Inputs must be a valid JSON object: ${error.message}`; return { isValid: false, errorMessage: errorMessage }; } @@ -149,8 +149,7 @@ export const checkInputs = (inputString: string): checkedData => { try { inputSchema.validateSync(input, { strict: true, stripUnknown: false }); return { isValid: true, errorMessage: '' }; - } catch (error: any) { - // eslint-disable-line @typescript-eslint/no-explicit-any + } catch (error: any) { // eslint-disable-line @typescript-eslint/no-explicit-any return { isValid: false, errorMessage: `Invalid inputs: ${error.message}` }; } }; @@ -176,8 +175,7 @@ export function checkOutputs(jsonString: string): checkedData { let jsonOutput!: JSON; try { jsonOutput = JSON.parse(jsonString); - } catch (e: any) { - // eslint-disable-line @typescript-eslint/no-explicit-any + } catch (e: any) { // eslint-disable-line @typescript-eslint/no-explicit-any const errorMessage = `Miden VM Outputs need to be a valid JSON object: ${e.message} Did you prove the program first?`; @@ -190,8 +188,7 @@ Did you prove the program first?`; stripUnknown: false }); return { isValid: true, errorMessage: '' }; - } catch (error: any) { - // eslint-disable-line @typescript-eslint/no-explicit-any + } catch (error: any) { // eslint-disable-line @typescript-eslint/no-explicit-any return { isValid: false, errorMessage: `Invalid outputs: ${error.message}`