Starknet Storage Layout

close button

Part I

Simple Variables

Download quests in Questplay

View the contracts and any other additional content from your IDE.

Catacombs is a basic smart contract that has a couple of storage variables. It also has a peculiar write function that allows you to write onto anywhere in storage.

You do not need to worry how write works. You just need to know that the function writes a value onto the contract's storage, at slot_index.

To venture into the dungeon, you first need to open it...

Your Task

Open the catacombs! Set entry_code in Catacombs to 'OPEN_SESAME'.

Contract Code

#[derive(Copy, Drop, Serde, starknet::Store)] struct Chest { is_open: bool, owner: starknet::ContractAddress } #[starknet::interface] trait ICatacombs<TContractState> { fn get_entry_code(self: @TContractState) -> felt252; fn get_brightness(self: @TContractState) -> u256; fn is_tile_safe(self: @TContractState, tile_id: u256) -> bool; fn get_chest(self: @TContractState) -> Chest; fn write(ref self: TContractState, slot_index: felt252, value: felt252); } #[starknet::contract] mod Catacombs { use option::OptionTrait; use starknet::{ storage_write_syscall, SyscallResultTrait }; use traits::TryInto; use super::Chest; #[storage] struct Storage { entry_code: felt252, brightness: u256, safe_tiles: LegacyMap::<u256, bool>, chest: Chest } #[abi(embed_v0)] impl CatacombsImpl of super::ICatacombs<ContractState> { fn get_entry_code(self: @ContractState) -> felt252 { } fn get_brightness(self: @ContractState) -> u256 { } fn is_tile_safe(self: @ContractState, tile_id: u256) -> bool { } fn get_chest(self: @ContractState) -> Chest { } fn write( ref self: ContractState, slot_index: felt252, value: felt252 ) { let storageAddress = slot_index.try_into().unwrap(); let result = storage_write_syscall(0, storageAddress, value); result.unwrap_syscall(); } } }

The carvings around the catacombs’ door are hard to make out, but looking carefully, you see a pattern…