
This engineering research project is focused on the implementation of native Bitcoin Smart Contracts. The work documents an in-depth study of the SegWit architecture and the advanced use of the Bitcoin Script language for building complex cryptographic logic.
The advanced topics explored (supported by the development of a dedicated Docker environment for local testing) include:
- Transaction Malleability Resolution: Detailed analysis of this historical bug and how the implementation of Segregated Witness (SegWit) solved it by separating the witness from the inputs.
- Multisig and P2SH: Evolution of multisignature scripts: from primitive P2MS to the scratch-building of 2-of-3 Pay To Script Hash (P2SH) addresses, analyzing stack resolution during validations.
- Transaction Signing (Legacy vs SegWit): Complete workflow for the manual construction and signing (ECDSA) of transactions. Study of serialization differences and the new weight calculation (vbyte) introduced by SegWit for P2WPKH transactions.
- Timelocks & Smart Contracts (HTLC): Temporal control of funds via nLockTime, nSequence, CLTV, and CSV. Development of advanced conditional scripts (OP_IF) and native implementation of HTLCs, the architectural foundations of the Lightning Network.
This meticulous reverse-engineering work, executed entirely in Bash (without external libraries abstracting the complexity), solidified critical skills: the concatenation of digital signatures, the advanced use of stack-based languages, and the programming of Smart Contracts from scratch. Furthermore, the practical management of network nodes allowed me to directly experience the importance of optimizing transmitted payloads (byte analysis and weight reduction), a vital aspect for engineering globally distributed P2P networks.
