Skip to content

Instantly share code, notes, and snippets.

Avatar
🏴‍☠️
My time travel machine is stuck at 60 seconds per minute

HaRold HarryR

🏴‍☠️
My time travel machine is stuck at 60 seconds per minute
View GitHub Profile
@HarryR
HarryR / download-solc.sh
Created Nov 23, 2020
Download solidity compiler
View download-solc.sh
#!/usr/bin/env bash
if [[ -z $1 ]]; then
>&2 echo "Usage: `basename $0` [N.M|latest]"
>&2 echo ""
>&2 echo "Example to download v0.7.2:"
>&2 echo ""
>&2 echo ' $' "`basename $0` 7.2"
>&2 echo ""
>&2 echo "Example to download latest version:"
@HarryR
HarryR / signal.hpp
Created Dec 9, 2019
Tiny declarative signals / event hooks for C++11
View signal.hpp
#pragma once
#include <functional>
template<typename... ArgsT>
struct EventHook;
template<typename... ArgsT>
View automagic.hpp
/// Conditionally enable a function if they share the same CurveT type
/// e.g. template<IsSameCurve<CurveT,OtherType> = 0>
template<typename MyCurve, typename OtherType>
using IsSameCurve = std::enable_if_t<std::is_same<MyCurve,typename OtherType::CurveT>::value,int>;
/// Conditionally enable a function if the are of the same types and curves
/// Uses CanonicalSelfT to determine if they're the same general type
/// e.g. template<IsSameCurve<CurveT,OtherType> = 0>
@HarryR
HarryR / text2sms.py
Created Nov 8, 2019
Text to old-school phone keyboard
View text2sms.py
def text2sms(text):
pairs = [' ', '!', 'abc', 'def', 'ghi', 'jkl', 'mno', 'pqrs', 'tuv', 'wxyz']
mapping = {c:(str(i)*(j+1)) for i,p in enumerate(pairs) for j, c in enumerate(p)}
return '-'.join(mapping[c] for c in text if c in mapping)
@HarryR
HarryR / tal.py
Created Oct 23, 2019
Parse simple(ish) algorithms from whitepapers, do basic optimisations to transform into consistent state
View tal.py
import re
from pypeg2 import word, attr, maybe_some, blank, endl, parse, optional
from collections import defaultdict
class ExprBase(str):
pass
class Expression(ExprBase):
def __str__(self):
return str(self.inside) + ''.join([str(_) for _ in self.rhs])
View zexe_sw6.sage
"""
https://cryptosith.org/michael/data/talks/2013-08-01-SIAMAG13.pdf
https://www.issac-conference.org/2015/Slides/Schost.pdf
http://www.craigcostello.com.au/pairings/PairingsForBeginners.pdf
"""
fresh_compute = False # Perform expensive-(ish) computations for curve orders
field_modulus = 22369874298875696930346742206501054934775599465297184582183496627646774052458024540232479018147881220178054575403841904557897715222633333372134756426301062487682326574958588001132586331462553235407484089304633076250782629492557320825577
desired_curve_order = 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177
View mimc_fp2.py
# Let (L, R) = x, 0
# for i in range(128): (L, R) = (L, R) ** 3 + (k_i1, k_i2) (interpreting the two values as an element of some quadratic field over F_p,
# so the # actual equations are newL = L**3 + 3*q*L*R**2 + k_i1, newR = 3*L**2*R + q*R**3 + k_i2,
from random import randint
q = 21888242871839275222246405745257275088696311157297823662689037894645226208583
q = 199
@HarryR
HarryR / bls12_381.sage
Created Sep 26, 2019
Sage script to derive all necessary parameters for BLS12-381 curve (including frobenius coefficients and montgomery reduction constants etc.)
View bls12_381.sage
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()
@HarryR
HarryR / chacharng.hpp
Created Sep 14, 2019
C++ implementation of Rust's `rand::chacha::ChaChaRng`
View chacharng.hpp
#ifndef CHACHARNG_HPP_
#define CHACHARNG_HPP_
// C++ port of Rust's ChaChaRng
// https://rust-num.github.io/num/src/rand/chacha.rs.html
#include <cstdint>
template<size_t nRounds>
View cocks-pinch-derive-elements.py
D = -3572
k = 6
q = 447231129305840782240237212949663229744995012174421358105320171206333968505891497257173296273883152751267692209531558911549014331037613855148689298263886841953
# log2(q) 527.025659602
t = 678535529027017531887434617617827405828167042133406771522385895475121806814108
r_torsion = 21888242871839275222246405745257275088696311157297823662689037894645226208583
a4 = 42712243339421257868660507567123354675510133075791388004452184727050960820502924907704571467862154994392063936591279133153055638947148552957928421434686670171
a6 = 131738226030767995270565871104903809777878096841386516668655049559644995686736483226876210759529899795643641377453253635430103115971908064841330245626213375876
point_count = 447231129305840782240237212949663229744995012174421358105320171206333968505891496578637767246865620863833074591704153083381972197630842332762793823142080027846
h = point_count // r_torsion