Skip to content

Instantly share code, notes, and snippets.

View kcalvinalvin's full-sized avatar

Calvin Kim kcalvinalvin

View GitHub Profile
@kcalvinalvin
kcalvinalvin / tip-bridge-coverage.md
Last active November 30, 2026 12:04
Tip bridge coverage on mainnet

Tip bridge coverage on mainnet

Nov 30, 2026 · @Calvin Kim

Why tip bridges?

Utreexo compact state nodes (CSNs) only store the accumulator roots, so they rely on bridge nodes to provide inclusion proofs for incoming transactions and blocks. Running a full bridge requires storing the entire utreexo forest on disk and building it from genesis. You can construct the bridge state at the tip much faster than processing every deletion along the way by doing an add-only pass (using the node's current UTXO set to tell which historical outputs were spent, you just add an empty hash for deleted leaves and still end up with the correct forest state). However, even that shortcut requires replaying every block from genesis, which takes time and prevents an already-synced full node from quickly enabling bridge support.

A tip bridge skips genesis sync by starting from a recent block's utreexo roots and leaf count instead of the full forest. From that height onward, it stays in sync using incoming block proofs to proc

@kcalvinalvin
kcalvinalvin / utreexo-validation-v0.4.1.md
Created May 19, 2025 05:13
Verifying a block as an utreexo compact state node for v0.4.1

Verifying a bitcoin block as an utreexo compact state node

A utreexo compact state node doesn't have all the data required for verifying a bitcoin block just with the block. It also requires a utreexo proof.

The method described here is only valid for utreexod v0.4.1. The next version will have a different P2P messaging flow.

For v0.4.1, to get the necessary utreexo data, one must ask for a MSG_UTREEXO_BLOCK when constructing the getdata. Since we also want segwit blocks as well, we use the

@kcalvinalvin
kcalvinalvin / utreexo-algorithms.md
Last active November 6, 2026 11:34
Utreexo algorithms

Add

Utreexo accumulator is a collection of proper merkle trees. All the merkle trees have 2 children or none.

Below is an example of adding 7 leaves to the tree. You can run the code I used to generate this at https://go.dev/play/p/um5263SDk59

This is an accumulator with 1 leaf. It has 1 root, which is also a leaf.

@kcalvinalvin
kcalvinalvin / sanity_test.go
Created August 29, 2022 06:41
Test function to verify that the code is incorrect
package patriciaaccumulator
import (
"encoding/hex"
"fmt"
"os"
"path/filepath"
"testing"
)
@kcalvinalvin
kcalvinalvin / reproduce-results.patch
Last active August 29, 2022 06:32
Patch to reproduce the results of the blog
diff --git a/bridgenode/genproofs.go b/bridgenode/genproofs.go
index 36f1117..cca31b8 100644
--- a/bridgenode/genproofs.go
+++ b/bridgenode/genproofs.go
@@ -110,6 +110,7 @@ func BuildProofs(
logrus.SetOutput(logfile)
logrus.SetLevel(logrus.InfoLevel)
for ; height != knownTipHeight && !stop; height++ {
+ fmt.Println("on block", height)