Update examples to use transition keyword

This commit is contained in:
Pranav Gaddamadugu 2022-10-03 11:22:37 -07:00
parent e7e01b23a9
commit a886357585
25 changed files with 48 additions and 96 deletions

View File

@ -19,8 +19,7 @@ record Bid {
// Requires that `bidder` matches the function caller. // Requires that `bidder` matches the function caller.
// The owner of the record is set to the entity responsible for running the auction (auction runner). // The owner of the record is set to the entity responsible for running the auction (auction runner).
// The address of the auction runner is aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh. // The address of the auction runner is aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh.
@program transition place_bid(bidder: address, amount: u64) -> Bid {
function place_bid(bidder: address, amount: u64) -> Bid {
// Ensure the caller is the auction bidder. // Ensure the caller is the auction bidder.
console.assert_eq(self.caller, bidder); console.assert_eq(self.caller, bidder);
// Return a new 'Bid' record for the auction bidder. // Return a new 'Bid' record for the auction bidder.
@ -39,8 +38,7 @@ function place_bid(bidder: address, amount: u64) -> Bid {
// Requires that the function caller is the auction runner. // Requires that the function caller is the auction runner.
// Assumes that the function is invoked only after the bidding period has ended. // Assumes that the function is invoked only after the bidding period has ended.
// In the event of a tie, the first bid is selected. // In the event of a tie, the first bid is selected.
@program transition resolve(first: Bid, second: Bid) -> Bid {
function resolve(first: Bid, second: Bid) -> Bid {
// Ensure the caller is the auctioneer. // Ensure the caller is the auctioneer.
console.assert_eq(self.caller, aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh); console.assert_eq(self.caller, aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh);
// Resolve the winner of the auction. // Resolve the winner of the auction.
@ -55,8 +53,7 @@ function resolve(first: Bid, second: Bid) -> Bid {
// - `bid` : The winning bid. // - `bid` : The winning bid.
// Requires that the function caller is the auction runner. // Requires that the function caller is the auction runner.
// Assumes that the function is invoked only after all bids have been resolved. // Assumes that the function is invoked only after all bids have been resolved.
@program transition finish(bid: Bid) -> Bid {
function finish(bid: Bid) -> Bid {
// Ensure the caller is the auctioneer. // Ensure the caller is the auctioneer.
console.assert_eq(self.caller, aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh); console.assert_eq(self.caller, aleo1fxs9s0w97lmkwlcmgn0z3nuxufdee5yck9wqrs0umevp7qs0sg9q5xxxzh);
// Return 'is_winner' as 'true' in the winning 'Bid'. // Return 'is_winner' as 'true' in the winning 'Bid'.

View File

@ -17,8 +17,7 @@ mapping balances: field => u64;
// - `amount`: The amount of tokens to issue. // - `amount`: The amount of tokens to issue.
// Requires that the function caller is the bank. // Requires that the function caller is the bank.
// The bank's address is aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a. // The bank's address is aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a.
@program transition issue(owner: address, amount: u64) -> Token {
function issue(owner: address, amount: u64) -> Token {
console.assert_eq(self.caller, aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a); console.assert_eq(self.caller, aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a);
return Token { return Token {
owner: owner, owner: owner,
@ -31,8 +30,7 @@ function issue(owner: address, amount: u64) -> Token {
// Returns a new Token with the remaining amount of money. // Returns a new Token with the remaining amount of money.
// - `token` : A record containing tokens to deposit. // - `token` : A record containing tokens to deposit.
// - `amount`: The amount of tokens to deposit. // - `amount`: The amount of tokens to deposit.
@program transition deposit(token: Token, amount: u64) -> Token {
function deposit(token: Token, amount: u64) -> Token {
let difference: u64 = token.amount - amount; let difference: u64 = token.amount - amount;
let remaining: Token = Token { let remaining: Token = Token {
@ -62,8 +60,7 @@ finalize deposit(hash: field, amount: u64) {
// - `rate` : The compound interest rate. // - `rate` : The compound interest rate.
// - `periods` : The number of periods to compound the interest over. // - `periods` : The number of periods to compound the interest over.
// Requires that the function caller is the bank. // Requires that the function caller is the bank.
@program transition withdraw(recipient: address, amount: u64, rate: u64, periods: u64) -> Token {
function withdraw(recipient: address, amount: u64, rate: u64, periods: u64) -> Token {
console.assert_eq(self.caller, aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a); console.assert_eq(self.caller, aleo1t0uer3jgtsgmx5tq6x6f9ecu8tr57rzzfnc2dgmcqldceal0ls9qf6st7a);
let hash: field = BHP256::hash(recipient); let hash: field = BHP256::hash(recipient);

View File

@ -20,8 +20,7 @@ record board_state {
} }
// Returns a new board_state. // Returns a new board_state.
@program transition new_board_state(
function new_board_state(
ships: u64, ships: u64,
opponent: address, opponent: address,
) -> board_state { ) -> board_state {
@ -39,8 +38,7 @@ function new_board_state(
// Returns a new board state that has been started. // Returns a new board state that has been started.
// Fails if this board has been started before. // Fails if this board has been started before.
@program transition start_board(
function start_board(
// The record of the board to start. A board can only be started once. // The record of the board to start. A board can only be started once.
board: board_state, board: board_state,
) -> board_state { ) -> board_state {
@ -61,8 +59,7 @@ function start_board(
// Returns a new board state record that includes all the played tiles. // Returns a new board state record that includes all the played tiles.
// Fails if r1 has been played before. // Fails if r1 has been played before.
@program transition update_played_tiles(
function update_played_tiles(
// The record of the board to update. // The record of the board to update.
board: board_state, board: board_state,
// The u64 equivalent of a bitstring fire coordinate to send to the opponent. // The u64 equivalent of a bitstring fire coordinate to send to the opponent.
@ -94,8 +91,7 @@ function update_played_tiles(
} }
// Returns a new board state record that includes all the hits and misses. // Returns a new board state record that includes all the hits and misses.
@program transition update_hits_and_misses(
function update_hits_and_misses(
// The record of the board to update. // The record of the board to update.
board: board_state, board: board_state,
// The u64 equivalent of a bitstring of whether this player's previous move was a hit or miss. // The u64 equivalent of a bitstring of whether this player's previous move was a hit or miss.

View File

@ -9,8 +9,7 @@ record move {
} }
// Returns new move record owned by the opponent. // Returns new move record owned by the opponent.
@program transition create_move(
function create_move(
// The move record created by the opponent. // The move record created by the opponent.
move_record: move, move_record: move,
// The u64 representation of incoming_fire_coordinate, the bitstring fire coordinate to send to the opponent. // The u64 representation of incoming_fire_coordinate, the bitstring fire coordinate to send to the opponent.
@ -34,8 +33,7 @@ function create_move(
// Returns the move record owned by the opponent. // Returns the move record owned by the opponent.
// Note, this move record contains dummy fire coordinates and previous hit or miss. // Note, this move record contains dummy fire coordinates and previous hit or miss.
@program transition start_game(player_2: address) -> move {
function start_game(player_2: address) -> move {
return move { return move {
owner: player_2, owner: player_2,
gates: 0u64, gates: 0u64,

View File

@ -74,8 +74,7 @@ function horizontal_check(
} }
// Returns `true` if the ship placement is valid. // Returns `true` if the ship placement is valid.
@program transition validate_ship(
function validate_ship(
// The u64 representation of a ship's placement in an 8x8 grid. // The u64 representation of a ship's placement in an 8x8 grid.
ship: u64, ship: u64,
// The length of the placed ship. // The length of the placed ship.
@ -104,8 +103,7 @@ function validate_ship(
// Returns the u64 representation of all the ships' placements in an 8x8 grid. This function will fail // Returns the u64 representation of all the ships' placements in an 8x8 grid. This function will fail
// if any of the ship placements overlap each other. // if any of the ship placements overlap each other.
@program transition create_board(
function create_board(
// The u64 representation of a carrier's placement in an 8x8 grid. Length = 5. // The u64 representation of a carrier's placement in an 8x8 grid. Length = 5.
carrier: u64, carrier: u64,
// The u64 representation of a battleship's placement in an 8x8 grid. Length = 4. // The u64 representation of a battleship's placement in an 8x8 grid. Length = 4.

View File

@ -4,8 +4,7 @@ import move.leo;
import verify.leo; import verify.leo;
// Returns a new record representing a new game of battleship. // Returns a new record representing a new game of battleship.
@program transition initialize_board(
function initialize_board(
// The u64 representation of a carrier's placement in an 8x8 grid. Length = 5. // The u64 representation of a carrier's placement in an 8x8 grid. Length = 5.
carrier: u64, carrier: u64,
// The u64 representation of a battleship's placement in an 8x8 grid. Length = 4. // The u64 representation of a battleship's placement in an 8x8 grid. Length = 4.
@ -42,8 +41,7 @@ function initialize_board(
// Returns an updated board state record that has been started. This board cannot be used to start any other games. // Returns an updated board state record that has been started. This board cannot be used to start any other games.
// Returns a dummy move record owned by the opponent. // Returns a dummy move record owned by the opponent.
// This function commits a given board to a game with an opponent and creates the initial dummy move. // This function commits a given board to a game with an opponent and creates the initial dummy move.
@program transition offer_battleship(
function offer_battleship(
// The board record to start a game with. // The board record to start a game with.
board: board.leo/board_state.record, board: board.leo/board_state.record,
) -> (board.leo/board_state.record, move.leo/move.record) { ) -> (board.leo/board_state.record, move.leo/move.record) {
@ -55,8 +53,7 @@ function offer_battleship(
// Returns updated board_state.record that has been started and can no longer be used to join or start new games. // Returns updated board_state.record that has been started and can no longer be used to join or start new games.
// Returns dummy move record owned by the opponent. // Returns dummy move record owned by the opponent.
@program transition start_battleship(
function start_battleship(
// The board record to play the game with. // The board record to play the game with.
board: board.leo/board_state.record, board: board.leo/board_state.record,
// The move record to play to begin the game. This should be the dummy move record created from offer_battleship. // The move record to play to begin the game. This should be the dummy move record created from offer_battleship.
@ -74,8 +71,7 @@ function start_battleship(
// Returns updated board record. // Returns updated board record.
// Returns new move record owned by opponent. // Returns new move record owned by opponent.
@program transition play(
function play(
// The board record to update. // The board record to update.
board: board.leo/board_state.record, board: board.leo/board_state.record,
// The incoming move from the opponent. // The incoming move from the opponent.

View File

@ -16,8 +16,7 @@
// Note that the implementation below uses tuples instead of arrays. // Note that the implementation below uses tuples instead of arrays.
// The implementation also manually unrolls the loop. // The implementation also manually unrolls the loop.
@program transition bubble_sort(
function bubble_sort(
arr0: u32, arr0: u32,
arr1: u32, arr1: u32,
arr2: u32, arr2: u32,

View File

@ -2,8 +2,7 @@
// Core functions are built-in to the Leo language and call handwritten, optimized circuits in the AVM. // Core functions are built-in to the Leo language and call handwritten, optimized circuits in the AVM.
// To call a core function, use the correct capitalized identifier followed by two colons // To call a core function, use the correct capitalized identifier followed by two colons
// and then the function name. Example: `Pedersen64::hash()`. // and then the function name. Example: `Pedersen64::hash()`.
@program transition main(a: field) -> field {
function main(a: field) -> field {
let b: field = BHP256::hash(a); let b: field = BHP256::hash(a);
let c: field = Poseidon2::hash(b); let c: field = Poseidon2::hash(b);
let d: field = BHP256::commit(c, 1scalar); let d: field = BHP256::commit(c, 1scalar);

View File

@ -1,8 +1,7 @@
// This function takes a group coordinate as input `a` and performs several operations which should output the `0group`. // This function takes a group coordinate as input `a` and performs several operations which should output the `0group`.
// Note that the operations can be called as associated functions on the `a` variable. // Note that the operations can be called as associated functions on the `a` variable.
@program transition main(a: group) -> group {
function main(a: group) -> group {
// unary // unary
let e: group = a.double(); // 2a let e: group = a.double(); // 2a
let g: group = e.neg(); // -2a let g: group = e.neg(); // -2a

View File

@ -1,7 +1,6 @@
// The 'ntzdebruijn' main function. // The 'ntzdebruijn' main function.
// From Hacker's Delight 2nd ed. figure 5-26 // From Hacker's Delight 2nd ed. figure 5-26
@program transition main(public x: u32) -> u8 {
function main(public x: u32) -> u8 {
if x == 0u32 {return 32u8;} if x == 0u32 {return 32u8;}
// 0x04D7651F = 81224991 // 0x04D7651F = 81224991
x = (x & 0u32.sub_wrapped(x)).mul_wrapped(81224991u32); x = (x & 0u32.sub_wrapped(x)).mul_wrapped(81224991u32);

View File

@ -1,7 +1,6 @@
// The 'ntzgaudet' main function. // The 'ntzgaudet' main function.
// From Hacker's Delight 2nd ed. figure 5-24 // From Hacker's Delight 2nd ed. figure 5-24
@program transition main(public x: u32) -> u8 {
function main(public x: u32) -> u8 {
let y: u32 = x & 0u32.sub_wrapped(x); // Isolate rightmost 1-bit let y: u32 = x & 0u32.sub_wrapped(x); // Isolate rightmost 1-bit
let bz: u8 = (y != 0u32) ? 0u8 : 1u8; let bz: u8 = (y != 0u32) ? 0u8 : 1u8;
// 0x0000FFFF = 65535 // 0x0000FFFF = 65535

View File

@ -1,7 +1,6 @@
// The 'ntzloops' main function. // The 'ntzloops' main function.
// From Hacker's Delight 2nd ed. figure 5-23 // From Hacker's Delight 2nd ed. figure 5-23
@program transition main(public x: u32) -> u8 {
function main(public x: u32) -> u8 {
x = !x & x.sub_wrapped(1u32); x = !x & x.sub_wrapped(1u32);
let n: u8 = 0u8; let n: u8 = 0u8;
for i:u8 in 0u8..32u8 { for i:u8 in 0u8..32u8 {

View File

@ -1,7 +1,6 @@
// The 'ntzmasks' main function. // The 'ntzmasks' main function.
// From Hacker's Delight 2nd ed. figure 5-20 // From Hacker's Delight 2nd ed. figure 5-20
@program transition main(public x: u32) -> u8 {
function main(public x: u32) -> u8 {
if (x == 0u32) {return 32u8;} if (x == 0u32) {return 32u8;}
let n: u8 = 1u8; let n: u8 = 1u8;
// x >>= 16u8 wasn't working, and I don't want to use // x >>= 16u8 wasn't working, and I don't want to use

View File

@ -1,7 +1,6 @@
// The 'ntzreisers' main function. // The 'ntzreisers' main function.
// From Hacker's Delight 2nd ed. figure 5-27 // From Hacker's Delight 2nd ed. figure 5-27
@program transition main(public x: u32) -> u8 {
function main(public x: u32) -> u8 {
x = (x & 0u32.sub_wrapped(x)).rem_wrapped(37u32); x = (x & 0u32.sub_wrapped(x)).rem_wrapped(37u32);
return reisersTableLookup(x); return reisersTableLookup(x);
} }

View File

@ -1,7 +1,6 @@
// The 'nztseals' main function. // The 'nztseals' main function.
// From Hacker's Delight 2nd ed. figure 5-25 // From Hacker's Delight 2nd ed. figure 5-25
@program transition main(public x: u32) -> u8 {
function main(public x: u32) -> u8 {
// 0x0450FBAF = 72416175 // 0x0450FBAF = 72416175
x = (x & 0u32.sub_wrapped(x)).mul_wrapped(72416175u32); x = (x & 0u32.sub_wrapped(x)).mul_wrapped(72416175u32);
return sealsTableLookup(x >> 26u8); return sealsTableLookup(x >> 26u8);

View File

@ -1,8 +1,7 @@
// The 'ntzsearchtree' main function. // The 'ntzsearchtree' main function.
// From Hacker's Delight 2nd ed. figure 5-22, // From Hacker's Delight 2nd ed. figure 5-22,
// expanded to a 32-bit version. // expanded to a 32-bit version.
@program transition main(public x: u32) -> u8 {
function main(public x: u32) -> u8 {
if (x & 65535u32 != 0u32) { if (x & 65535u32 != 0u32) {
if (x & 255u32 != 0u32) { if (x & 255u32 != 0u32) {
if (x & 15u32 != 0u32) { if (x & 15u32 != 0u32) {

View File

@ -1,7 +1,6 @@
// The 'ntzsmallvals' main function. // The 'ntzsmallvals' main function.
// From Hacker's Delight 2nd ed. figure 5-21 // From Hacker's Delight 2nd ed. figure 5-21
@program transition main(public x: u32) -> u8 {
function main(public x: u32) -> u8 {
if (x == 0u32) {return 32u8;} if (x == 0u32) {return 32u8;}
let n: u8 = 31u8; let n: u8 = 31u8;
let y: u32 = x.shl_wrapped(16u8); if (y != 0u32) {n = n - 16u8; x = y;} let y: u32 = x.shl_wrapped(16u8); if (y != 0u32) {n = n - 16u8; x = y;}

View File

@ -1,5 +1,4 @@
// The 'helloworld' main function. // The 'helloworld' main function.
@program transition main(public a: u32, b: u32) -> u32 {
function main(public a: u32, b: u32) -> u32 {
return a + b; return a + b;
} }

View File

@ -1,7 +1,6 @@
// This function calculates the interest accrued // This function calculates the interest accrued
// over ten iterations for some `capital` and `rate`. // over ten iterations for some `capital` and `rate`.
@program transition fixed_iteration_interest(capital: u32, public rate: u32) -> u32 {
function fixed_iteration_interest(capital: u32, public rate: u32) -> u32 {
let amount: u32 = capital; let amount: u32 = capital;
// Accrue for exactly 10 iterations. // Accrue for exactly 10 iterations.
@ -15,8 +14,7 @@ function fixed_iteration_interest(capital: u32, public rate: u32) -> u32 {
// This function calculates the interest accrued // This function calculates the interest accrued
// over a variable number of iterations (max 50) for some `capital` and `rate`. // over a variable number of iterations (max 50) for some `capital` and `rate`.
@program transition bounded_iteration_interest(capital: u32,
function bounded_iteration_interest(capital: u32,
public rate: u32, public rate: u32,
iterations: u8) -> u32 { iterations: u8) -> u32 {
console.assert(iterations <= 50u8); console.assert(iterations <= 50u8);

View File

@ -10,8 +10,7 @@ struct Message {
// The "main" function of this Leo program takes a "Message" struct type as input. // The "main" function of this Leo program takes a "Message" struct type as input.
// To see how to input variable "m" is passed in open up `inputs/message.in`. // To see how to input variable "m" is passed in open up `inputs/message.in`.
@program transition main(m: Message) -> field {
function main(m: Message) -> field {
// 1. Define the "Message" type. // 1. Define the "Message" type.
// 2. Use brackets `{ }` to enclose the struct members. // 2. Use brackets `{ }` to enclose the struct members.

View File

@ -12,8 +12,7 @@ record Token {
// The `mint` function initializes a new record with the // The `mint` function initializes a new record with the
// specified number of tokens assigned to the specified receiver. // specified number of tokens assigned to the specified receiver.
@program transition mint(owner: address, amount: u64) -> Token {
function mint(owner: address, amount: u64) -> Token {
return Token { return Token {
owner: owner, owner: owner,
gates: 0u64, gates: 0u64,
@ -23,8 +22,7 @@ function mint(owner: address, amount: u64) -> Token {
// The `transfer` function sends the specified number of tokens // The `transfer` function sends the specified number of tokens
// to the receiver from the provided token record. // to the receiver from the provided token record.
@program transition transfer(token: Token, to: address, amount: u64) -> (Token, Token) {
function transfer(token: Token, to: address, amount: u64) -> (Token, Token) {
// Checks the given token record has sufficient balance. // Checks the given token record has sufficient balance.
// This `sub` operation is safe, and the proof will fail // This `sub` operation is safe, and the proof will fail

View File

@ -21,8 +21,7 @@ struct Board {
} }
// Returns an empty board. // Returns an empty board.
@program transition new() -> Board {
function new() -> Board {
return Board { return Board {
r1: Row { c1: 0u8, c2: 0u8, c3: 0u8 }, r1: Row { c1: 0u8, c2: 0u8, c3: 0u8 },
r2: Row { c1: 0u8, c2: 0u8, c3: 0u8 }, r2: Row { c1: 0u8, c2: 0u8, c3: 0u8 },
@ -54,8 +53,7 @@ function check_for_win(b: Board, p: u8) -> bool {
// Assumes that `player` is either 1 or 2. // Assumes that `player` is either 1 or 2.
// Assumes that `row` and `col` are valid indices into the board. // Assumes that `row` and `col` are valid indices into the board.
// If an entry is already occupied, the move is invalid and the board is returned unchanged. // If an entry is already occupied, the move is invalid and the board is returned unchanged.
@program transition make_move(player: u8, row: u8, col: u8, board: Board) -> (Board, u8) {
function make_move(player: u8, row: u8, col: u8, board: Board) -> (Board, u8) {
// Check that inputs are valid. // Check that inputs are valid.
console.assert(player == 1u8 || player == 2u8); console.assert(player == 1u8 || player == 2u8);
console.assert(1u8 <= row && row <= 3u8); console.assert(1u8 <= row && row <= 3u8);

View File

@ -14,8 +14,7 @@ record token {
/* Mint */ /* Mint */
// The function `mint_public` issues the specified token amount for the token receiver publicly on the network. // The function `mint_public` issues the specified token amount for the token receiver publicly on the network.
@program transition mint_public(public receiver: address, public amount: u64) {
function mint_public(public receiver: address, public amount: u64) {
// Mint the tokens publicly by invoking the computation on-chain. // Mint the tokens publicly by invoking the computation on-chain.
async finalize(receiver, amount); async finalize(receiver, amount);
} }
@ -28,8 +27,7 @@ finalize mint_public(public receiver: address, public amount: u64) {
} }
// The function `mint_private` initializes a new record with the specified amount of tokens for the receiver. // The function `mint_private` initializes a new record with the specified amount of tokens for the receiver.
@program transition mint_private(receiver: address, amount: u64) -> token {
function mint_private(receiver: address, amount: u64) -> token {
return token { return token {
owner: receiver, owner: receiver,
gates: 0u64, gates: 0u64,
@ -38,8 +36,7 @@ function mint_private(receiver: address, amount: u64) -> token {
} }
/* Transfer */ /* Transfer */
@program transition transfer_public(public receiver: address, public amount: u64) {
function transfer_public(public receiver: address, public amount: u64) {
// Transfer the tokens publicly, by invoking the computation on-chain. // Transfer the tokens publicly, by invoking the computation on-chain.
async finalize(self.caller, receiver, amount); async finalize(self.caller, receiver, amount);
} }
@ -56,8 +53,7 @@ finalize transfer_public(public sender: address, public receiver: address, publi
} }
// The function `transfer_private` sends the specified token amount to the token receiver from the specified token record. // The function `transfer_private` sends the specified token amount to the token receiver from the specified token record.
@program transition transfer_private(sender: token, receiver: address, amount: u64) -> (token, token) {
function transfer_private(sender: token, receiver: address, amount: u64) -> (token, token) {
// Checks the given token record has sufficient balance. // Checks the given token record has sufficient balance.
// This `sub` operation is safe, and the proof will fail if an overflow occurs. // This `sub` operation is safe, and the proof will fail if an overflow occurs.
// `difference` holds the change amount to be returned to sender. // `difference` holds the change amount to be returned to sender.
@ -83,8 +79,7 @@ function transfer_private(sender: token, receiver: address, amount: u64) -> (tok
// The function `transfer_private_to_public` turns a specified token amount from a token record into public tokens for the specified receiver. // The function `transfer_private_to_public` turns a specified token amount from a token record into public tokens for the specified receiver.
// This function preserves privacy for the sender's record, however it publicly reveals the token receiver and the token amount. // This function preserves privacy for the sender's record, however it publicly reveals the token receiver and the token amount.
@program transition transfer_private_to_public(sender: token, public receiver: address, public amount: u64) -> token {
function transfer_private_to_public(sender: token, public receiver: address, public amount: u64) -> token {
// Checks the given token record has a sufficient token amount. // Checks the given token record has a sufficient token amount.
// This `sub` operation is safe, and the proof will fail if an underflow occurs. // This `sub` operation is safe, and the proof will fail if an underflow occurs.
// `difference` holds the change amount for the caller. // `difference` holds the change amount for the caller.
@ -113,8 +108,7 @@ finalize transfer_private_to_public(public receiver: address, public amount: u64
// The function `transfer_public_to_private` turns a specified token amount from `account` into a token record for the specified receiver. // The function `transfer_public_to_private` turns a specified token amount from `account` into a token record for the specified receiver.
// This function preserves privacy for the receiver's record, however it publicly reveals the caller and the specified token amount. // This function preserves privacy for the receiver's record, however it publicly reveals the caller and the specified token amount.
@program transition transfer_public_to_private(public receiver: address, public amount: u64) -> token {
function transfer_public_to_private(public receiver: address, public amount: u64) -> token {
// Produces a token record for the token receiver. // Produces a token record for the token receiver.
let transferred: token = token { let transferred: token = token {
owner: receiver, owner: receiver,

View File

@ -1,7 +1,6 @@
// This function calculates the number of powers of two ("twoadicity") // This function calculates the number of powers of two ("twoadicity")
// in the prime factorization of the input number `n`. // in the prime factorization of the input number `n`.
@program transition main(public n: field) -> u8 {
function main(public n: field) -> u8 {
let remaining_n: field = n; let remaining_n: field = n;
let powers_of_two: u8 = 0u8; let powers_of_two: u8 = 0u8;
// Since field ints are 253 bits or fewer, any number in the field // Since field ints are 253 bits or fewer, any number in the field

View File

@ -33,8 +33,7 @@ mapping agree_votes: field => u64;
mapping disagree_votes: field => u64; mapping disagree_votes: field => u64;
// Propose a new proposal to vote on. // Propose a new proposal to vote on.
@program transition propose(public info: ProposalInfo) -> Proposal {
function propose(public info: ProposalInfo) -> Proposal {
// Authenticate proposer. // Authenticate proposer.
console.assert_eq(self.caller, info.proposer); console.assert_eq(self.caller, info.proposer);
@ -58,8 +57,7 @@ finalize propose(public id: field) {
} }
// Create a new ticket to vote with. // Create a new ticket to vote with.
@program transition new_ticket(
function new_ticket(
public pid: field, public pid: field,
public voter: address, public voter: address,
) -> Ticket { ) -> Ticket {
@ -78,8 +76,7 @@ finalize new_ticket(public pid: field) {
} }
// Vote privately to agree with a proposal. // Vote privately to agree with a proposal.
@program transition agree(ticket: Ticket) {
function agree(ticket: Ticket) {
// Finalize this vote. // Finalize this vote.
async finalize(ticket.pid); async finalize(ticket.pid);
} }
@ -89,8 +86,7 @@ finalize agree(public pid: field) {
} }
// Vote privately to disagree with a proposal. // Vote privately to disagree with a proposal.
@program transition disagree(ticket: Ticket) {
function disagree(ticket: Ticket) {
// Finalize this vote. // Finalize this vote.
async finalize(ticket.pid); async finalize(ticket.pid);
} }