Precompiled contract offers a method to program contract using C++. It separates contract logic with data, and has better performance than solidity contract. The update can be achieved by modifying the codes in bottom layer.
Precompied contract and solidity contract¶
|table||precompiled contract||Solidity contract|
|address||fixed address, defined in codes||confirmed during deployment|
|contract code||data stored in table, separate with contract, contract logic can be updated||contract variety and data stored in MPT tree|
|execution||in C++ bottom layer, higher performance, support parallel execution||EVM virtual machine， serial execution|
The structure of Precompiled is as below:
- Block verifier will verify type of contract by the address of the called contract during transaction execution. Address 1-4 indicates Ethereum Precompile contract; address 0x1000-0x10000 belongs to C++ Precompiled contract, other addresses belong to EVM contract.
- The execution of Precompiled contract needs a object acquired through contract address.
- Each Precompiled contract object will implement
callAPI, in which the detail logic of Precompile contract is implemented.
callprograms according to abi of transaction, acquires
Function Selectorand parameter, and executes the relative logic.
Every Precompiled contract has to realize its own
call API, which accepts 3 parameters:
ExecutiveContext executive context, abi code of
bytesConstRef and exterior account address to judge whether it has write permission.
Precompiled source code.
|API||Parameter description||Api description|
||implementation of contract API|
||acquire abi code of parameter of the called function|