Blockchain Scripts

May 15, 2024 3:59:44 PM

Blockchain Scripts

Blockchain scripts are instructions embedded within transactions, blocks, and smart contracts on a blockchain network. The steps included in a script are processed by the network virtual machine, ensuring the same outcome across all nodes. The code is limited by the opcodes supported by the blockchain’s scripting language, which can vary between different platforms.

The code within a script is limited by the opcodes and virtual machine capabilities. The Neo Virtual Machine(NeoVM) and Ethereum Virtual Machine(EVM) are examples of blockchain-specific virtual machines that execute scripts on their respective networks.

The execution is deterministic, meaning that the same input will always produce the same output. This ensures that the blockchain’s state remains consistent across all nodes.

Blockchain scripts are also referred to as bytecode. The bytecode contains the instructions and parameters used to process transactions, validate blocks, and execute smart contracts. Verification scripts, invocation scripts, block scripts, transaction scripts, and smart contract scripts are the primary types of blockchain scripts.

Blockchain Scripts - Key Concepts

  • Ensure Deterministic Execution: The same input will always produce the same output, ensuring consistency across all nodes.
  • Limited by Opcodes: The code is limited by the opcodes supported by the blockchain’s scripting language.
  • Embedded in Transactions and Blocks: Scripts are embedded within transactions and blocks to execute specific functions.
  • Verification Scripts: Used to validate transactions and blocks.
  • Platform-Specific Virtual Machines: Each blockchain network has a specific virtual machine to execute scripts.
  • Bytecode: The instructions and parameters in a script are referred to as bytecode.

Deterministic Script Execution

Blockchains must ensure that all nodes reach the same state after processing transactions and blocks. This is achieved through deterministic script execution, where the same input will always produce the same output.

The operations within a script are not processed by the node itself, but by a virtual machine that executes the instructions. This abstraction is necessary to avoid inconsistencies caused by different hardware or software configurations.

Turing Completeness

Turing completeness refers to the ability of a system to execute any arbitrary computation. While some blockchain scripting languages are Turing complete, others are intentionally limited to prevent infinite loops and other security vulnerabilities.

While smart contracts are Turing complete, they are subject to gas limits that prevent infinite loops and other malicious behavior.

Finite Scripts

Finite scripts are those that have a limited number of instructions and are guaranteed to terminate within a certain number of steps. Verification scripts are an example of finite scripts used to validate transactions and blocks. On Neo, they are limited to 0.5 GAS.

Finite scripts may have other limitations, such as writing to storage or using specific opcodes.

GAS Execution Cost

The execution of scripts on a blockchain network consumes computational resources, which are measured in GAS. GAS is a unit of measurement that represents the computational cost of processing a transaction or executing a smart contract. GAS fees are used to avoid network abuse and prevent infinite execution loops.

The cost of executing a script is determined by the complexity of the instructions, the number of operations performed, and the resources consumed by the virtual machine.

Network Fees and System Fees on Neo

Some platforms like Neo divide the fees into two categories: network fees and system fees. Network fees are charged based on transaction size, priority and validation requirements.

System fees are proportional to the computational resources consumed by the script execution. Invoking smart contracts, deploying new contracts, and executing complex operations incur system fees.

Network fees are paid to the consensus nodes, while system fees are destroyed to prevent inflation and maintain the scarcity of the platform’s native token (GAS).

Transaction Scripts

The execution instructions of a transaction are contained within the transaction script. It defines the operations that must be performed to process the transaction, such as invoking a smart contract.