concrete-eth / concrete-geth

Concrete is a framework for building application-specific rollups on the OP Stack
GNU Lesser General Public License v3.0
47 stars 19 forks source link

Built-in registry precompiles #9

Closed therealbytes closed 1 year ago

therealbytes commented 1 year ago

Right now, concrete has the following problems:

This PR fixes both of them by adding three built-in precompiles to concrete.

PrecompileRegistry @ 0xcc00000000000000000000000000000000000000

A registry of all concrete precompiles active in this chain, including itself and the two others listed below. It also exposes basic framework metadata.

struct FrameworkMetadata {
    string name;    // "Concrete"
    string version; // "0.1.0"
    string source;  // "https://github.com/therealbytes/concrete-geth"
}

struct PrecompileMetadata {
    address addr;       // "0xcc00000000000000000000000000000000000000"
    string name;        // "PrecompileRegistry"
    string version;     // "0.1.0"
    string author;      // "The concrete-geth Authors"
    string description; // "A registry of precompiles indexed by address and name."
    string source;      // "https://github.com/therealbytes/concrete-geth/tree/concrete/concrete/precompiles/precompile_registry.go",
    string ABI;         // { ... }
}

interface PrecompileRegistry {
    function getFramework()
        external
        view
        returns (FrameworkMetadata memory);

    function getPrecompile(
        address _addr
    ) external view returns (PrecompileMetadata memory);

    function getPrecompileByName(
        string memory _name
    ) external view returns (address);

    function getPrecompiledAddresses() external view returns (address[] memory);

    function getPrecompiles()
        external
        view
        returns (PrecompileMetadata[] memory);
}

PreimageRegistry @ 0xcc00000000000000000000000000000000000001

A registry of all preimages added by PersistentStorage. Note getPreimage takes both the preimage hash and size (which can easily be obtained with getPreimageSize), this is so the call to RequiredGas remains stateless.

interface PreimageRegistry {
    function addPreimage(bytes memory preimage) external returns (bytes32);

    function hasPreimage(bytes32 _hash) external view returns (bool);

    function getPreimageSize(bytes32 _hash) external view returns (uint256);

    function getPreimage(
        uint256 size,
        bytes32 _hash
    ) external view returns (bytes memory);
}

BigPreimageRegistry @ 0xcc00000000000000000000000000000000000002

Same as above but for preimages added with BigPreimageStore. e.g., api.NewPersistentBigPreimageStore(concrete, radix, leafSize).AddPreimage(preimage). Note that (persistent) BigPreimageStore uses PersistentStorage to store the nodes of a Merkle tree holding the preimage, individual nodes will be available through the PreimageRegistry precompile like any other preimage.