Skip to content

Instantly share code, notes, and snippets.

View HarryR's full-sized 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
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
@HarryR
HarryR / MillerRabin.sol
Last active October 18, 2022 08:04
Miller Rabin probabilistic primality test for Solidity, and RSA-2048 modexp
pragma solidity ^0.5.0;
contract MillerRabin
{
function modexp_rsa2048(uint256[8] memory b, uint256 e)
public view returns(uint256[8] memory result)
{
bool success;
assembly {
let freemem := mload(0x40)
@HarryR
HarryR / KZG10.py
Last active October 4, 2022 11:50
Implementation of PolyCommit_{DL} from "Constant-Size Commitments to Polynomials and Their Applications" https://www.cypherpunks.ca/~iang/pubs/PolyCommit-AsiaCrypt.pdf
from typing import List, NamedTuple, Tuple, Union
from math import ceil, log2
from random import randint
from functools import reduce
import operator
from py_ecc import bn128 as curve
"""
Implementation of PolyCommit_{DL} from:
@HarryR
HarryR / poseidon.py
Last active May 22, 2022 08:32
Starkad and Poseidon: New Hash Functions for Zero Knowledge Proof Systems
#!/usr/bin/env python
"""
Implements the Poseidon permutation:
Starkad and Poseidon: New Hash Functions for Zero Knowledge Proof Systems
- Lorenzo Grassi, Daniel Kales, Dmitry Khovratovich, Arnab Roy, Christian Rechberger, and Markus Schofnegger
- https://eprint.iacr.org/2019/458.pdf
Other implementations:
@HarryR
HarryR / etherscrape.py
Created September 13, 2017 17:20
EtherScan.io contract scraper
#!/usr/bin/env python
from __future__ import print_function
import os
import requests
import codecs
from bs4 import BeautifulSoup
ETHERSCAN_URL = 'https://etherscan.io/'
@HarryR
HarryR / download-solc.sh
Created November 23, 2020 17:56
Download solidity compiler
#!/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:"
/// 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 / signal.hpp
Created December 9, 2019 17:16
Tiny declarative signals / event hooks for C++11
#pragma once
#include <functional>
template<typename... ArgsT>
struct EventHook;
template<typename... ArgsT>
@HarryR
HarryR / text2sms.py
Created November 8, 2019 14:58
Text to old-school phone keyboard
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 October 23, 2019 13:03
Parse simple(ish) algorithms from whitepapers, do basic optimisations to transform into consistent state
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])