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

Updates to most recent version of Leo. #20

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion auction/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The auction is conducted in a series of stages.

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

## Running the Program
Expand Down
6 changes: 3 additions & 3 deletions auction/src/main.leo
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ program auction.aleo {
// The address of the auction runner is aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh.
transition place_bid(bidder: address, amount: u64) -> Bid {
// Ensure the caller is the auction bidder.
console.assert_eq(self.caller, bidder);
assert_eq(self.caller, bidder);
// Return a new 'Bid' record for the auction bidder.
return Bid {
owner: aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh,
Expand All @@ -43,7 +43,7 @@ program auction.aleo {
// In the event of a tie, the first bid is selected.
transition resolve(first: Bid, second: Bid) -> Bid {
// Ensure the caller is the auctioneer.
console.assert_eq(self.caller, aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh);
assert_eq(self.caller, aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh);
// Resolve the winner of the auction.
if (first.amount >= second.amount) {
return first;
Expand All @@ -58,7 +58,7 @@ program auction.aleo {
// Assumes that the function is invoked only after all bids have been resolved.
transition finish(bid: Bid) -> Bid {
// Ensure the caller is the auctioneer.
console.assert_eq(self.caller, aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh);
assert_eq(self.caller, aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh);
// Return 'is_winner' as 'true' in the winning 'Bid'.
return Bid {
owner: bid.bidder,
Expand Down
2 changes: 1 addition & 1 deletion basic_bank/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Can you find any others?

## Language Features and Concepts
- `record` declarations
- `console.assert_eq`
- `assert_eq`
- core functions, e.g. `BHP256::hash`
- record ownership
- loops and bounded iteration
Expand Down
4 changes: 2 additions & 2 deletions basic_bank/src/main.leo
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ program basic_bank.aleo {
// Requires that the function caller is the bank.
// The bank's address is aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a.
transition issue(owner: address, amount: u64) -> Token {
console.assert_eq(self.caller, aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a);
assert_eq(self.caller, aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a);
return Token {
owner: owner,
gates: 0u64,
Expand Down Expand Up @@ -61,7 +61,7 @@ program basic_bank.aleo {
// - `periods` : The number of periods to compound the interest over.
// Requires that the function caller is the bank.
transition withdraw(recipient: address, amount: u64, rate: u64, periods: u64) -> Token {
console.assert_eq(self.caller, aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a);
assert_eq(self.caller, aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a);
let hash: field = BHP256::hash(recipient);

let total: u64 = calculate_interest(amount, rate, periods);
Expand Down
6 changes: 3 additions & 3 deletions battleship/imports/board.leo
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ program board.aleo {
board: board_state,
) -> board_state {
// Ensure this board hasn't been used to start a game before.
console.assert(!board.game_started);
assert(!board.game_started);

return board_state {
owner: board.owner,
Expand All @@ -72,11 +72,11 @@ program board.aleo {
let flip_bit: u64 = shoot - 1u64;
// bitwise and operation
let check_move: u64 = shoot & flip_bit;
console.assert_eq(check_move, 0u64);
assert_eq(check_move, 0u64);

// Need to make sure shoot is a valid move given the played_tiles: no bits should overlap.
let check_tiles: u64 = shoot & board.played_tiles;
console.assert_eq(check_tiles, 0u64);
assert_eq(check_tiles, 0u64);

// Update played tiles.
let played_tiles: u64 = board.played_tiles | shoot;
Expand Down
4 changes: 2 additions & 2 deletions battleship/imports/verify.leo
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ program verify.aleo {
) -> bool {
// Check bitcount -- all other validations depend on the bitcount being correct.
let num_bits: u64 = bitcount(ship);
console.assert_eq(num_bits, length);
assert_eq(num_bits, length);

// Check horizontal bits of ship.
let is_adjacent: bool = adjacency_check(ship, horizontal); // True if bits are adjacent horizontally.
Expand Down Expand Up @@ -119,7 +119,7 @@ program verify.aleo {
let ships: u64 = carrier | battleship | cruiser | destroyer;

let num_bits: u64 = bitcount(ships);
console.assert_eq(num_bits, 14u64); // Given 4 individually-valid ships, a valid combination should yield exactly 14 flipped bits.
assert_eq(num_bits, 14u64); // Given 4 individually-valid ships, a valid combination should yield exactly 14 flipped bits.

return ships;
}
Expand Down
18 changes: 9 additions & 9 deletions battleship/src/main.leo
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ program battleship.aleo {
) -> board.leo/board_state.record {
// Verify that each individual ship placement bitstring is valid.
let valid_carrier: bool = verify.leo/validate_ship(carrier, 5u64, 31u64, 4311810305u64);
console.assert(valid_carrier);
assert(valid_carrier);

let valid_battleship: bool = verify.leo/validate_ship(battleship, 4u64, 15u64, 16843009u64);
console.assert(valid_battleship);
assert(valid_battleship);

let valid_cruiser: bool = verify.leo/validate_ship(cruiser, 3u64, 7u64, 65793u64);
console.assert(valid_cruiser);
assert(valid_cruiser);

let valid_destroyer: bool = verify.leo/validate_ship(destroyer, 2u64, 3u64, 257u64);
console.assert(valid_destroyer);
assert(valid_destroyer);

// Create the board with all the ship placements combined.
let board: u64 = verify.leo/create_board(carrier, battleship, cruiser, destroyer);
Expand Down Expand Up @@ -62,8 +62,8 @@ program battleship.aleo {
move_start: move.leo/move.record,
) -> (board.leo/board_state.record, move.leo/move.record) {
// Validate that the move players and board players match each other.
console.assert_eq(board.player_1, move_start.player_2);
console.assert_eq(board.player_2, move_start.player_1);
assert_eq(board.player_1, move_start.player_2);
assert_eq(board.player_2, move_start.player_1);

let state: board_state = board.leo/start_board(board);
let dummy: move = move.leo/start_game(board.player_2);
Expand All @@ -83,11 +83,11 @@ program battleship.aleo {
) -> (board.leo/board_state.record, move.leo/move.record) {
// Verify the board has been started. This prevents players from starting a game and then creating
// a brand new board to play with.
console.assert(board.game_started);
assert(board.game_started);

// Validate that the move players and board players match each other.
console.assert_eq(board.player_1, move_incoming.player_2);
console.assert_eq(board.player_2, move_incoming.player_1);
assert_eq(board.player_1, move_incoming.player_2);
assert_eq(board.player_2, move_incoming.player_1);

// Play coordinate on own board. Will fail if not a valid move.
let hit_or_miss: board_state = board.leo/update_played_tiles(board, shoot);
Expand Down
6 changes: 3 additions & 3 deletions tictactoe/src/main.leo
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ program tictactoe.aleo {
// If an entry is already occupied, the move is invalid and the board is returned unchanged.
transition make_move(player: u8, row: u8, col: u8, board: Board) -> (Board, u8) {
// Check that inputs are valid.
console.assert(player == 1u8 || player == 2u8);
console.assert(1u8 <= row && row <= 3u8);
console.assert(1u8 <= col && col <= 3u8);
assert(player == 1u8 || player == 2u8);
assert(1u8 <= row && row <= 3u8);
assert(1u8 <= col && col <= 3u8);

// Unpack the entries in the board into variables.
let r1c1: u8 = board.r1.c1;
Expand Down
2 changes: 1 addition & 1 deletion vote/src/main.leo
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ program vote.aleo {
// Propose a new proposal to vote on.
transition propose(public info: ProposalInfo) -> Proposal {
// Authenticate proposer.
console.assert_eq(self.caller, info.proposer);
assert_eq(self.caller, info.proposer);

// Generate a new proposal id.
let id: field = BHP256::hash(info.title);
Expand Down