ics02

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

README

ICS02 Precompile

The ICS02 precompile provides an EVM interface to the IBC-Go's 02-client module, enabling smart contracts to interact with IBC light clients using the ICS-02 standard.

Address

The precompile is available at the fixed address: 0x0000000000000000000000000000000000000807

Interface

Data Structures
/// @notice The result of an update operation
enum UpdateResult {
    /// The update was successful
    Update,
    /// A misbehaviour was detected
    Misbehaviour
}
Transaction Methods
/// @notice Updates the client with the given client identifier.
/// @param clientId The client identifier
/// @param updateMsg The encoded update message e.g., a protobuf any.
/// @return The result of the update operation
function updateClient(string calldata clientId, bytes calldata updateMsg) external returns (UpdateResult);

/// @notice Querying the membership of a key-value pair
/// @dev Notice that this message is not view, as it may update the client state for caching purposes.
/// @param proof The proof of membership
/// @param proofHeight The height of the proof
/// @param path The path of the value in the Merkle tree
/// @param value The value in the Merkle tree
/// @return The unix timestamp of the verification height in the counterparty chain in seconds.
function verifyMembership(
    string calldata clientId,
    bytes calldata proof,
    Height calldata proofHeight,
    bytes[] calldata path,
    bytes calldata value
) external returns (uint256);

/// @notice Querying the non-membership of a key
/// @dev Notice that this message is not view, as it may update the client state for caching purposes.
/// @param proof The proof of membership
/// @param proofHeight The height of the proof
/// @param path The path of the value in the Merkle tree
/// @return The unix timestamp of the verification height in the counterparty chain in seconds.
function verifyNonMembership(
    string calldata clientId,
    bytes calldata proof,
    Height calldata proofHeight,
    bytes[] calldata path
) external returns (uint256);
Query Methods
/// @notice Returns the client state.
/// @param clientId The client identifier
/// @return The client state.
function getClientState(string calldata clientId) external view returns (bytes memory);

Gas Costs

Gas costs are calculated dynamically based on:

  • Base gas for the method
  • Additional gas for IBC operations
  • Key-value storage operations

The precompile uses standard gas configuration for storage operations.

Implementation Details

GetClientState

This method is meant to be called by solidity-ibc relayers. It validates the client identifier and retrieves the protobuf encoded client state from the IBC-Go store. The relayer must decode the client state to correct type to use it.

UpdateClient

This method allows updating the IBC light client state on-chain. It accepts a client identifier and an encoded client message (a protobuf Any). The method processes the update message, verifies it, and updates the client state accordingly. It returns an UpdateResult enum indicating whether the update was successful or if misbehaviour was detected.

VerifyMembership and VerifyNonMembership

These methods allow smart contracts to verify the membership or non-membership of key-value pairs in the IBC light client's state. They accept a client identifier, a proof, proof height, and the path (and value for membership). The methods validate the proofs against the client state and return the unix timestamp (in seconds) of the verification height in the counterparty chain.

Events

The ICS-02 precompile does not emit any events. Since it is meant to be called by other solidity-ibc contracts, events should be emitted by the calling contract if needed.

Usage Example

A usage example is to be included in solidity-ibc repository. For now, we link the tracking issue: cosmos/solidity-ibc-eureka#794.

Documentation

Index

Constants

View Source
const (
	UpdateClientMethod        = "updateClient"
	VerifyMembershipMethod    = "verifyMembership"
	VerifyNonMembershipMethod = "verifyNonMembership"
)
View Source
const (
	UpdateResultSuccess      uint8 = 0
	UpdateResultMisbehaviour uint8 = 1
)
View Source
const (
	// GetClientStateMethod defines the get client state query method name.
	GetClientStateMethod = "getClientState"
)

Variables

View Source
var (
	ABI abi.ABI
)

Functions

func ParseGetClientStateArgs

func ParseGetClientStateArgs(args []interface{}) (string, error)

ParseGetClientStateArgs parses the arguments for the GetClientState method.

func ParseUpdateClientArgs

func ParseUpdateClientArgs(args []interface{}) (string, []byte, error)

ParseUpdateClientArgs parses the arguments for the UpdateClient method.

func ParseVerifyMembershipArgs

func ParseVerifyMembershipArgs(method *abi.Method, args []interface{}) (string, []byte, clienttypes.Height, [][]byte, []byte, error)

ParseVerifyMembershipArgs parses the arguments for the VerifyMembership method.

func ParseVerifyNonMembershipArgs

func ParseVerifyNonMembershipArgs(method *abi.Method, args []interface{}) (string, []byte, clienttypes.Height, [][]byte, error)

ParseVerifyNonMembershipArgs parses the arguments for the VerifyNonMembership method.

Types

type Precompile

type Precompile struct {
	cmn.Precompile

	abi.ABI
	// contains filtered or unexported fields
}

Precompile defines the precompiled contract for ICS02.

func NewPrecompile

func NewPrecompile(
	cdc codec.Codec,
	clientKeeper ibcutils.ClientKeeper,
) *Precompile

NewPrecompile creates a new Client Precompile instance as a PrecompiledContract interface.

func (Precompile) Execute

func (p Precompile) Execute(ctx sdk.Context, stateDB vm.StateDB, contract *vm.Contract, readOnly bool) ([]byte, error)

func (*Precompile) GetClientState

func (p *Precompile) GetClientState(
	ctx sdk.Context,
	_ *vm.Contract,
	_ vm.StateDB,
	method *abi.Method,
	args []interface{},
) ([]byte, error)

GetClientState returns the client state for the precompile's client ID.

func (Precompile) IsTransaction

func (Precompile) IsTransaction(method *abi.Method) bool

IsTransaction checks if the given method name corresponds to a transaction or query.

func (Precompile) Logger

func (p Precompile) Logger(ctx sdk.Context) log.Logger

Logger returns a precompile-specific logger.

func (Precompile) Name

func (Precompile) Name() string

func (Precompile) RequiredGas

func (p Precompile) RequiredGas(input []byte) uint64

RequiredGas calculates the precompiled contract's base gas rate.

func (Precompile) Run

func (p Precompile) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([]byte, error)

func (*Precompile) UpdateClient

func (p *Precompile) UpdateClient(
	ctx sdk.Context,
	_ *vm.Contract,
	_ vm.StateDB,
	method *abi.Method,
	args []interface{},
) ([]byte, error)

UpdateClient implements the ICS02 UpdateClient transactions.

func (*Precompile) VerifyMembership

func (p *Precompile) VerifyMembership(
	ctx sdk.Context,
	_ *vm.Contract,
	_ vm.StateDB,
	method *abi.Method,
	args []interface{},
) ([]byte, error)

VerifyMembership implements the ICS02 VerifyMembership transactions.

func (*Precompile) VerifyNonMembership

func (p *Precompile) VerifyNonMembership(
	ctx sdk.Context,
	_ *vm.Contract,
	_ vm.StateDB,
	method *abi.Method,
	args []interface{},
) ([]byte, error)

VerifyNonMembership implements the ICS02 VerifyNonMembership transactions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL