LogoLogo
Threshold WebsitetBTC v2 DocsTACo Docs
  • What is the Threshold Network?
  • THRESHOLD DASHBOARD
    • tBTC Minting Walkthrough
  • Applications
    • tBTC Bitcoin Bridge
      • Fees
      • Wallet Generation
      • Wallet Signing
      • The Path to Permissionlessness
      • Sweeping
      • Coverage Pool
    • Threshold USD
      • Overview of thUSD
      • Borrowing
      • Stability Pool and Liquidations
      • Redemptions and thUSD Price Stability
      • Recovery Mode
      • Bootstrapping
        • Initial Protocol Loan
      • B. Protocol
      • thUSD on Build on Bitcoin (BOB)
        • Connecting to BOB Network
        • Bridging Collateral to BOB Network
        • Opening Collateral Vaults and Minting thUSD
  • Governance
    • Threshold DAO
      • 🗳️Governance Process
      • 🙋‍♀️Guilds
      • 💰Threshold Multisigs
      • Threshold DAO Rules
    • Vote Delegation
      • Liquid Token Delegation
  • Staking & Running a Node
    • tBTC v2 Node Setup
      • Operator Account
      • Application Authorization & Operator Registration
      • Network Configuration
      • Data Storage
      • Installation
        • Docker Installation
        • Binary Installation
      • Updating tBTC v2 Node
      • Advanced Options
        • Alternatives to Dashboard
        • Logging
        • Config File
        • CLI Options
        • Client Info
      • Frequently Asked Questions
      • Sepolia Testnet
        • Testnet tBTC v2 node Setup
    • tBTC Beta Stakers Program
  • App Development
    • DAO Contracts
      • DAO Contracts API
        • BaseTokenholderGovernor
        • Checkpoints
        • GovernorParameters
        • IApplication
        • ILegacyTokenStaking
        • IStaking
        • IVotesHistory
        • KeepStake
        • PercentUtils
        • ProxyAdminWithDeputy
        • SafeTUpgradeable
        • StakerGovernor
        • StakerGovernorVotes
        • T
        • TokenholderGovernor
        • TokenholderGovernorVotes
        • TokenStaking
        • VendingMachine
    • Random Beacon
      • Random Beacon API
        • AltBn128
        • BeaconAuthorization
        • BeaconDkg
        • BeaconDkgValidator
        • BeaconInactivity
        • BLS
        • BytesLib
        • Callback
        • Governable
        • Groups
        • IRandomBeacon
        • IRandomBeaconConsumer
        • ModUtils
        • RandomBeacon
        • RandomBeaconChaosnet
        • RandomBeaconGovernance
        • Reimbursable
        • ReimbursementPool
        • Relay
    • tBTC
      • tBTC SDK
        • Quickstart
        • Architecture
        • Guides
          • Initialize SDK
            • Ethereum and Bitcoin mainnet
            • Ethereum and Bitcoin testnet
            • Crosschain
            • Custom mode
          • Deposit and mint
          • Unmint and redeem
        • API Reference
      • tBTC Contracts API
        • Bridge API
          • Bank
          • BitcoinTx
          • Bridge
          • BridgeGovernance
          • BridgeGovernanceParameters
          • BridgeState
          • Deposit
          • DepositSweep
          • DonationVault
          • EcdsaLib
          • Fraud
          • GovernanceUtils
          • Heartbeat
          • IReceiveBalanceApproval
          • IRelay
          • IVault
          • L2TBTC
          • L2WormholeGateway
          • LightRelay
          • LightRelayMaintainerProxy
          • MaintainerProxy
          • MovingFunds
          • Redemption
          • TBTC
          • TBTCOptimisticMinting
          • TBTCVault
          • VendingMachine
          • VendingMachineV2
          • VendingMachineV3
          • WalletCoordinator
          • Wallets
        • ECDSA API
          • EcdsaAuthorization
          • EcdsaDkg
          • EcdsaDkgValidator
          • EcdsaInactivity
          • IWalletOwner
          • IWalletRegistry
          • WalletRegistry
          • WalletRegistryGovernance
          • Wallets
  • Resources
    • T Token
    • Contract Addresses
      • Mainnet
        • Threshold DAO
        • tBTC
        • thUSD
        • Legacy
      • Görli Testnet
      • Sepolia Testnet
    • tBTC Pools
    • Upgrade NU & KEEP to T
    • Contribution
    • Security
    • Brand Assets
    • Links
