Program

class jam.pvm.program.Program(z: U8, jump_table: List[int], instruction_set: List[U8], offset_bitmask: List[Bit])[source]

Bases: Codable

This is the program blob which the PVM will execute.

Parameters:
  • z – Size of jump-table entries

  • jump_table – sequence of NN, each of size z

  • instruction_set – Sequence of instructions (U8)

  • offset_bitmask – Bitsequence of size len(instruction_set) that defines which blob is an opcode

__init__(z: U8, jump_table: List[int], instruction_set: List[U8], offset_bitmask: List[Bit])[source]

Initialize the Codable.

Parameters:
  • codec – Optional codec to use for encoding/decoding

  • enc_sequence – Optional function that returns sequence of fields to encode

z: U8
jump_table: List[int]
instruction_set: List[U8]
offset_bitmask: List[Bit]
encode_size() int[source]

Calculate number of bytes needed to encode.

encode_into(buffer: bytes | bytearray, offset: int = 0) int[source]

Encode the program bytecode into a buffer.

Parameters:
  • buffer – The buffer to encode the program into

  • offset – Offset of the buffer to start encoding from

static decode_from(buffer: bytes | bytearray, offset: int = 0) Tuple[Self, int][source]

Decode a program from a bytes

Parameters:
  • buffer (Union[bytes, bytearray]) – Bytes

  • offset (int, optional) – Where to start decoding from. Defaults to 0.

Returns:

Returns Program and bytes read

Return type:

Tuple[Self, int]

static from_json(buffer: bytes | bytearray) Self[source]
execute(register: U64, initial_registers: Registers, gas: U64, memory: MemoryChunk) Registers[source]