Skip to content

Instantly share code, notes, and snippets.

View bitjson's full-sized avatar

Jason Dreyzehner bitjson

View GitHub Profile
@cpacia
cpacia / main.go
Created May 16, 2018 00:06
Bitcoin Cash tree signature
package main
import (
"fmt"
"github.com/btcsuite/btcd/btcec"
"encoding/hex"
"crypto/sha256"
"github.com/btcsuite/btcd/txscript"
"github.com/cpacia/bchutil"
"github.com/btcsuite/btcd/chaincfg"
@bellbind
bellbind / check-secp256k1.mjs
Last active March 28, 2020 18:43
[ECMAScript][BigInt] elliptic curve cryptography impl with ECMAScript BigInt proposal
// - required node.js >= 10.0.0
// $ npm i elliptic
// $ node --harmony-bigint --experimental-modules check-secp256k1.mjs
import crypto from "crypto";
import elliptic from "elliptic";
import {EC, ECC, secp256k1, a2bi, bi2a, randint} from "./ecc.mjs";
// With real standard curve: secp256k1
@gavinandresen
gavinandresen / UTXO_BitVector.md
Last active December 14, 2023 23:28
Storing the UTXO as a bit-vector

Half-baked thoughts exploring a different way of implementing a fully-validating BCH node.

The idea is to shift the storage of full transaction data to wallets, and explore how little data a fully validating node could store. This isn't a problem today (the UTXO set easily fits in the RAM of an inexpensive server-class machine), but might eventually be at very large transaction volumes.

Initial block download is a problem today (it is annoying to have to wait several hours or days to sync up a new node), and this scheme could make it orders of magnitude faster by shifting the time when full transaction data is broadcast from initial block download to new transaction announcement.

@gavinandresen
gavinandresen / UTXO_Cuckoo.md
Last active June 7, 2021 17:45
Using a cuckoo filter for fast 'unspent?' lookups

A "Cuckoo Filter" is a nifty data structure invented a few years ago; read the paper for details.

Like a Bloom filter, you insert items and then can later ask "does this item exist in the filter?" You'll get either a definite "no" or "yes, probably" with some false-positive error rate. Cuckoo filters have two advantages over Bloom filters:

  1. They are more space efficient at false positive rates less than about 0.03.
  2. You can delete items from them without affecting the false positive rate at all.

It seems to me that an in-memory cuckoo filter could work really well to keep track of Bitcoin's "unspent transaction output set" (UTXO set), to make transaction (or block) validation as fast as possible using minimal memory or disk.

Recall that Bitcoin transactions (other than coinbase transactions that create new coins) have inputs that refer to unspent outputs. An input refers to a previous output by giving the transaction id (a 32-byte hash) co

@maaku
maaku / .gitignore
Last active December 9, 2021 20:57
BIP specifying new tail-call optimized subscript execution rule
*~
@maaku
maaku / .gitignore
Last active December 20, 2021 04:10
BIP specifying a new script opcode for checking inclusion of an element in a Merkle tree
*~
@maaku
maaku / .gitignore
Last active November 17, 2020 21:53
BIP specifying fast merkle trees, as used in the Merkle branch verification opcodes
*~
@nacardin
nacardin / gist:c112dff46207f13c7a9554dd766f9eca
Created April 5, 2017 18:38
HackerRank > Algorithms > Implementation > Breaking the Records
use std::io::{self, Read};
fn line_to_vec<T: std::str::FromStr>(line: &str) -> Vec<T> {
line.split_whitespace().map(|x| x.parse::<T>().ok().expect("parse error")).collect::<Vec<T>>()
}
fn main() {
let mut buffer = String::new();
io::stdin().read_to_string(&mut buffer).unwrap();
@nathansgreen
nathansgreen / postgresql-debugger-install-macos
Last active January 18, 2023 04:04 — forked from jhngrant/postgresql-debugger-install-ubuntu
Installing the PL/pgSQL Debugger Extension (pldbgapi) for pgAdmin III on PostgreSQL 9.4 and MacOS
# First install database
brew install postgres
# Clone and build the PL/pgSQL server-side debugger
srcdir=/usr/local/src
[ -e "$scrdir" ] || \
sudo sh -c "mkdir $srcdir && chgrp admin $srcdir && chmod g+w $srcdir"
cd "$srcdir"