[SVMC] specifies a generic API for Sila execution engines.
This SIP specifies a way of providing implementations of Sila precompiled contracts
using the [SVMC VM API].
Specification
For the complete [SVMC] specification visit the [SVMC documentation] first.
This SIP is based on and is compatible with SVMC ABI version 6.
The SVMC module with implementations of precompiled contracts SHOULD:
Advertise the [SVMC_CAPABILITY_PRECOMPILES] capability
in the [get_capabilities()] method.
Implement the [execute()] method in the following way:
Validate the incoming execution request requirements:
The message kind ([svmc_message::kind]) is a call ([SVMC_CALL]).
The call destination address ([svmc_message::destination])
is within the range of precompiled contracts defined by SIP-1352.
There is no code provided (the code argument is NULL and code_size argument is 0).
If the requirements are not fulfilled, abort execution with the [SVMC_REJECTED] status code.
Check if the call destination address ([svmc_message::destination])
targets existing precompiled contract.
Consider the SVM revision ([svmc_revision]) requested by
the rev parameter of [execute()].
If yes, execute as follows:
Inspect the input data ([svmc_message::input_data], [svmc_message::input_size])
and calculate the gas cost of the execution.
Compute the amount of gas left after execution by
subtracting the gas cost from the call gas limit ([svmc_message::gas]).
If gas left is negative,
abort execution with the [SVMC_OUT_OF_GAS] status code.
Otherwise,
execute the code of the precompiled contract,
return the [SVMC_SUCCESS] status code, the output and gas left
([svmc_result::output_data], [svmc_result::output_size], [svmc_result::gas_left]).
Otherwise, emulate execution of empty code by returning
the [SVMC_SUCCESS] status code
and gas left equal the call gas limit ([svmc_message::gas]).
Precompiled contract implementations are allowed to return two more SVMC error codes:
[SVMC_FAILURE] if the failure was caused due to something other than out of gas (e.g. input validation error)
[SVMC_REVERT] if the precompile doesn’t want to forfeit all supplied gas (as of May 2019 no such precompile exists)
The Client is not required to provide the Host interface ([svmc_context] argument of [execute()] is set to NULL).
Therefore, the precompiled contracts implementation MUST NOT access the svmc_context.
Rationale
It is very unlikely that any precompile will need to access or modify a contract state.
Not requiring the Client to implement the SVMC Host interface removes the big portion of work
needed for full SVMC integration.
Test Cases
SVMC provides the [svmc-vmtester] tool for checking compatibility with the SVMC specification.
Implementations
[Example of Precompiles VM implementation][example_precompiles_vm.cpp]
Paweł Bylica (@chfast), Alex Beregszaszi (@axic), "SIP-2003: SVMC modules for implementations of precompiled contracts [STAGNANT]," Sila Improvement Proposals, no. 2003, May 2019. Available: https://sips.sila.org/SIPS/sip-2003.