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 / MiMCp.sol
Last active July 16, 2023 03:20
MiMC-p/p for Solidity
View MiMCp.sol
// 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
*
View RandomStorage.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract RandomStorage {
mapping(bytes32 => bytes32) internal data;
event ReadEvent(bytes32 k, bytes32 v);
constructor() {}
@HarryR
HarryR / SapphireShuffle.sol
Last active April 23, 2023 18:04
Shuffle a deck of cards on Oasis Sapphire
View SapphireShuffle.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
contract SapphireShuffle {
address private constant RANDOM_BYTES = 0x0100000000000000000000000000000000000001;
error ErrorGeneratingRandom();
function _random_bytes32()
View WW.sol
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.9;
contract WW
{
event EncryptedResponse(bytes32 nonce, bytes data);
event PublicKey(bytes32 x25519_public);
struct Coupon {
View wrose-example.py
import z3
s = z3.Solver()
bvp = 256
bvs = 2**bvp
balanceOf_signer = z3.BitVec('balanceOf_signer', bvp)
wad = z3.BitVec('wad', bvp)
reward = z3.BitVec('reward', bvp)
contract_balance = z3.Int('contract_balance') # z3.IntVal((10**18) * 4.48)
# Calculate balance of user after performing withdrawal
View E2Example.sol
pragma solidity ^0.8.9;
contract E2Example
{
event EncryptedResponse(bytes32 nonce, bytes data);
event DecryptedInput(uint256 a, uint256 b, uint256 c);
event PublicKey(bytes32 x);
@HarryR
HarryR / newrelic.php
Created July 25, 2012 16:13
NewRelic API for PHP
View newrelic.php
<?php
class NewRelic_Error extends Exception {}
function NewRelic_Date(DateTime $date) {
return $date->format('Y-m-d') . 'T' . $date->format('H:i:s') . 'Z';
}
function NewRelic_Metrics2Array(SimpleXMLElement $result) {
$return = array();
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
@HarryR
HarryR / MillerRabin.sol
Last active October 18, 2022 08:04
Miller Rabin probabilistic primality test for Solidity, and RSA-2048 modexp
View MillerRabin.sol
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
View KZG10.py
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: