Safe CASM{:md}
.
Sierra ensures that programs are always provable by preventing the compilation of programs with infinite loops or invalid constraints.
DECLARE
transactions.
This approach had risks, as the sequencer could not determine whether a given transaction would fail without executing it, and therefore could not charge fees for failed transactions.
Cairo 1 introduced contract class compilation to this new Sierra intermediate representation instead of directly compiling to CASM. The Sierra code is then submitted to the sequencer, compiled down to CASM, and finally executed by the Starknet OS.
Using Sierra ensures that all transactions (including failed ones) are provable, and allows sequencers to charge fees for all submitted transactions, making DoS attacks significantly more expensive.
dup
instruction, which will assign two new identifiers to preserve linearity.
Type declaration is done with the following syntax:
libfuncs
) that represent the call to low-level units of code known to be safe. After type declarations, a Sierra program must define all the libfuncs used in the program along with their expected input types.
Libfunc declaration is done with the following syntax:
return(variable_id)
statement.
felt252
: Represents the field element typefelt252_add
: Performs addition on field elementsstore_temp<felt252>
: Temporarily stores the resultfelt252_add
libfunc to add the values from memory cells 0 and 1, storing the result in memory cell 2store_temp<felt252>
libfunc to prepare the result for the return statementadd_numbers
: Takes two felt252
types in memory cells 0 and 1 and returns a felt252
value by starting at statement 0sierra-text
flag to the library target in your Scarb.toml{:md}
file: