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) $ 93,628.09 3.12%
ethereum
Ethereum (ETH) $ 1,792.68 5.80%
tether
Tether (USDT) $ 1.00 0.05%
xrp
XRP (XRP) $ 2.23 3.82%
bnb
BNB (BNB) $ 605.87 0.55%
solana
Solana (SOL) $ 151.79 4.91%
usd-coin
USDC (USDC) $ 1.00 0.00%
dogecoin
Dogecoin (DOGE) $ 0.178627 4.37%
cardano
Cardano (ADA) $ 0.705638 7.73%
tron
TRON (TRX) $ 0.245554 0.49%
staked-ether
Lido Staked Ether (STETH) $ 1,791.26 5.71%
wrapped-bitcoin
Wrapped Bitcoin (WBTC) $ 93,424.03 3.11%
sui
Sui (SUI) $ 2.94 22.48%
chainlink
Chainlink (LINK) $ 14.83 7.22%
avalanche-2
Avalanche (AVAX) $ 22.27 3.12%
leo-token
LEO Token (LEO) $ 9.08 1.27%
stellar
Stellar (XLM) $ 0.26775 4.02%
shiba-inu
Shiba Inu (SHIB) $ 0.000013 3.29%
the-open-network
Toncoin (TON) $ 3.12 4.74%
hedera-hashgraph
Hedera (HBAR) $ 0.181277 2.88%
wrapped-steth
Wrapped stETH (WSTETH) $ 2,148.55 5.39%
usds
USDS (USDS) $ 1.00 0.00%
bitcoin-cash
Bitcoin Cash (BCH) $ 359.88 0.34%
litecoin
Litecoin (LTC) $ 83.66 1.44%
polkadot
Polkadot (DOT) $ 4.09 5.54%
hyperliquid
Hyperliquid (HYPE) $ 18.47 0.20%
bitget-token
Bitget Token (BGB) $ 4.50 0.05%
binance-bridged-usdt-bnb-smart-chain
Binance Bridged USDT (BNB Smart Chain) (BSC-USD) $ 0.996189 0.55%
weth
WETH (WETH) $ 1,790.27 5.32%
ethena-usde
Ethena USDe (USDE) $ 0.999623 0.03%
pi-network
Pi Network (PI) $ 0.654423 2.60%
monero
Monero (XMR) $ 228.09 3.40%
whitebit
WhiteBIT Coin (WBT) $ 28.68 0.64%
wrapped-eeth
Wrapped eETH (WEETH) $ 1,908.14 5.42%
coinbase-wrapped-btc
Coinbase Wrapped BTC (CBBTC) $ 93,633.09 3.28%
pepe
Pepe (PEPE) $ 0.000009 5.06%
uniswap
Uniswap (UNI) $ 6.00 7.29%
aptos
Aptos (APT) $ 5.32 4.53%
dai
Dai (DAI) $ 0.999845 0.05%
okb
OKB (OKB) $ 52.12 0.90%
near
NEAR Protocol (NEAR) $ 2.48 8.60%
ondo-finance
Ondo (ONDO) $ 0.925644 4.04%
gatechain-token
Gate (GT) $ 23.56 0.09%
bittensor
Bittensor (TAO) $ 333.28 3.20%
official-trump
Official Trump (TRUMP) $ 14.15 59.24%
internet-computer
Internet Computer (ICP) $ 5.10 5.67%
tokenize-xchange
Tokenize Xchange (TKX) $ 32.56 0.79%
ethereum-classic
Ethereum Classic (ETC) $ 16.76 3.31%
aave
Aave (AAVE) $ 166.02 9.35%
susds
sUSDS (SUSDS) $ 1.05 0.12%
blackrock-usd-institutional-digital-liquidity-fund
BlackRock USD Institutional Digital Liquidity Fund (BUIDL) $ 1.00 0.00%
crypto-com-chain
Cronos (CRO) $ 0.089704 0.11%
kaspa
Kaspa (KAS) $ 0.094794 3.70%
mantle
Mantle (MNT) $ 0.703867 2.51%
render-token
Render (RENDER) $ 4.57 2.30%
vechain
VeChain (VET) $ 0.025957 5.89%
ethena-staked-usde
Ethena Staked USDe (SUSDE) $ 1.17 0.08%
polygon-ecosystem-token
POL (ex-MATIC) (POL) $ 0.224928 4.23%
cosmos
Cosmos Hub (ATOM) $ 4.35 2.97%
ethena
Ethena (ENA) $ 0.346732 12.22%
lombard-staked-btc
Lombard Staked BTC (LBTC) $ 92,951.90 2.98%
algorand
Algorand (ALGO) $ 0.216173 7.01%
fasttoken
Fasttoken (FTN) $ 4.23 0.06%
filecoin
Filecoin (FIL) $ 2.75 5.62%
celestia
Celestia (TIA) $ 2.80 5.71%
sonic-3
Sonic (prev. FTM) (S) $ 0.51589 6.72%
fetch-ai
Artificial Superintelligence Alliance (FET) $ 0.620091 2.00%
arbitrum
Arbitrum (ARB) $ 0.329839 6.57%
first-digital-usd
First Digital USD (FDUSD) $ 0.998219 0.05%
jupiter-perpetuals-liquidity-provider-token
Jupiter Perpetuals Liquidity Provider Token (JLP) $ 4.13 3.02%
solv-btc
Solv Protocol SolvBTC (SOLVBTC) $ 93,300.00 3.07%
kucoin-shares
KuCoin (KCS) $ 10.34 2.95%
jupiter-exchange-solana
Jupiter (JUP) $ 0.454629 6.95%
optimism
Optimism (OP) $ 0.76172 6.93%
binance-staked-sol
Binance Staked SOL (BNSOL) $ 158.31 4.41%
maker
Maker (MKR) $ 1,476.08 4.02%
xdce-crowd-sale
XDC Network (XDC) $ 0.076489 4.09%
bonk
Bonk (BONK) $ 0.000015 9.01%
blockstack
Stacks (STX) $ 0.772102 0.26%
fartcoin
Fartcoin (FARTCOIN) $ 1.16 9.75%
worldcoin-wld
Worldcoin (WLD) $ 0.860152 8.43%
immutable-x
Immutable (IMX) $ 0.60373 10.47%
binance-peg-weth
Binance-Peg WETH (WETH) $ 1,785.15 5.16%
flare-networks
Flare (FLR) $ 0.016907 3.29%
nexo
NEXO (NEXO) $ 1.06 2.12%
kelp-dao-restaked-eth
Kelp DAO Restaked ETH (RSETH) $ 1,864.76 5.45%
quant-network
Quant (QNT) $ 70.52 6.39%
eos
EOS (EOS) $ 0.667581 1.58%
story-2
Story (IP) $ 3.72 5.11%
sei-network
Sei (SEI) $ 0.194113 6.31%
usdt0
USDT0 (USDT0) $ 1.00 0.01%
injective-protocol
Injective (INJ) $ 9.46 6.08%
dexe
DeXe (DEXE) $ 15.60 2.71%
curve-dao-token
Curve DAO (CRV) $ 0.660448 2.87%
paypal-usd
PayPal USD (PYUSD) $ 1.00 0.04%
the-graph
The Graph (GRT) $ 0.090866 4.03%
rocket-pool-eth
Rocket Pool ETH (RETH) $ 2,018.09 5.52%
binance-bridged-usdc-bnb-smart-chain
Binance Bridged USDC (BNB Smart Chain) (USDC) $ 0.997299 0.43%
polygon-bridged-usdt-polygon
Polygon Bridged USDT (Polygon) (USDT) $ 1.00 0.04%
tether-gold
Tether Gold (XAUT) $ 3,311.05 2.64%
Scroll to Top