Skip to content

Instantly share code, notes, and snippets.

View RobinLinus's full-sized avatar

Robin Linus RobinLinus

View GitHub Profile
@RobinLinus
RobinLinus / is-fritzbox.js
Created December 1, 2019 21:31
Detect if the client's router is a FritzBox
function isFritzBox(){
return new Promise(resolve =>{
let img = document.createElement('img');
img.onload = _ => resolve(true);
img.onerror = _ => resolve(false);
img.src = 'http://fritz.box/favicon.ico';
});
}

Decaying MultiSig using nLockTime

A decaying MultiSig that requires no bitcoin script other than regular MultiSigs.

A 3-of-3 that decays into a 2-of-3 at block height x.

  1. Alice, Bob, and Carol create a 3-of-3 regular MultiSig output.

  2. Alice signs the output with nLocktime = x and SIGHASH_NONE.

  3. She sends this partially signed TX to Bob and Carol.

@RobinLinus
RobinLinus / peg.sol
Last active February 11, 2022 00:32
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.5.10;
import "https://github.com/summa-tx/bitcoin-spv/blob/master/solidity/contracts/ViewBTC.sol";
import "https://github.com/summa-tx/bitcoin-spv/blob/master/solidity/contracts/ViewSPV.sol";
contract Peg {
//
// Security Parameters

Weighted Threshold Points

For a threshold point over n points we can assign "weights" or "number of votes per key":

(T₁,w₁), (T₂,w₂), ...,(Tₙ,wₙ).

Instead of using each Tᵢ only once, we also use the keys Tᵢ+H(Tᵢ|1)G, Tᵢ+H(Tᵢ|2)G, ..., Tᵢ+H(Tᵢ|wᵢ)G during the creation of the threshold point. So, if Alice learns Tᵢ she learns the key for all of its votes.

Let's define the total number of votes as N = sum{wᵢ}. Now, we can choose any threshold t < N by enumerating all sums of subsets of size t. We can apply the OR operator to these sums to condense the threshold condition into a single point.

@RobinLinus
RobinLinus / dlc-order-relations.md
Last active March 14, 2022 23:47
Succinct order relations for DLCs

Order Relations for DLCs

We expect an oracle will publish some number 𝑁 by signing each of its n bits.

Given a constant c, we want to express the spending condition 𝑁 ≥ c in a single adaptor point.

The key idea is to construct an OR operator for adaptor points. This is possible with verifiable encryption. An OR operator allows to condense complex spending conditions into a single point. This prevents the combinatorical explosions that usually occure when using multi-oracles. An OR operator makes spending conditions easily composable. In theory, it even enables arbitrary computations.

Number Format

We define B₁ to Bₙ to represent the adaptor points for oracle signatures of those bits of 𝑁 that are equal to 1:

@RobinLinus
RobinLinus / enhancing-bitcoin-script.md
Last active April 22, 2022 19:30
Enhancing Bitcoin's scripting capabilities with client-side validation

Enhancing Bitcoin's scripting capabilities with client-side validation

TL;DR: We can enhance Bitcoin's scripting capabilities with client-side validation protocols. However, off-chain protocols like RGB or Taro do require some on-chain data.

Suppose we're given a client-side validation scheme for tokens on Bitcoin such as Omni, RGB, or Taro.

We want to express a simple spending condition that we cannot express in Bitcoin Script alone. For example, a hashed timelock contract that uses SHA3 instead of SHA2. So we want to express:

  • Alice can take the token if she reveals the SHA3 preimage of <hash> within a week.
  • Otherwise, after one week, Bob can take the token.

Bitcoin Cash is the real Bitcoin Cash

Charge Dollar bills with Bitcoins to create inflation-resitant cash. This idea originated in an old post on Bitcoin Talk. Here's a detailed writeup.

How to mint Bitcoin Cash?

  1. Take a 1 Dollar bill
  2. Burn 5000 sats and add that Dollar bill's serial number to your burn transaction.

Now the note is worth 1 USD + 5000 sats.

XOR Seed Splitting

A simple 2-of-3 seed splitting scheme for BIP39 seed phrases by Ruben Somsen.

Encrypt

  1. Split your 24 seed words into share_A and share_B of 12 words each.
  2. Pairwise XOR the words of the first share with the second share to derive the 12 words of share_C, the backup.
backup_1 = word_1 xor word_13
backup_2 = word_2 xor word_14
@RobinLinus
RobinLinus / simd.cairo
Last active November 17, 2022 23:59
Parallel processing in Cairo with single instruction, multiple data (SIMD) operations
//
// SIMD Operation for Bitwise Rotations of Seven UInt32 Values in Parallel
//
%builtins bitwise
from starkware.cairo.common.bitwise import BitwiseBuiltin
// How many bitwise steps do we want to rotate?
// 2**t expresses a rotation of t bits to the right.