Skip to content

Instantly share code, notes, and snippets.

View 0xNonCents's full-sized avatar

Non 0xNonCents

View GitHub Profile
@HarryR
HarryR / bls12_381.sage
Created September 26, 2019 20:13
Sage script to derive all necessary parameters for BLS12-381 curve (including frobenius coefficients and montgomery reduction constants etc.)
field_modulus = 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787
desired_curve_order = 52435875175126190479447740508185965837690552500527637822603658699938581184513
Fp = GF(field_modulus)
PARAM_A4 = 0
PARAM_A6 = 4
E = EllipticCurve(Fp, [PARAM_A4, PARAM_A6])
E_order = E.order()
@agolajko
agolajko / suez_fp_trick.md
Last active August 8, 2022 22:26
Quick trick for better looping in Cairo

Returning fp for calling functions in Cairo loops

Getting loops to work in Starknet's Cairo can be complicated. Currently you need to fiddle around a lot with ap, fp and pc even for mundane computations. Further, when calling a function within a loop tempvar will be dereferenced causing the loop to fail. For example the following code will not run:

tempvar iterator=10
tempvar sum=0

loop_start:
 let (local a, local b)=div (10, 5)
@milancermak
milancermak / README.md
Last active February 24, 2022 21:00
keccak256 of uint256 in Cairo

This gist contains the following Solidity code translated to Cairo:

uint256 x = 20
uint256 out = uint256(keccak256(abi.encode(x)))

It uses the keccak256 implementation from starknet-l2-storage-verifier lib. The function deals with all the peculiarities of the necessary conversion (endianness, splitting of Uint256 to four 64-bit words and back again). There's also two helper python function to illustrate how to pass arguments in and how to deal with the result.

*
Verifying Drands BLS12-381 Signatures in GoLang
Using the following randomness payloads:
{
"round": 1657526,
"randomness": "58b26a65bf4032555748c2949311abb2c4f580e7d7d7f70b13d0533b793c4c7d",
"signature": "8434e45af135f363b04b792c1d77b83e36ef66829b0a09f7eed058103429f0e7f759ebf6d001cf73e9138f5b7a7f04b602c4167390c323432562d6367e09169422707a9778eba260c4d6434ea5e1d2c81462a4e3cd430990aebc593f4ae7517c",
"previous_signature": "ab9e594732265dd737b536a144fb955bfeabe929116fc78f7bb740de3f43629691cabcec507eeb39a98d51be11942cf4062b0a38dd1be18be5e23bea7efd3935bb23032dba4da0374899e583feb937119f33f6b645048e0e91cde0de00e3e9ee"
},