Bitcoin Covenants: CHECKSIGFROMSTACK (BIP 348)

Bitcoin Covenants: CHECKSIGFROMSTACK (BIP 348)

That is the second article in a collection deep diving into particular person covenant proposals which have reached some extent of maturity meriting an in-depth breakdown. 

CHECKSIGFROMSTACK (CSFS), put ahead by Brandon Black and Jeremy Rubin with BIP 348, just isn’t a covenant. As I mentioned within the introductory article to this collection, a number of the proposals I’d be overlaying are usually not covenants, however synergize or interrelate with them not directly. CSFS is the primary instance of that. 

CSFS is a quite simple opcode, however earlier than we undergo the way it works let’s have a look at the fundamentals of how a Bitcoin script really works. 

Script is a stack primarily based language. That signifies that knowledge is “stacked” collectively on prime of one another on the stack, and operated on by eradicating an merchandise from the highest of the stack to function on primarily based on what an opcode does, both returning the information or a consequence from it to the highest of the stack. 

There are two elements of a script when it’s finally executed and verified, the “witness” offered to unlock the script, and the script included within the output being spent. The witness/unlocking script is “added” to the left aspect of the locking script, after which every factor is added to (or operates on) the stack one after the other left to proper. Have a look at this instance (the “|” marks the boundary between the witness and script):

1 2 | OP_ADD 3 OP_EQUAL

This instance script provides the worth “1” to the stack, then the worth “2” on prime of that. OP_ADD takes the highest two parts of the stack and provides them collectively, placing the consequence again on to the stack (so now all that’s on the stack is “3”). One other “3” is then added to the stack. The final merchandise, OP_EQUAL, takes the highest two gadgets of the stack and returns a “1” to the stack (1 and 0 can symbolize True or False in addition to numbers).

A script should finish with the final merchandise on the highest of the stack being True, in any other case the script (and transaction executing it) fails and is taken into account consensus invalid. 

This can be a primary instance of a pay-to-pubkey-hash (P2PKH) script, i.e. the legacy addresses that begin with a “1”:

| DUP HASH160 EQUALVERIFY CHECKSIG

First the signature and the general public key are added to the stack. Then DUP is known as, which takes the highest stack merchandise and duplicates it, returning it to the highest of the stack. HASH160 takes the highest stack merchandise (the general public key duplicate), hashes it, then returns it to the highest of the stack. The general public key hash from the script is placed on prime of the stack. EQUALVERIFY capabilities the identical as EQUAL, it grabs the 2 prime stack gadgets and returns a 1 or 0 primarily based on the end result. The one distinction is EQUALVERIFY additionally runs VERIFY after EQUAL, which fails the transaction if the highest stack merchandise just isn’t 1, and likewise removes the highest stack merchandise. Lastly CHECKSIG is run, which grabs the highest two stack gadgets assuming them to be a signature and a pubkey, and verifies the signature implicitly in opposition to the hash of the transaction being verified. Whether it is legitimate it places a 1 on prime of the stack. 

How CSFS Works

CHECKSIG is among the most used opcodes in Bitcoin. Each transaction, with nearly no exceptions, makes use of this opcode in some unspecified time in the future in considered one of its scripts. Signature verification is a foundational part of the Bitcoin protocol. The issue is, there may be nearly no flexibility when it comes to what message you might be checking the signature in opposition to. CHECKSIG will solely confirm a signature in opposition to the transaction being verified. There may be some flexibility, i.e. you possibly can determine with some extent of freedom what elements of the transaction the signature applies to, however that’s it. 

CSFS goals to vary this by permitting a signature to be verified in opposition to any arbitrary message that’s pushed immediately onto the stack, as an alternative of being restricted to the verification of signatures in opposition to the transaction itself. The opcode follows a really primary operational construction:

| CSFS

The signature and message are dropped on prime of the stack, then the general public key on prime of them, and eventually CSFS grabs the highest three gadgets from the stack assuming them to be the general public key, message, and signature from prime to backside, verifying the signature in opposition to the message. If the signature is legitimate, a 1 is positioned on the stack. 

That’s it. A easy variant of CHECKSIG that lets customers specify arbitrary messages as an alternative of simply the spending transaction. 

What Is CSFS Helpful For

So what precisely is that this good for? What’s using checking a signature in opposition to an arbitrary message on the stack as an alternative of in opposition to the spending transaction? 

Firstly, together with CTV it could actually present a performance equal to one thing that Lightning builders have wished because the very starting, floating signatures that may connect to completely different transactions. This was initially proposed as a brand new sighash flag for signatures (the sector that dictates what elements of a transaction a signature applies to). This was wanted as a result of a transaction signature covers the transaction ID of the transaction that created the output being spent. This implies a signature is barely legitimate for a transaction spending that precise output. 

This can be a desired conduct for Lightning as a result of it could enable us to put off channel penalties. Each previous Lightning state wants a penalty key and transaction as a way to make sure that your channel counterparty by no means makes use of any of them to attempt to declare funds they don’t personal. If they struggle you possibly can declare all their cash. A superior performance could be one thing that means that you can merely “attach” the present state transaction to any earlier one to cease the theft try by distributing funds accurately versus confiscating them. 

