Ventimore Ltd
 
  HOME   DOCS    
 
The BSV Editor

Scripts

Transaction scripts are binary, low level objects designed to be executed efficiently. They consist of a sequence of opcodes and data.

Transaction scripts are generally generated from script language. I.e.

script language binary script (opcodes + data)

More information can be found here.

Data Format

The script interpreter (which executes the binary script) assumes that the next byte in a binary script is an opcode (not data) unless one of the OP_PUSHDATA opcodes is encountered.

Data is stored in one of the following format

<1-byte data length specifier> <data>
 
OP_PUSHDATA1 <1-byte data length specifier> <data>
 
OP_PUSHDATA2 <2-byte data length specifier> <data>
 
OP_PUSHDATA4 <4-byte data length specifier> <data>

The first format (no OP_PUSHDATAX) can only be used if the data length specifier is less than 75. The 2-byte and 4-byte length specifiers should be CScriptNum objects.

The data contains no type information. For example, the data may actually represent a string, but the interpreter will happily treat the data as a number and attempt to mulitply it with a number if asked to (and probably producing an error).

The standard Bitcoin script language (asm) allows data to be represented as

  1. opcodes OP_0 .. OP_16
  2. signed (decimal) integers (e.g. -123)
  3. hex - which starts with '0x' (e.g. 0xCAFEBABE)
  4. strings - quoted data (e.g. 'Hello world')

These formats have a number of idiosyncracies.

1. The hex 0xAABBCC does mean the hex number 0xAABBCC (whose binary implementation is machine dependent), rather it represents the byte sequence 0xAA, 0xBB, 0xCC.

2. It is common practice amongst authors to exclude the OP_PUSHDATA opcode and the data length specifier from scripts. The BSV Editor does not follow that convention. The reason is that the BSV Editor is intended for the development of complex scripts, including those generated by high-level languages. It is therefore important that the script text accurately reflects the binary opcodes and data seen by the interpreter, and is not a reduced view.

For example, the following P2PKH locking script

"OP_DUP OP_HASH160 7f9b1a7fb68d60c536c2fd8aeaa53a8f3cc025a8 OP_EQUALVERIFY OP_CHECKSIG"

would be displayed in the BSV Editor as

"OP_DUP OP_HASH160 L20 0x7f9b1a7fb68d60c536c2fd8aeaa53a8f3cc025a8 OP_EQUALVERIFY OP_CHECKSIG"

The length specifier is denoted L20 rather than 20, which removes any possible ambiguity about its purpose.

Saving Script Text

Note that information is lost going from script language binary script (opcodes + data) script language. Hex is always used to describe the result of decoding a binary script.

BSV Editor allows users to store the original script text with the transaction. To enable this feature, choose the Windows > Settings menu options and then enable the 'Save script text' checkbox. (Not currently implemented)

Script Links

BSV Editor allows script objects to be stored searately from the transaction object; the transaction object stores a link to the script object rather than storing the script text. To link a transaction script to a script object, right click on the script you wish to link and chose the Link input[n] script menu option (as below). You will be asked for the name of the script object. Once a transaction script is linked to a script object, it cannot be updated using the transaction view. Instead edit and debug the script usin the script/spend view.

 

 
     
 

 

Copyright (c) Ventimore Ltd (UK), 2011, 2012, 2017, 2018.