Skip to content

Instantly share code, notes, and snippets.

View mmagician's full-sized avatar

Marti mmagician

View GitHub Profile
@mmagician
mmagician / pre-commit
Last active March 13, 2024 14:06 — forked from hryniuk/pre-commit-cargo-fmt
Git `pre-commit` hook that checks Rust code style with `cargo fmt`
#!/bin/bash
diff=$(cargo fmt -- --check)
result=$?
if [[ ${result} -ne 0 ]] ; then
cat <<\EOF
There are some code style issues, run `cargo fmt` first.
EOF
exit 1
@mmagician
mmagician / square_benchmarks.md
Last active November 30, 2022 12:13
Square benchmarks

For montgomery squaring

const SAMPLES: usize = 10000;

inside the loop

for i in 1..(2 * N) {
	r[2 * N - i] = (r[2 * N - i] << 1) | (r[2 * N - (i + 1)] >> 63);
}
@mmagician
mmagician / bls12-381-effective-cofactor.sage
Created October 9, 2022 19:42
BLS12-381 effective cofactor
field_modulus = 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787
desired_curve_order = 52435875175126190479447740508185965837690552500527637822603658699938581184513
x = -0xd201000000010000
Fp = GF(field_modulus)
Fr = GF(desired_curve_order)
X = Fp(x)
PARAM_A4 = 0
@mmagician
mmagician / bls12_381-iso_gens.sage
Created July 19, 2022 09:56
BLS12-381 isogeny generators
# Finding the generators of G1 & G2 of a curve isogenous to BLS12-381, which has non-zero A, B coefficients in Short Weierstrass form.
# Script adapted from https://github.com/zkcrypto/bls12_381/blob/main/src/notes/design.rs
# Below are some links to the IETF draft where the isogeny is defined.
param = -0xd201000000010000
def r(x):
return (x**4) - (x**2) + 1
def q(x):
return (((x - 1) ** 2) * ((x**4) - (x**2) + 1) // 3) + x
@mmagician
mmagician / main.py
Created March 11, 2021 18:06
zkSync tutorial
from web3 import Web3, HTTPProvider, Account
from zksync_sdk import ZkSyncProviderV01, HttpJsonRPCTransport, network, ZkSync, EthereumProvider, Wallet, ZkSyncSigner, EthereumSignerWeb3, ZkSyncLibrary
import asyncio
from zksync_sdk.types import ChainId
from dataclasses import dataclass
@dataclass
class Network:
zksync_url: str
@mmagician
mmagician / saveFigure.m
Created February 21, 2016 01:57 — forked from corydolphin/saveFigure.m
Saving figures in MATLAB as full size, not cutoff. Gets around issue of cutting off Title, etc. Slightly slow, but it works. Damnit MATLAB graphics library.
function [ output_args ] = saveFigure( handle, fileName )
% saveFigure
% Saves figure specified by `handle` as `fileName` in fullscreen
% as to get around the stupid behavior.
screen_size = get(0, 'ScreenSize');
origSize = get(handle, 'Position'); % grab original on screen size
set(handle, 'Position', [0 0 screen_size(3) screen_size(4) ] ); %set to scren size
set(handle,'PaperPositionMode','auto') %set paper pos for printing
saveas(handle, fileName) % save figure