Skip to content

Instantly share code, notes, and snippets.

@ralexstokes
ralexstokes / gist:37f6c3779038705c7795962fd0147c1d
Created March 31, 2019 03:26
change-sequence-of-epoch-processing.patch
From c47d7ce48eaadf0faf45ec53fc0e8adf0017db7b Mon Sep 17 00:00:00 2001
From: Alex Stokes <[email protected]>
Date: Wed, 20 Mar 2019 16:50:03 -0700
Subject: [PATCH] Reorder the per-epoch transition to occur at the start of the
state transition
---
.../beacon/state_machines/forks/serenity/state_transitions.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
@ralexstokes
ralexstokes / async.py
Created June 20, 2019 18:31
basic python async
import asyncio
async def count(delay):
# this will block everything :(
# time.sleep(2)
# will explode the other stuff
# raise Exception("hi")
@ralexstokes
ralexstokes / basic_trio.py
Created June 20, 2019 18:33
basic trio example
import trio
async def child1(nursery):
print("from 1")
# will cancel the nursery
# raise Exception("there")
await trio.sleep(1)
@ralexstokes
ralexstokes / asyncio_echo.py
Created June 20, 2019 18:34
asyncio echo server
import random
import asyncio
import colored
host = "127.0.0.1"
port = 8080
import colored
import random
import trio
host = "127.0.0.1"
port = 8080
def _mk_msg(_id):
return f"query from {_id}"
@ralexstokes
ralexstokes / sketch.clj
Last active March 11, 2020 21:52
Sketch of Clojure-like smart contract language
(require
[types]
[precompiles]
[registry]
[tools])
(defcontract BLSSignatureVerifier
(defn ^:public verify [message public-key signature)
(let [message-on-curve (precompiles/hash-to-curve message)]
(=
import itertools
import time
import requests
LH_URL = "http://<host-elided>/consensus/global_votes"
MEDALLA_GENESIS_TIME = 1596546008
def _current_epoch():
t = int(time.time())
return (t - MEDALLA_GENESIS_TIME) // 12 // 32
@ralexstokes
ralexstokes / validator-lifecycle.py
Last active April 29, 2021 15:58
validator-lifecycle
from graphviz import Digraph
font_name = "helvetica"
node_settings = {"fontname": font_name}
edge_settings = {"fontname": font_name}
title = "Validator lifecycle on the beacon chain (phase 0 spec)\n\n"
dot = Digraph(
title,
node_attr=node_settings,
@ralexstokes
ralexstokes / cargo.toml
Created May 14, 2021 20:16
work around lighthouse cargo patches @ commit 3a24ca5f14c6e6d6612fd43eca82aa0c1e6aba16
[patch]
[patch.crates-io]
tree_hash = { git = "https://github.com/sigp/lighthouse", branch = "stable" }
tree_hash_derive = { git = "https://github.com/sigp/lighthouse", branch = "stable" }
eth2_ssz = { git = "https://github.com/sigp/lighthouse", branch = "stable" }
eth2_ssz_derive = { git = "https://github.com/sigp/lighthouse", branch = "stable" }
eth2_ssz_types = { git = "https://github.com/sigp/lighthouse", branch = "stable" }
eth2_hashing = { git = "https://github.com/sigp/lighthouse", branch = "stable" }
@ralexstokes
ralexstokes / validate_bls_12_381_primitive_root.py
Created December 1, 2021 17:21
Compute the smallest primitive root of unity of BLS-12-381
# Python3 program to find primitive root
# of a given number n
from math import sqrt
from gmpy2 import is_prime
import primefac
# Function to find smallest primitive
# root of n
def findPrimitive(n):