Introduction
We express our gratitude to the Sundial team for the collaborative engagement that enabled the execution of this dApp Security Assessment.
Sundial Protocol is building Bitcoin-native yield infrastructure, enabling users to lock BTC into time-based escrow contracts and earn yield through a decentralized staking mechanism. The protocol leverages Bitcoin Script primitives (CLTV, CSV) to create trustless timelock and escrow outputs, allowing for non-custodial yield distribution without requiring wrapped tokens or cross-chain bridges.
Document | |
|---|---|
| Name | dApp Code Review and Security Analysis Report for Sundial |
| Audited By | Adedolapo Olayinka-Adeyemi |
| Approved By | Ece Orsel |
| Website | sundialprotocol.com |
| Changelog | 30/01/2025 - Preliminary Report |
| Platform | Bitcoin |
| Language | Typescript |
| Tags | White-box |
| Methodology | https://docs.hacken.io/methodologies/dapp-audit-methodology→ |
Document
- Name
- dApp Code Review and Security Analysis Report for Sundial
- Audited By
- Adedolapo Olayinka-Adeyemi
- Approved By
- Ece Orsel
- Website
- sundialprotocol.com
- Changelog
- 30/01/2025 - Preliminary Report
- Platform
- Bitcoin
- Language
- Typescript
- Tags
- White-box
Review Scope | |
|---|---|
| Repository | https://github.com/sundial-protocol/btc-locker→ |
| Commit | dd1332516d9721b67fefdc219048527de066cbdc |
Review Scope
- Commit
- dd1332516d9721b67fefdc219048527de066cbdc
Audit Summary
The system users should acknowledge all the risks summed up in the risks section of the report
{FindingsVulnSeverityStatusTable}
Documentation quality
Comprehensive top-level
README.mdwith protocol overview, installation instructions, and usage examplesDetailed
CLI.mddocumenting all command-line operations with flags and examples
Code quality
Strong TypeScript usage with strict typings, dedicated
types.ts, and interface definitions for all transaction parametersClean modular architecture with single-responsibility separation (
locker/scripts/,locker/transactions/,utils/)
System Overview
The BTC Locker core library lives in its own top-level /packages/core folder and is responsible for Bitcoin script generation, PSBT construction, transaction signing, and on-chain interaction with Bitcoin APIs. Inside there is:
A README.md and supporting documentation that explain overall setup, usage patterns, and integration guidance for the Sundial staking workflow.
src/ with several subdirectories and standalone modules:
locker/— the primary module containing Bitcoin locking primitives:core.tswhich provides theBTCLockerCorebase class handling ECC initialization, transaction signing, and PSBT finalization logic.index.tsexposing the unifiedBTCLockerfacade class that combines key generation, script management, and transaction building into a single interface.keypair.tsfor Bitcoin key pair generation (random and from existing private keys) using the secp256k1 curve.script-manager.tsandtransaction-manager.tsas thin facades delegating to specialized builders.scripts/subdirectory containing:timelock.tsfor absolute (CLTV) and relative (CSV) timelock script creation.escrow.tsfor dual-path escrow scripts with before/after deadline spending conditions.
transactions/subdirectory containing:deposit/withdeposit.ts,deposit-with-script.ts, andcalculate.tsfor Dawn Protocol staking transactions that split funds between escrow and timelock outputs.withdraw.tsfor combining escrow and timelock inputs into a single withdrawal transaction.claim.tsfor spending from escrow scripts using either the before-deadline or after-deadline path.distribute.tsfor yield distribution transactions back to timelock addresses.generic.tsproviding low-level spending and funding transaction primitives.
utils/— shared utility modules:scripts.tswith helpers for script validation, address generation, script parsing, and locktime extraction.keys.tsfor public/private key validation and ECPair creation.fees.tsencapsulating fee estimation logic with priority levels (HIGH/MEDIUM/LOW) and dust threshold calculations.transactions.tsfor UTXO selection, witness input construction, and metadata output appending.metadata.tsimplementing the Sundial OP_RETURN metadata protocol (60-byte schema with magic bytes, version, transaction type, deposit ID, provider pubkey, flags, and CRC-32 checksum).validation.tswith common parameter validation (locktime, amounts, protocol fees).time.tsfor timestamp/date conversions and duration calculations.network.tsdefining Bitcoin network configurations (mainnet, testnet, regtest).
bitcoin-api.ts— integration layer for external Bitcoin APIs (Mempool.space, Blockstream, BlockCypher) providing UTXO fetching, transaction broadcasting, fee estimation, and block height queries.errors.tsdefining custom error classes (BTCLockerError,ValidationError,TimelockError) for structured error handling.types.tsandindex.tsfor TypeScript type definitions and public API exports.
Supporting files include package.json, TypeScript configurations (tsconfig.json, tsconfig.build.json), Vitest test suite under tests/, ESLint/Prettier configs, and webpack bundling configuration for browser distribution.
Findings
Code ― | Title | Status | Severity | |
|---|---|---|---|---|
| F-2026-1609 | Spending PSBT Builder Omits Required Previous Output Data | fixed | Medium | |
| F-2026-1609 | Incorrect PSBT Finalization Logic for Script-Based Spending | fixed | Medium | |
| F-2026-1609 | Infinite Recursion in BTCLocker Facade Methods | fixed | Medium | |
| F-2026-1609 | Claim and Withdraw Flows Assume P2SH While Address Uses SegWit-Like Form | fixed | Low | |
| F-2026-1609 | Distribution Builder Uses Incorrect Input Script Fallback | fixed | Low | |
| F-2026-1609 | Relative Timelock (CSV) Exposed but Not Fully Implemented | fixed | Low | |
| F-2026-1609 | Inconsistent PSBT Encoding Across Public API | fixed | Low | |
| F-2026-1611 | Transaction Amount Lacks Upper Bound Validation | fixed | Observation | |
| F-2026-1611 | Keypair Object Serialization Exposes Internal ECPair Properties | fixed | Observation | |
| F-2026-1611 | UTXO Selection Without Ordinal-Safe Controls | fixed | Observation |
Appendix 1. Severity Definitions
Findings are categorized based on their potential impact and assigned a severity level using the Common Vulnerability Scoring System (CVSS) version 4.0: →
Severity | Description |
|---|---|
Critical | These issues present a major security vulnerability that poses a severe risk to the system. They require immediate attention and must be resolved to prevent a potential security breach or other significant harm. |
High | These issues present a significant risk to the system, but may not require immediate attention. They should be addressed in a timely manner to reduce the risk of the potential security breach. |
Medium | These issues present a moderate risk to the system and cannot have a great impact on its function. They should be addressed in a reasonable time frame, but may not require immediate attention. |
Low | These issues present no risk to the system and typically relate to the code quality problems or general recommendations. They do not require immediate attention and should be viewed as a minor recommendation. |
Severity
- Critical
Description
- These issues present a major security vulnerability that poses a severe risk to the system. They require immediate attention and must be resolved to prevent a potential security breach or other significant harm.
Severity
- High
Description
- These issues present a significant risk to the system, but may not require immediate attention. They should be addressed in a timely manner to reduce the risk of the potential security breach.
Severity
- Medium
Description
- These issues present a moderate risk to the system and cannot have a great impact on its function. They should be addressed in a reasonable time frame, but may not require immediate attention.
Severity
- Low
Description
- These issues present no risk to the system and typically relate to the code quality problems or general recommendations. They do not require immediate attention and should be viewed as a minor recommendation.
Appendix 2. Scope
The scope of the project includes the following:
Scope Details | |
|---|---|
| Repository | https://github.com/sundial-protocol/btc-locker→ |
| Commit | dd1332516d9721b67fefdc219048527de066cbdc |
Scope Details
- Commit
- dd1332516d9721b67fefdc219048527de066cbdc
Appendix 3. Additional Valuables
Frameworks and Methodologies
This security assessment was conducted in alignment with recognised penetration testing standards, methodologies and guidelines, including the NIST SP 800-115 – Technical Guide to Information Security Testing and Assessment →, the Penetration Testing Execution Standard (PTES) →, and the OWASP Testing Guide →. These assets provide a structured foundation for planning, executing, and documenting technical evaluations such as vulnerability assessments, exploitation activities, and security code reviews. Hacken’s internal penetration testing methodology extends these principles to Web2 and Web3 environments to ensure consistency, repeatability, and verifiable outcomes.