sCrypt Exeter: Opcodes, Sighash preimages, and private and public keys

Price also discussed important topics such as Sighash preimages, private and public keys, and the Pay to Public Key Hash (P2PKH).

sCrypt recently hosted a four-day Bitcoin hackathon at the University of Exeter in June 2023. The workshop was designed to introduce the students to smart contracts built on a scalable public blockchain using sCrypt tooling. Following the workshop, students had a few months to design their web-based applications using the skills they learned.

As part of the workshop, Curriculum Specialist at the BSV Association Todd Price gave a presentation on Bitcoin Script, with a specific focus on the OP_CODESEPARATOR – arguably the most mysterious opcode in Bitcoin Script. He also discussed important topics such as Sighash preimages, private and public keys, and the Pay to Public Key Hash (P2PKH).

Price’s presentation was set directly after Xiaohui Liu’s presentation. While Liu’s presentation focused on the high-level scripting language, sCrypt, Price’s presentation took a look at Bitcoin transactions ‘under the hood’.

Under the hood of Bitcoin transactions

Sighash preimage is what gets signed in a Bitcoin signature, whose format is as follows:

  1. version of the transaction (4-byte little endian)
  2. hashPrevouts (32-byte hash)
  3. hashSequence (32-byte hash)
  4. outpoint (32-byte hash + 4-byte little endian)
  5. scriptCode of the input (serialised as scripts inside CTxOuts)
  6. value of the output spent by this input (8-byte little endian)
  7. nSequence of the input (4-byte little endian)
  8. hashOutputs (32-byte hash)
  9. nLocktime of the transaction (4-byte little endian)
  10. sighash type of the signature (4-byte little endian)

Part 5, scriptCode, usually contains the entire locking script. The only exception is when there is OP_CODESEPARATOR (OCS) in it. In this case, the scriptCode is the locking script but removing everything up to and including the last executed OCS before OP_CHECKSIG is executed.

A more technical breakdown of the concepts can be found here.

Learn more with the BSV Academy

BSV Academy is an online education platform for Bitcoin which offers academia-quality, university-style courses and learning materials categorised under Bitcoin in Law, Bitcoin for Software Engineering, Bitcoin for Software Development and Bitcoin for Business in addition to several short courses covering specific concepts and content in more detail.

Developed and run by the BSV Association, the BSV Academy has been created to make learning about the Bitcoin protocol – the way creator Satoshi Nakamoto designed it – accessible, accurate, and understandable.

, , ,