Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface InstructionSet<AuthenticationProgram, ProgramState>

An InstructionSet is a mapping of methods which define the operation of an AuthenticationVirtualMachine. An instruction set is specific to a single consensus setting of a single network, e.g. BCH_2019_05_Mandatory, BCH_2019_05_Standard or BTC_2017_08_Mandatory.

An instruction set is composed of Operations which take a ProgramState and return a ProgramState, as well as the clone, continue, evaluate, and verify "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 which are unassigned by the instruction set will use the undefined operation.

Type parameters

  • AuthenticationProgram

  • ProgramState

Hierarchy

  • InstructionSet

Index

Properties

clone

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

continue: (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.

Type declaration

    • (state: ProgramState): boolean
    • Parameters

      • state: ProgramState

      Returns boolean

evaluate

evaluate: (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 semantics of the basic EvalScript system.)

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.

privateremarks

When using the debug method, the stateEvaluate parameter is given a a modified stateDebug which shares the same method signature as stateEvaluate but saves intermediate states for use in the returned array. When the method returns, the last ProgramState is added to the array of saved intermediate states, and the full array is returned. This allows the same implementation to be used for both evaluate and debug.

Due to this behavior, the ordering of ProgramStates in debugging results depends upon the order in which stateEvaluate is called in this method. If stateEvaluate is called multiple times, the intermediate results from the first call will be appear before the results of the second call, etc.

Type declaration

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

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

            • state: Readonly<ProgramState>

            Returns ProgramState

      Returns ProgramState

operations

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.

undefined

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

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

Verify a program state has completed evaluation successfully.

remarks

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

Type declaration

    • (state: ProgramState): string | true
    • Parameters

      • state: ProgramState

      Returns string | true

Generated using TypeDoc