Skip to content

Instantly share code, notes, and snippets.

View Th0rgal's full-sized avatar
🕶️

Thomas Marchand Th0rgal

🕶️
  • LFG Labs
  • Lisbon
  • 13:28 (UTC +01:00)
  • X @Th0rgal_
View GitHub Profile
%lang starknet
from starkware.cairo.common.uint256 import Uint256
from src.game import GameData
@contract_interface
namespace IGasLessLiar {
func deposit(amount: Uint256) {
}
import {
useStarknet,
useConnectors,
useStarknetInvoke,
useStarknetTransactionManager,
} from "@starknet-react/core";
import { useEffect } from "react";
import { useRouter } from "next/router";
import { stringToFelt, toFelt } from "../utils/felt";
import styles from "../styles/home.module.css";
[nix-shell:~/workspace/hello]$ python ~/workspace/protostar/binary_entrypoint.py test
22:46:14 [WARNING] Couldn't read protostar package info
22:46:14 [INFO] Collected 1 suite, and 2 test cases (0.027 s)
Unexpected Protostar error. Report it here:
https://github.com/software-mansion/protostar/issues
Traceback (most recent call last):
File "/Users/thomas/workspace/protostar/binary_entrypoint.py", line 11, in <module>
main(Path(__file__).parent)
File "/Users/thomas/workspace/protostar/protostar/start.py", line 23, in main
[FAIL] tests/test_storage.cairo test_my_var
[type] TRANSACTION_FAILED
[code] 39
[details]:
/Users/thomas/.protostar/dist/protostar/starkware/cairo/common/bitwise.cairo:63:21: While expanding the reference 'x_xor_y' in:
return (x_xor_y=x_xor_y)
^*****^
/Users/thomas/.protostar/dist/protostar/starkware/cairo/common/bitwise.cairo:60:19: Error at pc=0:127:
Unknown value for memory cell at address 13:3.
let x_xor_y = bitwise_ptr.x_xor_y
@storage_var
func my_var(id : felt) -> (content : felt):
end
@view
func test_my_var{syscall_ptr : felt*, range_check_ptr, pedersen_ptr : HashBuiltin*}():
alloc_locals
my_var.write(7, 'hello')
let (local keccak_ptr_start : felt*) = alloc()
let keccak_ptr = keccak_ptr_start
func reverse{syscall_ptr : felt*, range_check_ptr, pedersen_ptr : HashBuiltin*}(
arr_len : felt, arr : felt*
) -> (rev_arr_len : felt, rev_arr : felt*):
# if our array is empty (i.e. we reached the end of our recursion)
if arr_len == 0:
let (rev_arr) = alloc()
return (0, rev_arr)
end
%builtins output
from starkware.cairo.common.serialize import serialize_word
from starkware.cairo.common.alloc import alloc
func print_words{output_ptr : felt*}(res_len : felt, res : felt*):
if res_len == 0:
return ()
end
@Th0rgal
Th0rgal / fold_left.cairo
Last active June 6, 2022 14:13
Trying functional programming in cairo. Thanks https://github.com/onlydustxyz/cairo-streams for the inspiration
%builtins output range_check
from starkware.cairo.common.registers import get_label_location
from starkware.cairo.common.serialize import serialize_word
from starkware.cairo.common.alloc import alloc
func main{output_ptr : felt*, range_check_ptr}():
alloc_locals
let (arr : felt*) = alloc()
@Th0rgal
Th0rgal / cairocheat.md
Last active May 26, 2022 17:40
Personal CheatSheet for programming on StarkNet

Checking transaction status

https://alpha4.starknet.io/feeder_gateway/get_transaction_receipt?transactionHash=

Using hints

Go to starkware/starknet/testing/starknet.py In the definition of deploy, you will see there the invocation of compile_starknet_files. Add the argument disable_hints_validation=True

@Th0rgal
Th0rgal / louis.cairo
Last active April 30, 2022 16:47
Demonstration of array usage in cairo
%builtins output
from starkware.cairo.common.alloc import alloc
from starkware.cairo.common.serialize import serialize_word
func print_array{output_ptr : felt*}(res_len : felt, res : felt*):
if res_len == 0:
return ()
end