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
@HarryR
HarryR / pipeline.py
Last active January 9, 2025 16:20
Typesafe task pipeline for Python
import time
from dataclasses import dataclass
from typing import Awaitable, Callable, Generic, Iterable, Literal, Tuple, TypeVar, Union
_TaskInputT = TypeVar('_TaskInputT')
_TaskOutputT = TypeVar('_TaskOutputT')
TaskTypeT = Literal['first', 'intermediate', 'final']
@dataclass
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.0;
import { IERC721 } from '@openzeppelin/contracts/token/ERC721/IERC721.sol';
import { IERC721Receiver } from '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol';
import { Staking } from './Staking.sol';
import { randomBytes32 } from './Random.sol';
import { Moderation } from './Moderation.sol';
@HarryR
HarryR / transcriptex.rs
Last active December 23, 2024 01:46
Forking Merlin transcripts
use merlin::Transcript;
pub trait TranscriptExt {
// Proposed method to fork a transcript
fn fork_transcript(&mut self) -> Transcript;
// Proposed method to append another transcript
fn append_transcript(&mut self, other: &mut Transcript);
}
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 / schnorr.py
Last active October 22, 2024 05:38
Implementation of Schnorr signatures over secp256k1 - warning, this is vulnerable to the Related Key Attack...
from __future__ import print_function
from random import randint
from hashlib import sha256
from py_ecc.secp256k1.secp256k1 import add, multiply, inv, N, P, G
bytes_to_int = lambda x: reduce(lambda o, b: (o << 8) + ord(b), [0] + list(x))
rands = lambda: randint(1, N - 1)
sbmul = lambda s: multiply(G, s)
hashs = lambda *x: bytes_to_int(sha256('.'.join(['%X' for _ in range(0, len(x))]) % x).digest()) % N
hashp = lambda *x: hashs(*[item for sublist in x for item in sublist])
@HarryR
HarryR / kanbanflow-monthly-report.py
Last active September 6, 2024 05:51
Monthly reporting for Kanbanflow, produces a Markdown summary of all tasks and the percentage time breakdown daily & across categories
#!/usr/bin/env python3
import os
import re
import sys
import requests
import calendar
from datetime import datetime, timedelta, date
from typing import TypedDict
from collections import defaultdict
@HarryR
HarryR / MiMCp.sol
Last active August 15, 2024 06:37
MiMC-p/p for Solidity
// Copyright (c) 2018 HarryR
// License: LGPL-3.0+
pragma solidity ^0.5.0;
/**
* Implements MiMC-p/p over the altBN scalar field used by zkSNARKs
*
* See: https://eprint.iacr.org/2016/492.pdf
*
@HarryR
HarryR / triangle.html
Created July 28, 2024 18:12
Draws a cool morphing triangle thing
<!DOCTYPE html>
<html>
<head>
<title>Triangle</title>
</head>
<body>
<canvas id="canvas" width=500 height=500></canvas>
<script>
@HarryR
HarryR / KZG10.py
Last active June 3, 2024 02:17
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 / ecrecover.json
Last active April 9, 2024 16:29
ecrecover exploit example
{
"linkReferences": {},
"object": "6060604052341561000f57600080fd5b5b6102338061001f6000396000f300606060405263ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663eca135cb811461003d575b600080fd5b341561004857600080fd5b61009e60046024813581810190830135806020601f820181900481020160405190810160405281815292919060208401838380828437509496505060ff85351694602081013594506040013592506100a0915050565b005b60006001856040518082805190602001908083835b602083106100d557805182525b601f1990920191602091820191016100b5565b6001836020036101000a038019825116818451161790925250505091909101925060409150505180910390208585856040518060005260200160405260006040516020015260405193845260ff90921660208085019190915260408085019290925260608401929092526080909201915160208103908084039060008661646e5a03f1151561016357600080fd5b50506020604051035190503073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415156101a857600080fd5b3373ffffffffffffffffffffffffffffffffffffffff166108fc3073fffffffffffffffffff