-
Notifications
You must be signed in to change notification settings - Fork 3
Closed
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation
Description
We would love to support other PVM implementations than typeberry.
If you'd like to be listed in the select box on the PVM disassembler page, please add a comment in this issue.
The idea is to compile the PVM to WASM (if possible) and expose a common interface that is yet to be fully defined (we are open for discussion).
The proposed interface for now is:
interface PvmMinimal {
/**
* Re-initialize the PVM with given generic PVM program.
*
* This function is optional. The support is indicated in the metadata.
*
* Note: memory initialisation is deliberately missing for now. A good format for this is TBD.
*/
resetGeneric(program: Uint8Array, registers: Uint8Array, gas: i64): void;
/**
* Returns the current program counter of PVM
*/
getProgramCounter(): u32;
/**
* Set next program counter that will be applied on the next step.
* This is needed to control the entry point.
*/
setNextProgramCounter(pc: u32): void;
/**
* Get the current status of PVM
*
* Status {
* Ok = 255,
* Halt = 0,
* Panic = 1,
* Fault = 2,
* Host = 3,
* OutOfGas = 4,
* }
*/
getStatus(): u8;
/**
* Return an exit argument in case the PVM stopped with one.
* 1. In case of a page fault this is going to be the address,
* 2. In case of a host call this will be the host call index.
*/
getExitArg(): u32;
/**
* Return gas left.
*/
getGasLeft(): i64;
/**
* Set how much gas is left (e.g. after returning from a host call).
*/
setGasLeft(gas: i64);
/**
* Return registers dump.
*
* We expect 13 values, 4 bytes each, representing the state of all registers as a single byte array.
*/
getRegisters(): Uint8Array;
/**
* Perform a single step of PVM execution.
*
* Returns false when the machine cannot make any more progress (i.e. it halted, panicked, or went out of gas).
*/
nextStep(): boolean;
/**
* Returns a fixed-length page of memory.
*
* it's up to the implementation to decide if this is going to return just a single memory cell,
* or a page of some specific size.
* The page sizes should always be the same though (i.e. the UI will assume that if page 0 has size `N`
* every other page has the same size).
*/
getPageDump(pageIndex: u32): Uint8Array;
}
/** Each function from this set is optional and may or may not be supported by a PVM. */
type PvmOptionals {
* Re-initialize the PVM with given generic PVM program and memory layout.
*
* This function is optional. The support is indicated in the metadata.
*
* PageMap: `sequence(tuple(address: u32 , length: u32))`
* Chunks: `sequence(tuple(address: u32, length: u32, data: sequence(u8)))`
*/
resetGenericWithMemory(program: Uint8Array, registers: Uint8Array, pageMap: Uint8Array, memoryChunks: Uint8Array, gas: i64): void;
/**
* Re-initialize the PVM with given PVM program for JAM in Standard Program Initialisation container format.
*
* This function is optional. The support is indicated in the metadata.
*/
resetJAM(program: Uint8Array, gas: i64): void;
/**
* Re-initialize the PVM with given PVM program in PolkaVM container.
*
* This function is optional. The support is indicated in the metadata.
*/
resetPolkaVM(program: Uint8Array, gas: i64): void;
/**
* Overwrite all registers.
*
* We expect 13 values, 4 bytes each, representing the state of all registers as a single byte array.
*/
setRegisters(registers: Uint8Array): void;
/**
* Write a bunch of bytes to the memory.
*
* The data should fit on one page - in case it spans multiple pages it's UB.
*/
setMemory(address: u32, data: Uint8Array): void;
/**
* Return all page indices that have values that were explicitly set by the program.
* Each memory page index should be represented by 4 bytes.
*/
getDirtyMemoryPages(): Uint8Array
}
type Metadata = {
name: string;
version: string;
capabilities: {
resetJAM: boolean;
resetPolkaVM: boolean;
resetGeneric: boolean;
resetGenericWithMemory: boolean;
},
wasmBlobUrl: string
}
I imagine that the teams will provide an URL for the JSON
file with metadata. That file will be fetched by the UI at start to decouple deployment process of PVM implementations and the UI.
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation