Skip to content
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

Workshop Script Update #43

Merged
merged 24 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
80ac6ac
auction workshop new expressive script
Oct 6, 2023
531d291
workshop auction additional comments
Oct 10, 2023
806efe0
workshop basic_bank add more expressive script
Oct 10, 2023
ec315c4
workshop vote new expressive script
Oct 10, 2023
7c89ae4
workshop tictactoe new expressive script
Oct 10, 2023
9494d2d
workshop battleship & workshop token, new expressive scripts
Oct 11, 2023
18ca2e1
changed self.caller to signer in battleship, run.sh checks and format…
Oct 11, 2023
462f6f5
update README.md to match auction documentation tutorial
Oct 11, 2023
0b29351
update README.md to match basic_bank documentation tutorial
Oct 12, 2023
80987a7
add header back to README
Oct 12, 2023
0979d79
update README.md to match tictactoe documentation tutorial, change in…
Oct 12, 2023
be78c21
fix spacing issue
Oct 12, 2023
94c94e2
update READM.md to match vote documentation tutorial, run script elim…
Oct 12, 2023
0a5414a
update README.md to match token tutorial, fix incorrect math in run s…
Oct 12, 2023
ad7574e
update README.md to match battleship tutorial, update spacing run.sh
Oct 12, 2023
9b52aa5
formatting changes
Oct 12, 2023
abfe6f1
auction workshop fixes, update readme, remove input files, add back s…
Oct 17, 2023
f649e5b
basic bank workshop fixes, update readme, remove input files, add bac…
Oct 17, 2023
c28e1c4
battleship workshop fixes, update readme, remove input files
Oct 17, 2023
bbb6e70
tictactoe workshop fixes, update readme, remove input files
Oct 17, 2023
601cafd
token workshop fixes, update readme, remove input files
Oct 17, 2023
64af633
vote workshop fixes, update readme, remove input files
Oct 17, 2023
130d7c2
grammar fix
Oct 17, 2023
6b8032f
nits
collinc97 Oct 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 116 additions & 21 deletions auction/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A first-price sealed-bid auction in Leo.

## Summary

A first-price sealed-bid auction (or blind auction) is a type of auction in which each participant submits a bid without knowing the bids of the other participants.
A first-price sealed-bid auction (or blind auction) is a type of auction in which each participant submits a bid without knowing the bids of the other participants.
The bidder with the highest bid wins the auction.

In this model, there are two parties: the auctioneer and the bidders.
Expand All @@ -20,45 +20,140 @@ We make following assumptions about the auction:
Under this model, we require that:
- Bidders do not learn any information about the value of other bids.

### Auction Flow
## Auction Flow

The auction is conducted in a series of stages.
- **Bidding**: In the bidding stage, bidders submit bids to the auctioneer. They do so by invoking the `place_bid` function.
- **Resolution**: In the resolution stage, the auctioneer resolves the bids in the order they were received. The auctioneer does so by invoking the `resolve` function. The resolution process produces a single winning bid.
- **Finishing**: In this stage, the auctioneer finishes the auction by invoking the `finish` function. This function returns the winning bid to the bidder, which the bidder can then use to claim the item.


## Language Features and Concepts
- `record` declarations
- `assert_eq`
- record ownership

## Running the Program
## How to Run