This may be achieved with a primary script that takes a CTV hash and a signature over it that’s checked utilizing CSFS. This is able to enable any transaction hash signed by that CSFS key to spend any output that’s created with this script. 

One other helpful characteristic is delegation of management of a UTXO. The identical means that any CTV hash signed by a CSFS key can validly spend a UTXO with a script designed for that, different variables might be handed into the script to be checked in opposition to, equivalent to a brand new public key. A script may very well be constructed that enables a CSFS key to log off on any public key, which then may very well be validated utilizing CSFS and used for a standard CHECKSIG validation. This is able to mean you can delegate the flexibility to spend a UTXO to anybody else with out having to maneuver it on-chain. 

Lastly, together with CAT, CSFS can be utilized to compose far more advanced introspection performance. As we are going to see later within the collection although, CSFS just isn’t really required to emulate any of this extra superior conduct, as CAT alone is in a position to take action. 

Closing Ideas

CSFS is a really primary opcode that along with providing easy helpful performance in its personal proper composes very properly with even the most straightforward covenant opcodes to create very helpful performance. Whereas the instance above concerning floating signatures particularly references the Lightning Community, floating signatures are a usually helpful primitive which can be relevant to any protocol constructed on Bitcoin making use of pre-signed transactions. 

Along with floating signatures, script delegation is a really helpful primitive that generalizes far past delegating management over a UTXO to a brand new public key. The identical primary skill to “sideload” variables after the actual fact right into a script validation circulate can apply to something, not simply public keys. Timelock values, hashlock preimages, and so forth. Any script that hardcodes a variable to confirm in opposition to can now have these values dynamically added after the actual fact. 

On prime of that, CSFS is a really mature proposal. It has an implementation that has been dwell on the Liquid Community and Components (the codebase Liquid makes use of) since 2016. As well as Bitcoin Money has had a model of it since 2018. 

CSFS is a really mature proposal that goes again conceptually nearly so long as I’ve been on this house, with a number of mature implementations, and really clear use instances it may be utilized to. 

Supply hyperlink

bitcoin
Bitcoin (BTC) $ 102,740.53 3.08%
ethereum
Ethereum (ETH) $ 2,356.03 21.48%
tether
Tether (USDT) $ 1.00 0.02%
xrp
XRP (XRP) $ 2.36 6.68%
bnb
BNB (BNB) $ 632.40 2.57%
solana
Solana (SOL) $ 166.09 8.75%
usd-coin
USDC (USDC) $ 1.00 0.00%
dogecoin
Dogecoin (DOGE) $ 0.203676 11.38%
cardano
Cardano (ADA) $ 0.782317 9.26%
tron
TRON (TRX) $ 0.259282 3.30%
staked-ether
Lido Staked Ether (STETH) $ 2,348.33 21.41%
wrapped-bitcoin
Wrapped Bitcoin (WBTC) $ 102,556.48 3.01%
sui
Sui (SUI) $ 3.93 6.26%
chainlink
Chainlink (LINK) $ 16.14 9.30%
wrapped-steth
Wrapped stETH (WSTETH) $ 2,840.88 22.18%
avalanche-2
Avalanche (AVAX) $ 23.05 9.57%
stellar
Stellar (XLM) $ 0.29819 9.22%
shiba-inu
Shiba Inu (SHIB) $ 0.000015 10.73%
hedera-hashgraph
Hedera (HBAR) $ 0.199842 7.27%
bitcoin-cash
Bitcoin Cash (BCH) $ 419.87 0.98%
hyperliquid
Hyperliquid (HYPE) $ 24.76 13.93%
the-open-network
Toncoin (TON) $ 3.26 4.40%
leo-token
LEO Token (LEO) $ 8.75 0.58%
usds
USDS (USDS) $ 1.00 0.01%
litecoin
Litecoin (LTC) $ 98.16 6.38%
polkadot
Polkadot (DOT) $ 4.61 8.40%
weth
WETH (WETH) $ 2,350.11 21.25%
wrapped-eeth
Wrapped eETH (WEETH) $ 2,507.29 21.31%
monero
Monero (XMR) $ 302.28 3.60%
pepe
Pepe (PEPE) $ 0.000013 41.63%
bitget-token
Bitget Token (BGB) $ 4.53 4.84%
pi-network
Pi Network (PI) $ 0.72995 17.01%
binance-bridged-usdt-bnb-smart-chain
Binance Bridged USDT (BNB Smart Chain) (BSC-USD) $ 0.999654 0.05%
coinbase-wrapped-btc
Coinbase Wrapped BTC (CBBTC) $ 102,719.52 3.13%
ethena-usde
Ethena USDe (USDE) $ 0.999379 0.15%
whitebit
WhiteBIT Coin (WBT) $ 30.18 4.28%
uniswap
Uniswap (UNI) $ 6.38 22.63%
bittensor
Bittensor (TAO) $ 433.85 7.62%
aptos
Aptos (APT) $ 5.65 11.18%
near
NEAR Protocol (NEAR) $ 2.88 17.50%
dai
Dai (DAI) $ 1.00 0.02%
okb
OKB (OKB) $ 54.23 4.42%
ondo-finance
Ondo (ONDO) $ 1.01 9.33%
aave
Aave (AAVE) $ 211.32 12.59%
susds
sUSDS (SUSDS) $ 1.05 0.00%
ethereum-classic
Ethereum Classic (ETC) $ 19.08 10.27%
blackrock-usd-institutional-digital-liquidity-fund
BlackRock USD Institutional Digital Liquidity Fund (BUIDL) $ 1.00 0.00%
crypto-com-chain
Cronos (CRO) $ 0.099713 4.65%
internet-computer
Internet Computer (ICP) $ 5.28 9.23%
official-trump
Official Trump (TRUMP) $ 13.79 13.19%
kaspa
Kaspa (KAS) $ 0.103361 7.72%
gatechain-token
Gate (GT) $ 21.85 1.36%
tokenize-xchange
Tokenize Xchange (TKX) $ 32.77 9.87%
mantle
Mantle (MNT) $ 0.767425 4.86%
render-token
Render (RENDER) $ 4.88 7.57%
vechain
VeChain (VET) $ 0.029341 10.74%
polygon-ecosystem-token
POL (ex-MATIC) (POL) $ 0.254202 10.57%
fetch-ai
Artificial Superintelligence Alliance (FET) $ 0.851361 16.43%
ethena
Ethena (ENA) $ 0.367199 22.24%
cosmos
Cosmos Hub (ATOM) $ 4.79 10.45%
usd1-wlfi
USD1 (USD1) $ 1.00 0.05%
lombard-staked-btc
Lombard Staked BTC (LBTC) $ 102,433.44 3.07%
ethena-staked-usde
Ethena Staked USDe (SUSDE) $ 1.17 0.16%
algorand
Algorand (ALGO) $ 0.231505 9.25%
filecoin
Filecoin (FIL) $ 2.99 8.54%
sonic-3
Sonic (prev. FTM) (S) $ 0.589476 9.03%
fasttoken
Fasttoken (FTN) $ 4.35 0.15%
celestia
Celestia (TIA) $ 2.83 4.42%
arbitrum
Arbitrum (ARB) $ 0.373088 12.58%
jupiter-perpetuals-liquidity-provider-token
Jupiter Perpetuals Liquidity Provider Token (JLP) $ 4.45 5.61%
bonk
Bonk (BONK) $ 0.000021 11.49%
worldcoin-wld
Worldcoin (WLD) $ 1.12 12.59%
first-digital-usd
First Digital USD (FDUSD) $ 0.996391 0.22%
blockstack
Stacks (STX) $ 0.964062 4.35%
jupiter-exchange-solana
Jupiter (JUP) $ 0.504527 12.28%
maker
Maker (MKR) $ 1,760.44 9.69%
binance-peg-weth
Binance-Peg WETH (WETH) $ 2,355.51 21.57%
kucoin-shares
KuCoin (KCS) $ 11.12 2.07%
quant-network
Quant (QNT) $ 95.44 2.73%
kelp-dao-restaked-eth
Kelp DAO Restaked ETH (RSETH) $ 2,492.08 23.45%
binance-staked-sol
Binance Staked SOL (BNSOL) $ 173.92 8.33%
virtual-protocol
Virtuals Protocol (VIRTUAL) $ 2.03 24.37%
flare-networks
Flare (FLR) $ 0.020016 2.59%
eos
EOS (EOS) $ 0.8542 1.50%
fartcoin
Fartcoin (FARTCOIN) $ 1.28 17.22%
nexo
NEXO (NEXO) $ 1.26 0.95%
story-2
Story (IP) $ 4.62 14.57%
optimism
Optimism (OP) $ 0.726241 15.82%
sei-network
Sei (SEI) $ 0.233627 11.24%
xdce-crowd-sale
XDC Network (XDC) $ 0.075601 1.21%
immutable-x
Immutable (IMX) $ 0.642869 7.85%
solv-btc
Solv Protocol BTC (SOLVBTC) $ 102,603.49 3.28%
injective-protocol
Injective (INJ) $ 11.67 13.28%
rocket-pool-eth
Rocket Pool ETH (RETH) $ 2,665.85 21.44%
usdt0
USDT0 (USDT0) $ 0.997486 0.27%
ubtc
uBTC (UBTC) $ 205,452.05 110.69%
curve-dao-token
Curve DAO (CRV) $ 0.777826 6.93%
the-graph
The Graph (GRT) $ 0.105739 8.59%
pudgy-penguins
Pudgy Penguins (PENGU) $ 0.01507 6.14%
floki
FLOKI (FLOKI) $ 0.000098 17.73%
Scroll to Top