LPsLux Proposals
Precompiles
LP-1230

On-Chain GraphQL Query Precompile

Final

A precompile that lets any EVM contract run a GraphQL query against the G-Chain query layer, with a result cache, subscriptions, and index hints, and a gas schedule priced off the query AST

Category
Core
Created
2026-04-13

Abstract

An on-chain GraphQL query precompile lets any EVM contract execute a GraphQL query against the G-Chain query layer (LP-1300). Contracts read indexed chain state, cross-chain data, and oracle feeds without any off-chain infrastructure. The precompile carries a result cache, subscription registration, cache management, and index hinting.

Specification

Addresses

AddressFunction
0x0500000000000000000000000000000000000010GraphQL query execution
0x0500000000000000000000000000000000000011Subscription registration
0x0500000000000000000000000000000000000012Cache management
0x0500000000000000000000000000000000000013Index hints

The authoritative as-built address table for every Lux precompile is LP-1210; the derivation rule is LP-1220.

Interface

Query (0x…0010):

Input:  query_len(2) + query(UTF-8) + variables_len(2) + variables(JSON)
Output: result(JSON bytes)

Subscribe (0x…0011):

Input:  subscription query + callback address + callback selector
Output: subscription_id(32)

Cache (0x…0012):

Input:  op(1) + cache_key(32)
  0x01: Get cached result
  0x02: Invalidate cache entry
  0x03: Set TTL

Gas schedule

Gas scales with query complexity, estimated from the query AST:

ComponentGas
Base query5,000
Per field100
Per filter / where clause500
Per join / relation1,000
Cache hit500
Subscription registration10,000

Security Considerations

  1. Query complexity is bounded — maximum depth, field count, and result size are all enforced, so a query cannot become a denial-of-service vector.
  2. Cross-chain queries return data at the latest finalized block height. No unconfirmed data reaches a contract.
  3. Cache entries carry TTLs and can be invalidated. The staleness risk is the calling contract's to manage.
  4. The G-Chain client connection is local to the node. No external network call happens during EVM execution.

References

Copyright and related rights waived via CC0.