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
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 / download-solc.sh
Created November 23, 2020 17:56
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 December 9, 2019 17:16
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 November 8, 2019 14:58
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 October 23, 2019 13:03
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])