Powered by GitBook
On this page
  • Heartbeat
  • isValidHeartbeatMessage

Was this helpful?

Export as PDF
  1. App Development
  2. tBTC
  3. tBTC Contracts API
  4. Bridge API

Heartbeat

Heartbeat

The library establishes expected format for heartbeat messages signed by wallet ECDSA signing group. Heartbeat messages are constructed in such a way that they can not be used as a Bitcoin transaction preimages.

The smallest Bitcoin non-coinbase transaction is a one spending an OP_TRUE anyonecanspend output and creating 1 OP_TRUE anyonecanspend output. Such a transaction has 61 bytes (see BitcoinTx documentation): 4 bytes for version 1 byte for tx_in_count 36 bytes for tx_in.previous_output 1 byte for tx_in.script_bytes (value: 0) 0 bytes for tx_in.signature_script 4 bytes for tx_in.sequence 1 byte for tx_out_count 8 bytes for tx_out.value 1 byte for tx_out.pk_script_bytes 1 byte for tx_out.pk_script 4 bytes for lock_time

The smallest Bitcoin coinbase transaction is a one creating 1 OP_TRUE anyonecanspend output and having an empty coinbase script. Such a transaction has 65 bytes: 4 bytes for version 1 byte for tx_in_count 32 bytes for tx_in.hash (all 0x00) 4 bytes for tx_in.index (all 0xff) 1 byte for tx_in.script_bytes (value: 0) 4 bytes for tx_in.height 0 byte for tx_in.coinbase_script 4 bytes for tx_in.sequence 1 byte for tx_out_count 8 bytes for tx_out.value 1 byte for tx_out.pk_script_bytes 1 byte for tx_out.pk_script 4 bytes for lock_time

A SIGHASH flag is used to indicate which part of the transaction is signed by the ECDSA signature. There are currently 3 flags: SIGHASH_ALL, SIGHASH_NONE, SIGHASH_SINGLE, and different combinations of these flags.

No matter the SIGHASH flag and no matter the combination, the following fields from the transaction are always included in the constructed preimage: 4 bytes for version 36 bytes for tx_in.previous_output (or tx_in.hash + tx_in.index for coinbase) 4 bytes for lock_time

Additionally, the last 4 bytes of the preimage determines the SIGHASH flag.

This is enough to say there is no way the preimage could be shorter than 4 + 36 + 4 + 4 = 48 bytes.

For this reason, we construct the heartbeat message, as a 16-byte message. The first 8 bytes are 0xffffffffffffffff. The last 8 bytes are for an arbitrary uint64, being a signed heartbeat nonce (for example, the last Ethereum block hash).

The message being signed by the wallet when executing the heartbeat protocol should be Bitcoin's hash256 (double SHA-256) of the heartbeat message: heartbeat_sighash = hash256(heartbeat_message)

isValidHeartbeatMessage

function isValidHeartbeatMessage(bytes message) internal pure returns (bool)

Determines if the signed byte array is a valid, non-fraudulent heartbeat message.

Wallet heartbeat message must be exactly 16 bytes long with the first 8 bytes set to 0xffffffffffffffff.

Parameters

Name
Type
Description

message

bytes

Message signed by the wallet. It is a potential heartbeat message, Bitcoin transaction preimage, or an arbitrary signed bytes.

Return Values

Name
Type
Description

[0]

bool

True if valid heartbeat message, false otherwise.

PreviousGovernanceUtilsNextIReceiveBalanceApproval

Last updated 1 year ago

Was this helpful?