Add ERC: Representable Contract State - #1396
Conversation
|
✅ All reviewers have approved. |
Co-authored-by: Andrew B Coathup <28278242+abcoathup@users.noreply.github.com>
Co-authored-by: Andrew B Coathup <28278242+abcoathup@users.noreply.github.com>
Co-authored-by: Andrew B Coathup <28278242+abcoathup@users.noreply.github.com>
|
Hi @SamWilsn — sorry for the ping. I believe I’ve addressed all of your comments. |
|
Hi @SamWilsn — just gently following up here. |
SamWilsn
left a comment
There was a problem hiding this comment.
These are pretty minor, please fix them at your leisure.
|
|
||
| At the same time, many applications require a human-readable, machine-parseable representation of that product and its state: valuation oracles need inputs for settlements, smart bonds and other tokenized instruments need legal terms, term sheets or regulatory reports, and on-chain registries, governance modules or vaults benefit from a stable "document view" of their state. | ||
|
|
||
| In the traditional off-chain world, such needs are addressed by standards like FpML, the ISDA Common Domain Model, or the ICMA Bond Data Taxonomy. A common pattern is to treat an XML (or similar) document as the definitive source defining the financial product and then generate code to interact with the corresponding data. When a process modifies or updates properties of the product, developers must synchronize the smart contract's internal state with the off-chain XML representation. Today, each project typically invents its own set of view functions and off-chain conventions, so clients need bespoke code to map contract state into XML, JSON, or PDF. This makes interoperability, independent auditing, and reuse of tooling harder. |
There was a problem hiding this comment.
These may be common abbreviations in a specific domain, but not to general Ethereum developers.
| This ERC RECOMMENDS the following minimal scheme for references to partial XML views: | ||
|
|
||
| ```text | ||
| evmstate://self/part/{partId}[?key={application-specific-key}] |
There was a problem hiding this comment.
Small aside, but might be worth reserving this scheme if it's important.
|
|
||
| For the array binding profile defined below, array-valued return types MUST NOT be used in multi-binding mode. Implementations that support the array binding profile MUST treat a binding in multi-binding mode whose declared output type is an array as an error. Array handling in this ERC is restricted to single-binding mode on the array container and to single-binding nodes inside the template row. | ||
|
|
||
| #### Example with a Single Binding to the Element's Text: |
There was a problem hiding this comment.
| #### Example with a Single Binding to the Element's Text: | |
| #### Example with a Single Binding to the Element's Text |
eip-review-bot
left a comment
There was a problem hiding this comment.
All Reviewers Have Approved; Performing Automatic Merge...
This proposal specifies a minimal interface
IXMLRepresentableStatethat lets an EVM contract expose a canonicalrepresentation of its state via an XML (or JSON) template with machine-readable bindings to its state and view functions.
Off-chain renderers use only
eth_callat a specific block to materialize that representation.Note: The corresponding interface
IJSONRepresentableStateist part of the ERC, however the binding scheme is currently focussing on XML bindings.Abstract
This ERC introduces
IXMLRepresentableState, a standard interface and XML binding schema that allows an EVM smart contract to define a static XML template with machine-readable bindings to its state and view functions. Off-chain renderers use this template to build a canonical XML document representing the contract's state at a specific block, without incurring any on-chain gas cost.A contract that claims to implement
IXMLRepresentableStateMUST be XML-complete: every piece of mutable state that the author considers semantically relevant MUST be represented in the XML via bindings, so that the rendered XML is a complete representation of the contract at a given (chain-id, address, block-number).Motivation
Smart contracts can efficiently orchestrate and process the life-cycle of a financial (derivative) product to an extent that they finally represent the financial product itself.
At the same time, many applications require a human-readable, machine-parseable representation of that product and its state: valuation oracles need inputs for settlements, smart bonds and other tokenized instruments need legal terms, term sheets or regulatory reports, and on-chain registries, governance modules or vaults benefit from a stable "document view" of their state.
In the traditional off-chain world, such needs are addressed by standards like FpML, the ISDA Common Domain Model, or the ICMA Bond Data Taxonomy. A common pattern is to treat an XML (or similar) document as the definitive source defining the financial product and then generate code to interact with the corresponding data. When a process modifies or updates properties of the product, developers must synchronize the smart contract's internal state with the off-chain XML representation. Today, each project typically invents its own set of view functions and off-chain conventions, so clients need bespoke code to map contract state into XML, JSON, or PDF. This makes interoperability, independent auditing, and reuse of tooling harder.
This ERC inverts that pattern by putting the smart contract in the centre. A contract declares that it implements
IXMLRepresentableStateand defines an interface of representable state. Off-chain renderers can then derive a canonical XML document that reflects the semantically relevant state of the contract at a given (chain-id, address, block-number), using onlyeth_calland a standardized XML binding schema. Rendering happens entirely off-chain and does not change state, so there is no gas cost, yet the resulting XML remains cryptographically anchored to the chain.Typical use cases include:
By standardizing the Solidity interface and the XML attribute schema, this ERC allows generic tools to consume any compliant contract without project-specific adapters, and to plug directly into existing XML-based workflows in finance and beyond.
Specification sketch (informal)
Very briefly, beyond the header/abstract/motivation above, the ERC specifies:
IXMLRepresentableStatewithxmlTemplate()returning a UTF‑8 XML document.IRepresentableStateVersionedwithstateVersion()(monotonically increasing version of the representable state).IRepresentableStateHashedwithstateHash()(hash of a canonical state tuple for the representation).IXMLRepresentableStateVersioned,IXMLRepresentableStateHashed,IXMLRepresentableStateVersionedHashed.evmstatenamespace, with attributes like:evmstate:call/evmstate:selector/evmstate:returnsevmstate:format/evmstate:scaleevmstate:target(element text vs. attribute target)evmstate:calls/evmstate:selectors/evmstate:returnsListevmstate:formats/evmstate:scales/evmstate:targetsA renderer:
xmlTemplate()at a fixed block tagB,evmstate:*binding viaeth_callatblockTag=B,evmstate:chain-id,evmstate:contract-address,evmstate:block-number).Snapshot consistency is guaranteed by always using the same block
Bfor all calls.Reference implementation / demos
We have a small set of demo contracts and a Java-based reference renderer (Web3j + DOM XML), including:
MinimalInstrument– owner, notional, currency, maturity, active flag.TestContract– exercises many type/format combinations (uint/int, hex, decimal+scale, iso8601 date/datetime, bytes as hex/base64, etc.) including a multi-binding example.InterestRateSwapSettleToMarket– IRS with settle-to-market semantics andlastSettlement{time,value}.BondDataTaxonomyDemo– ICMA BDT-inspired bond (issuer, ISIN, coupon, dates, etc.) rendered via evmstate bindings.Project Homepage: http://finmath.gitlab.io/representable-contract-state