Follow the [Leo Installation Instructions](https://developer.aleo.org/leo/installation).

This auction program can be run using the following bash script. Locally, it will execute Leo program functions to conduct, bid, and close a three party auction.

```bash
cd auction
./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.

Leo provides users with a command line interface for compiling and running Leo programs.
Users may either specify input values via the command line or provide an input file in `inputs/`.
## Walkthrough

### Configuring Accounts
The `.env` file contains a private key.
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 values.
See `./run.sh` for an example of how to run the program as different parties.
* [Step 0: Initializing the Auction](#step0)
* [Step 1: The First Bid](#step1)
* [Step 2: The Second Bid](#step2)
* [Step 3: Select the Winner](#step3)

## <a id="step0"></a> Step 0: Initializing the Auction

The [Aleo SDK](https://github.com/AleoHQ/leo/tree/testnet3) provides an interface for generating new accounts.
To generate a new account, navigate to [aleo.tools](https://aleo.tools).
The three parties we'll be emulating are as follows:

```markdown
First Bidder Private Key:
APrivateKey1zkpG9Af9z5Ha4ejVyMCqVFXRKknSm8L1ELEwcc4htk9YhVK
First Bidder Address:
aleo1yzlta2q5h8t0fqe0v6dyh9mtv4aggd53fgzr068jvplqhvqsnvzq7pj2ke

Second Bidder Private Key:
APrivateKey1zkpAFshdsj2EqQzXh5zHceDapFWVCwR6wMCJFfkLYRKupug
Second Bidder Address:
aleo1esqchvevwn7n5p84e735w4dtwt2hdtu4dpguwgwy94tsxm2p7qpqmlrta4

Auctioneer Private Key:
APrivateKey1zkp5wvamYgK3WCAdpBQxZqQX8XnuN2u11Y6QprZTriVwZVc
Auctioneer Address:
aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh
```

## <a id="step1"></a> Step 1: The First Bid

Have the first bidder place a bid of 10.

Swap in the private key and address of the first bidder to `.env`.

### Providing inputs via the command line.
1. Run
```bash
leo run <function_name> <input_1> <input_2> ...
echo "
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkpG9Af9z5Ha4ejVyMCqVFXRKknSm8L1ELEwcc4htk9YhVK
" > .env
```
See `./run.sh` for an example.

Call the `place_bid` program function with the first bidder and `10u64` arguments.

### Using an input file.
1. Modify `inputs/auction.in` with the desired inputs.
2. Run
```bash
leo run <function_name>
leo run place_bid aleo1yzlta2q5h8t0fqe0v6dyh9mtv4aggd53fgzr068jvplqhvqsnvzq7pj2ke 10u64
```

## <a id="step2"></a> Step 2: The Second Bid

Have the second bidder place a bid of 90.

Swap in the private key of the second bidder to `.env`.

```bash
echo "
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkpAFshdsj2EqQzXh5zHceDapFWVCwR6wMCJFfkLYRKupug
" > .env
```

Call the `place_bid` program function with the second bidder and `90u64` arguments.

```bash
leo run place_bid aleo1esqchvevwn7n5p84e735w4dtwt2hdtu4dpguwgwy94tsxm2p7qpqmlrta4 90u64
```

## <a id="step3"></a> Step 3: Select the Winner

Have the auctioneer select the winning bid.

Swap in the private key of the auctioneer to `.env`.

```bash
echo "
NETWORK=testnet3
PRIVATE_KEY=APrivateKey1zkp5wvamYgK3WCAdpBQxZqQX8XnuN2u11Y6QprZTriVwZVc
" > .env
```

Provide the two `Bid` records as input to the `resolve` transition function.

```bash
leo run resolve "{
owner: aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh.private,
bidder: aleo1yzlta2q5h8t0fqe0v6dyh9mtv4aggd53fgzr068jvplqhvqsnvzq7pj2ke.private,
amount: 10u64.private,
is_winner: false.private,
_nonce: 4668394794828730542675887906815309351994017139223602571716627453741502624516group.public
}" "{
owner: aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh.private,
bidder: aleo1esqchvevwn7n5p84e735w4dtwt2hdtu4dpguwgwy94tsxm2p7qpqmlrta4.private,
amount: 90u64.private,
is_winner: false.private,
_nonce: 5952811863753971450641238938606857357746712138665944763541786901326522216736group.public
}"
```

## <a id="step4"></a> Step 4: Finish the Auction

Call the `finish` transition function with the winning `Bid` record.

```bash
leo run finish "{
owner: aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh.private,
bidder: aleo1esqchvevwn7n5p84e735w4dtwt2hdtu4dpguwgwy94tsxm2p7qpqmlrta4.private,
amount: 90u64.private,
is_winner: false.private,
_nonce: 5952811863753971450641238938606857357746712138665944763541786901326522216736group.public
}"
```

Congratulations! You've run a private auction. We recommend going to [aleo.tools](https://aleo.tools) to generate new accounts and trying the same commands with those addresses.
39 changes: 0 additions & 39 deletions auction/inputs/auction.in

This file was deleted.

Loading