Challenge 5: Perfect Pizza
When in Italy, pizza is a way of life. Crafted from simple ingredients with an artful touch, only the perfect combination will gain the approval of the pizzaiolo (master pizza maker). Choose your ingredients wisely—anything less than perfection and your creation won’t pass the test.
In this challenge, you'll need to carefully assemble your pizza using the correct ingredients. The pizzaiolo will judge your creation, and only a perfect pizza will earn you the flag. Attention to detail is key—get it right, or it's back to the kitchen!
Deployed Contract Address:
Package: 0xdd29ddb70eec2828bf8375c9bb3e4c3546f94d9090113fc760adce8010d69762
Contracts
pizza.move
module ctf::pizza {
use std::bcs;
public struct Pizza has store {
olive_oils: u16,
yeast: u16,
flour: u16,
water: u16,
salt: u16,
tomato_sauce: u16,
cheese: u16,
pineapple: u16,
}
public struct PizzaBox has key, store {
id: UID,
pizza: Pizza,
}
public struct Flag has key, store {
id: UID,
user: address
}
const EMamaMiaNonBene: u64 = 0;
#[allow(lint(self_transfer))]
public fun cook(olive_oils: u16, yeast: u16, flour: u16, water: u16, salt: u16, tomato_sauce: u16, cheese: u16, pineapple: u16, ctx: &mut tx_context::TxContext) {
let sender = tx_context::sender(ctx);
let p = Pizza {
olive_oils,
yeast,
flour,
water,
salt,
tomato_sauce,
cheese,
pineapple,
};
transfer::public_transfer(PizzaBox { id: object::new(ctx), pizza: p }, sender);
}
#[allow(lint(self_transfer))]
public fun get_flag(pizzabox: &PizzaBox, ctx: &mut tx_context::TxContext) {
// This is where the Pizzaiolo comes in to judge...
assert!(bcs::to_bytes(&pizzabox.pizza) == x"0a000300620272011200c800b4000000", EMamaMiaNonBene);
transfer::public_transfer(Flag {
id: object::new(ctx),
user: tx_context::sender(ctx)
}, tx_context::sender(ctx));
}
}
The pizzaiolo uses bcs::to_bytes to make sure the ingredients are in order. Make sure you understand how to use this function to pass the test.
Related Articles
Now that your are familiar with the basics of Move, this challenge will introduce a function from the iota-framework which you should be familiar with. After taking a look at the challenge's usage of bcs::to_bytes, we recommend you to take a look at the IOTA Framework documentation to understand how to use it in further challenges.
Good luck in capturing your fifth flag!