Questions tagged [cairo-lang]
20 questions
9
votes
1 answer
Why does this Cairo program put powers of 2 in the memory?
I'm trying to solve this bonus question from the "How Cairo Works" tutorial. I ran the following function, opened the Cairo tracer and saw that the memory is full with powers of 2. Why is that?
func main():
[fp + 1] = 2; ap++
[fp] =…

TorukMakto
- 2,066
- 2
- 24
- 38
6
votes
1 answer
What does it mean to declare a 'local' variable inside a 'let'?
As I understand it, let defines a reference, which can be seen as an alias, so for example let x = y * y * y doesn't compute y * y * y but the occurrences of x will be replaced by y * y * y.
Local variables are similar to other languages local…

Donnoh
- 161
- 10
3
votes
1 answer
How to generate a proof for a Cairo program and verify it?
In SNARKs, you can use Zokrates or snarkjs to generate a proof for a program/computation and verify it, locally or on Ethereum.
Similar to this unanswered question, how to do the same in Cairo and STARK for, say, the 15-puzzle?
Can cairo-run…

sinoTrinity
- 1,125
- 2
- 15
- 27
3
votes
1 answer
when to use tail call optimization in a cairo smartcontract
I can often make a terminal recursive version of my functions with a little less elegant code. Should I do it because it could reduce the fees or should I keep the unoptimised version?
For example, here is an "unoptimised" function which sums…

Th0rgal
- 703
- 8
- 27
2
votes
1 answer
Deploying Cairo contract using Protostar
protostar invoke --contract-address 0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf --function "deployContract" --network testnet --account-address 0x0691622bBFD29e835bA4004e7425A4e9630840EbD11c5269DE51C16774585b16 --max-fee auto…

CCDev
- 23
- 5
2
votes
1 answer
Cairo: let vs tempvar what is the difference?
I'm new to Cairo and I want to know what is the difference when I write let x = 1; and tempvar x = 1;. Is there any difference in Cairo Lang between let and tempvar?

QQQ
- 31
- 3
1
vote
2 answers
How do you optimize gas in Cairo with Uint256/felt?
I’m learning Cairo and I want to know more about Gas Optimization. In Solidity compiler, there is a difference between writing uint128 and uint256. Similarly to C and other languages, for example:
contract ThisIsNotAnOptimizedContract{
uint128…

QQQ
- 31
- 3
1
vote
2 answers
HashBuiltin - Cairo
I am having this contract.cairo:3:59: Unknown identifier 'HashBuiltin'
after doing :
starknet-compile contract.cairo
--output contract_compiled.json
--abi contract_abi.json
code :
@external
func increase_balance{syscall_ptr : felt*,…

newway
- 21
- 1
- 5
1
vote
1 answer
Why does range_check_ptr chek for [0, 2^128) instead of [0, P/2)
According to the doc a felt is a field element, ie any integer between in the range [0, P) with P = 2^251 + 17 * 2^192 + 1.
On the other hand, the range_check_ptr checks that a felt is within [0, 2^128).
I don't understand this limitation : why not…

ClementWalter
- 4,814
- 1
- 32
- 54
1
vote
2 answers
What is the inefficiency in this cairo code using alloc_locals
The following code:
func pow4(n) -> (m : felt):
alloc_locals
local x
jmp body if n != 0
[ap] = 0; ap++
ret
body:
x = n * n
[ap] = x * x; ap++
ret
end
func main():
pow4(n=5)
ret
end
is declared…

ClementWalter
- 4,814
- 1
- 32
- 54
1
vote
1 answer
Checking result of an L1 -> L2 message/invoke in Starknet
I've written a couple contracts for L1 (Ethereum) and L2 (Starknet) and have them communicate here.
I can see that L1 sent the message I'm expecting, see this TX on etherscan. The last message in there however never executed on my L2 contract. I'm…

codemedian
- 117
- 2
- 8
1
vote
1 answer
output_ptr Assertion Error in Main - Cairo-lang
I am going through the official Cairo language tutorial. When I get to the build_dict function for the 15-puzzle, I am a bit confused so would like to print out some things to see.
struct Location:
member row : felt
member col :…

0xTomato
- 108
- 10
0
votes
0 answers
Using the core library hash functions
How do I use the core library Poseidon implementation? I've searched for examples of use on Github and I can't find anything in other resources.
Importing the module is easy enough:
use poseidon::Poseidon;
However I'm not sure how to interact with…

tobluc
- 1
0
votes
0 answers
How can I add tracing information to my Cairo code?
In the old Cairo, it was possible to use with_attr to add debugging information to contracts. What's the equivalent now?

tensojka
- 302
- 1
- 5
- 20
0
votes
1 answer
Error while declaring/deploying a contract on Starknet by using starkli
I'm trying to declare my first contract on Starknet by following the official Starknet tutorial.
The problem is that when I try to declare my contract with this command:
starkli declare path/to/contract.sierra --compiler-version=2.0.1
after having…

Lapo
- 882
- 1
- 12
- 28