Home
Cairopractice
Cancel

Understanding upgradability

Starknet gives us, developers, the power to make our contracts upgradable in a native way. Unlike in the EVM world where one has to fiddle with the inferior proxy pattern, in Starknet we can utiliz...

Starknet fee reduction

Multiple factors go into calculating transaction fees on Starknet. The biggest one - use of storage - is going to be addressed by 4844 in a couple of days and by additional measures later this year...

When is get_caller_address zero?

It’s very rare for the caller address (as obtained by get_caller_address()) to be zero on Starknet. Let’s examine when can this happen. The obvious case is when calling a view function. The call i...

Compact module declaration

Here’s a cool technique how to declare all of a project’s modules inside the project root (typically src/lib.cairo) without any intermediary module files. Let’s say we have a project where src/ lo...

Underhanded Cairo, pt. 2. Solution

The results are in. Congratulations to wong_ssh and 0xkaliber, the only two participants who found the attack. Job well done guys! Thank you as well to all the others who gave it a try 🙏 So what’s ...

Underhanded Cairo, pt. 2. Intro

As promised on Twitter, here’s the vulerable contract. It’s a proof of concept, but I tried to make it so that it resembles an actual contract, so there’s more than just the bare minimum for a PoC...

Store packing

One of my favorite recent additions to Cairo is the StorePacking trait: trait StorePacking<T, PackedT> { fn pack(value: T) -> PackedT; fn unpack(value: PackedT) -> T; } A sup...

Using libfuncs

You know how felt division is “disabled” by default in Cairo 1? But what if we really know what we’re doing and are not afraid of shooting ourselves in the foot? It’s actually quite easy to bring i...

Underhanded Cairo, pt. 1

Here’s a pretty simple Cairo program: use debug::PrintTrait; fn calc(v1: u64, v2: u64) -> (u64, u64) { (v1 + v2, v2 * v2) } fn main() { let mut res: u64 = 0; let mut counter: u64 ...

Mock addresses for testing

When writing tests, we often need mock addresses to represent some entity like an account without actually deploying an initializing an account contract. The obvious thing to do is to use values li...