Skip to content

Commit

Permalink
Merge branch 'master' into d0cd/update-2-16-25
Browse files Browse the repository at this point in the history
  • Loading branch information
d0cd committed Feb 16, 2025
2 parents 185cd1d + 9df9150 commit 473a58b
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 36 deletions.
4 changes: 2 additions & 2 deletions archive/aleo/02_hello.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function hello:
output r2 as u32.private;
```

You can run a program with the `snarkvm run` command, followed by the function name you want to run and its input parameters:
You can run a program with the `snarkvm run` command (this command is used when you want to interact with an Aleo program on the blockchain, such as creating a transaction that updates the state of the program), followed by the function name you want to run and its input parameters:

``` bash
snarkvm run hello 2u32 3u32
Expand All @@ -56,7 +56,7 @@ As you can see, the output has the `5u32` value, representing the sum of the inp

## 2. Executing a program

You can execute a program with the `snarkvm execute` command, followed by the function name you want to execute and its input parameters:
You can execute a program with the `snarkvm execute` command (this command is used when you want to test the logic of your Aleo program and verify that it produces the correct outputs and proofs), followed by the function name you want to execute and its input parameters:

``` bash
snarkvm execute hello 2u32 3u32
Expand Down
63 changes: 32 additions & 31 deletions archive/aleo/03_language.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,14 @@ A get command that retrieves a value from a mapping, e.g. `get accounts[r0] into

A get command that uses the provided default in case of failure, e.g. `get.or_use accounts[r0] r1 into r2;`.

#### Remove

A remove command that removes a key-value pair from a mapping, e.g. `remove accounts[r0];`.

#### Set

A set command that sets a value in a mapping, e.g. `set r0 into accounts[r0];`.

```aleo showLineNumbers
finalize transfer_public:
// Input the sender.
Expand All @@ -386,18 +394,35 @@ finalize transfer_public:
set r6 into account[r1];
```

#### Set
### Finalize

A set command that sets a value in a mapping, e.g. `set r0 into accounts[r0];`.
A finalize is declared as `finalize {name}:`.
A finalize must immediately follow a [function](#function), and must have the same name;

#### Remove
:::note
Previously, a `finalize` function was executed on chain after the zero-knowledge proof of the execution of the associated function is verified;
Upon success of the finalize function, the program logic was executed.
Upon failure of the finalize function, the program logic was reverted.
:::

A remove command that removes a key-value pair from a mapping, e.g. `remove accounts[r0];`.
### Futures

### Finalize
A future is equivalent to the call graph of the on-chain execution and is explicitly used when finalizing an execution.
Instead of constructing the call graph implicitly from the code, the transition/circuit explicitly outputs a future,
specifying which code blocks to run on-chain and how to run them.

A finalize is declared as `finalize {name}:`.
A finalize must immediately follow a [function](#function), and must have the same name;
#### future type
A user can declare a future type by specifying a `Locator` followed by the tag `.future`.
For example, `credits.aleo/mint_public.future`.
A `function` can only output a future and a finalize block can only take a future in as input.
A `closure` cannot output a future or take a future in as input.

#### async call
A user can make an asynchronous call to the finalize block via the `async` keyword.
For example, `async mint_public r0 r1 into r2;`.
Note that the associated function must be specified.
This operation produces a `Future` as output.
`async` takes the place of the `finalize` command, which was allowed in the body of a function after the output statements.

```aleo showLineNumbers
// The `transfer_public_to_private` function turns a specified amount
Expand Down Expand Up @@ -441,30 +466,6 @@ finalize transfer_public_to_private:
set r3 into account[r0];
```

:::note
Previously, a `finalize` function was executed on chain after the zero-knowledge proof of the execution of the associated function is verified;
Upon success of the finalize function, the program logic was executed.
Upon failure of the finalize function, the program logic was reverted.
:::

### Futures

A future is equivalent to the call graph of the on-chain execution and is explicitly used when finalizing an execution.
Instead of constructing the call graph implicitly from the code, the transition/circuit explicitly outputs a future,
specifying which code blocks to run on-chain and how to run them.

#### future type
A user can declare a future type by specifying a `Locator` followed by the tag `.future`.
For example, `credits.aleo/mint_public.future`.
A `function` can only output a future and a finalize block can only take a future in as input.
A `closure` cannot output a future or take a future in as input.

#### async call
A user can make an asynchronous call to the finalize block via the `async` keyword.
For example, `async mint_public r0 r1 into r2;`.
Note that the associated function must be specified.
This operation produces a `Future` as output.
`async` takes the place of the `finalize` command, which was allowed in the body of a function after the output statements.

#### await command
A user can evaluate a future inside of a finalize block using the `await` command.
Expand Down
76 changes: 74 additions & 2 deletions documentation/leo_by_example/03_vote.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ Follow the [Leo Installation Instructions](https://docs.leo-lang.org/leo/install
This vote program can be run using the following bash script. Locally, it will execute Leo program functions to create proposals, create tickets, and make votes.

```bash
cd vote
cd leo/examples/vote
./run.sh
```

The `.env` file contains a private key and address. This is the account that will be used to sign transactions and is checked for record ownership. When executing programs as different parties, be sure to set the `private_key` field in `.env` to the appropriate value. You can check out how we've set things up in `./run.sh` for a full example of how to run the program as different parties.
The `.env` file contains a private key and network type. This is the account that will be used to sign transactions and is checked for record ownership. When executing programs as different parties, be sure to set the `private_key` field in `.env` to the appropriate value. You can check out how we've set things up in `./run.sh` for a full example of how to run the program as different parties.

## Walkthrough

Expand Down Expand Up @@ -84,6 +84,27 @@ leo run propose "{
proposer: aleo1rfez44epy0m7nv4pskvjy6vex64tnt0xy90fyhrg49cwe0t9ws8sh6nhhr
}"
```
Output
```bash

• {
owner: aleo1rfez44epy0m7nv4pskvjy6vex64tnt0xy90fyhrg49cwe0t9ws8sh6nhhr.private,
id: 2805252584833208809872967597325381727971256629741137995614832105537063464740field.private,
info: {
title: 2077160157502449938194577302446444field.private,
content: 1452374294790018907888397545906607852827800436field.private,
proposer: aleo1rfez44epy0m7nv4pskvjy6vex64tnt0xy90fyhrg49cwe0t9ws8sh6nhhr.private
},
_nonce: 7270749279509948287724447377218313625054368902761257869085068499107406906985group.public
}
• {
program_id: vote.aleo,
function_name: propose,
arguments: [
2805252584833208809872967597325381727971256629741137995614832105537063464740field
]
}
```

You'll see that the output generates a new record with the proposal information and sets a public mapping with the proposal id as an argument input. The public mapping will be queryable on-chain.

Expand All @@ -99,6 +120,21 @@ PRIVATE_KEY=APrivateKey1zkpHmSu9zuhyuCJqVfQE8p82HXpCTLVa8Z2HUNaiy9mrug2

leo run new_ticket 2264670486490520844857553240576860973319410481267184439818180411609250173817field aleo1c45etea8czkyscyqawxs7auqjz08daaagp2zq4qjydkhxt997q9s77rsp2
```
Output
```bash
• {
owner: aleo1c45etea8czkyscyqawxs7auqjz08daaagp2zq4qjydkhxt997q9s77rsp2.private,
pid: 2264670486490520844857553240576860973319410481267184439818180411609250173817field.private,
_nonce: 3111099913449740827888947259874663727415985369111767658428258317443300847451group.public
}
• {
program_id: vote.aleo,
function_name: new_ticket,
arguments: [
2264670486490520844857553240576860973319410481267184439818180411609250173817field
]
}
```

You'll see a new private ticket created belonging to the owner, and a public mapping in the vote program to track the ID of that ticket.

Expand All @@ -110,6 +146,17 @@ leo run agree "{
pid: 2264670486490520844857553240576860973319410481267184439818180411609250173817field.private,
_nonce: 1738483341280375163846743812193292672860569105378494043894154684192972730518group.public
}"
```
Output
```bash
• {
program_id: vote.aleo,
function_name: agree,
arguments: [
2264670486490520844857553240576860973319410481267184439818180411609250173817field
]
}

```

## <a id="step2"></a> Voter 2 makes a vote
Expand All @@ -124,6 +171,21 @@ PRIVATE_KEY=APrivateKey1zkp6NHwbT7PkpnEFeBidz5ZkZ14W8WXZmJ6kjKbEHYdMmf2

leo run new_ticket 2158670485494560943857353240576760973319410481267184429818180411607250143681field aleo1uc6jphye8y9gfqtezrz240ak963sdgugd7s96qpuw6k7jz9axs8q2qnhxc
```
Output
```bash
• {
owner: aleo1uc6jphye8y9gfqtezrz240ak963sdgugd7s96qpuw6k7jz9axs8q2qnhxc.private,
pid: 2158670485494560943857353240576760973319410481267184429818180411607250143681field.private,
_nonce: 7213678168429828883374086447188635180072431460350128753904256765278199909612group.public
}
• {
program_id: vote.aleo,
function_name: new_ticket,
arguments: [
2158670485494560943857353240576760973319410481267184429818180411607250143681field
]
}
```

Voter 2 can now vote privately on their ticket. Call the agree or disagree transition function, which takes the voter's ticket output as the input.

Expand All @@ -134,6 +196,16 @@ leo run disagree "{
_nonce: 6511154004161574129036815174288926693337549214513234790975047364416273541105group.public
}"
```
Output
```bash
• {
program_id: vote.aleo,
function_name: disagree,
arguments: [
2158670485494560943857353240576760973319410481267184429818180411607250143681field
]
}
```

## <a id="step3"></a> How votes are tallied

Expand Down
3 changes: 2 additions & 1 deletion documentation/leo_by_example/05_tictactoe.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ cd tictactoe

## <a id="step0"></a> Create a new board.

We generate the board, and then the player take turns executing the transition function make_move.
We generate the board, and then the players take turns executing the transition function make_move.

The inputs to the function are the player number, row position, column position, and the previous state of the board.

Expand Down Expand Up @@ -84,3 +84,4 @@ leo run make_move 1u8 3u8 1u8 "{ r1: { c1: 1u8, c2: 0u8, c3: 0u8 }, r2: { c1: 0u

If you follow the run script till the end, you'll see the players make a draw, with an output of `0u64`.

This example does not utilize records, as it is primarily designed to demonstrate Leo language features rather than serve as a fully realistic example of a ZK game. A more complete implementation would involve passing records between players to maintain game state securely.

0 comments on commit 473a58b

Please sign in to comment.