Interface InstructionSet<ResolvedTransaction, AuthenticationProgram, ProgramState>

An InstructionSet is a mapping of methods that define the operation of an AuthenticationVirtualMachine.

An instruction set is composed of Operations that take a ProgramState and return a ProgramState, as well as several instruction set "lifecycle" methods.

Each operation is assigned to its opcode number (between 0 and 255). When evaluating instructions, the virtual machine will select an Operation based on its opcode. Any opcodes that are unassigned by the instruction set will use the undefined operation.

Type Parameters

  • ResolvedTransaction

  • AuthenticationProgram

  • ProgramState

Hierarchy

  • InstructionSet

Properties

clone: Operation<ProgramState>

Take a ProgramState and return a new copy of that ProgramState.

Remarks

This method is used internally by stateEvaluate, stateStep, and stateDebug to prevent the AuthenticationVirtualMachine from mutating an input when mutation is not desirable.

continue: ((state: ProgramState) => boolean)

Type declaration

    • (state: ProgramState): boolean
    • Test the ProgramState to determine if execution should continue.

      Remarks

      This method is used internally by the AuthenticationVirtualMachine's stateEvaluate and stateDebug methods after each operation, and should usually test for errors or program completion. This method is exposed via the AuthenticationVirtualMachine's stateContinue method.

      Parameters

      • state: ProgramState

      Returns boolean

evaluate: ((program: AuthenticationProgram, stateEvaluate: ((state: Readonly<ProgramState>) => ProgramState)) => ProgramState)

Type declaration

    • (program: AuthenticationProgram, stateEvaluate: ((state: Readonly<ProgramState>) => ProgramState)): ProgramState
    • Evaluate a program to completion given the AuthenticationVirtualMachine's stateEvaluate method.

      Remarks

      Each AuthenticationVirtualMachine can have precise operation requirements modifying the ways in which AuthenticationPrograms and ProgramStates are interpreted. (In the C++ implementations, these requirements are encoded in VerifyScript, and can significantly modify the behavior of the basic EvalScript system.) For example, the secondary evaluation step required for P2SH can be performed in this method.

      This method is used internally by the AuthenticationVirtualMachine's evaluate and debug methods. It should perform any necessary operations and validations before returning a fully-evaluated ProgramState.

      Parameters

      • program: AuthenticationProgram
      • stateEvaluate: ((state: Readonly<ProgramState>) => ProgramState)
          • (state: Readonly<ProgramState>): ProgramState
          • Parameters

            • state: Readonly<ProgramState>

            Returns ProgramState

      Returns ProgramState

every?: Operation<ProgramState>

An optional operation to be performed after every executed virtual machine operation. This is useful for implementing logic that is common to all operations, e.g. stack depth or memory usage, operation count, etc.

operations: InstructionSetOperationMapping<ProgramState>

A mapping of opcode numbers (between 0 and 255) to Operations. When the AuthenticationVirtualMachine encounters an instruction for the specified opcode, the program state will be passed to the specified operation.

success: ((state: ProgramState) => string | true)

Type declaration

    • (state: ProgramState): string | true
    • Verify that a program state has completed evaluation successfully.

      Remarks

      This method should return true if the evaluation was successful, or an error message on failure.

      Parameters

      • state: ProgramState

      Returns string | true

undefined: Operation<ProgramState>

This operation is called when an undefined opcode is encountered.

Remarks

This method should usually mark the ProgramState with an error.

verify: ((resolvedTransaction: ResolvedTransaction, evaluate: ((program: Readonly<AuthenticationProgram>) => ProgramState), success: ((state: ProgramState) => string | true)) => string | true)

Type declaration

    • (resolvedTransaction: ResolvedTransaction, evaluate: ((program: Readonly<AuthenticationProgram>) => ProgramState), success: ((state: ProgramState) => string | true)): string | true
    • Verify a transaction given the InstructionSet's evaluate and success methods and a fully-resolved transaction (e.g. the decoded transaction and an array of the outputs spent by its inputs).

      This method should perform all possible stateless transaction validation but should not attempt to perform any kinds of network state-sensitive validation (ensuring source outputs remain unspent, validating claimed absolute or relative locktime values against current network conditions, etc.), as such results could not be safely cached.

      Remarks

      This method should return true if the transaction is valid, or an array of error messages on failure.

      Parameters

      • resolvedTransaction: ResolvedTransaction
      • evaluate: ((program: Readonly<AuthenticationProgram>) => ProgramState)
          • (program: Readonly<AuthenticationProgram>): ProgramState
          • Parameters

            • program: Readonly<AuthenticationProgram>

            Returns ProgramState

      • success: ((state: ProgramState) => string | true)
          • (state: ProgramState): string | true
          • Parameters

            • state: ProgramState

            Returns string | true

      Returns string | true

Generated using TypeDoc