Reducing size of contract spec/interface in contract wasm files #1551
leighmcculloch
started this conversation in
Stellar Ecosystem Proposals
Replies: 1 comment 4 replies
-
💡 A low complex approach to reducing the size would be to GZ compress the specs. Here's an assessment of what the saving would be to GZ compress the contracts installed on mainnet. Tools that need to read the specs would need to decompress them. Most languages and environments support GZ in their stdlib, including browsers.
Ref: spec-size-gz.csv |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
From time time I hear folks talk about the size that contract specs take up in deployed contracts, and it seems like an issue that is a concern to some.
I'm starting this conversation to discuss different ideas on how the contract specs might be compacted, compressed, or changed to reduce their impact to .wasm sizes. It is also an opportunity to voice an opinion on if this is a material issue, or not an issue.
To keep the conversation organised, a few asks for participating in this thread:
To comment on existing ideas that have already been posted in a comment, please post a sub-comment on the comment.
For new ideas that don't already have a thread, please post a top-level comment proposing the idea and showing example numbers for what size the contract spec would become. There are a few hundred contracts on pubnet that can be used as examples. See the notes below for how to get and analyse them.
To indicate that contract specs size is a problem for you, press the emoji button at the top of the discussion and select 👍🏻 .
To indicate that contract specs size is not a problem for you, press the emoji button at the top of the discussion and select 👎🏻 .
Take less structured discussion to Discord here.
Note
There is no existing SEP that captures how specs are defined and work, there probably should be, but in its absence here's a quick summary:
A contract spec details the exported interface of the contract, including the:
A contract's contract spec is stored in the custom section of the Wasm file, in the section with name
contractspecv0
.The format of contract specs are a stream of XDR
SCSpecEntry
entities appended. The XDR is defined in Stellar-contract-spec.x.Developer tooling like the soroban-sdk, stellar-cli, the stellar sdks (e.g. js-stellar-sdk, etc), and other tools (e.g. stellar.expert), to just name a few, extract contract specs out of .wasm files to understand what functions exist, what parameters they require, how to construct the types, and what values they return. Contract specs are used for bindings generation to make it possible to call a contract with types native in the language in use that get converted into their Stellar representations.
Tip
Looking for contracts to analyze? I've uploaded a few hundred contracts that are deployed on mainnet here:
https://github.com/leighmcculloch/stellar-contract-wasms
Tip
If you'd like to explore the spec data is stored in a contract wasm file, or any of the files above, the wasm-cs and stellar-cli tools can inspect them, see the examples below:
Examples
Inspect what custom sections exist in your contract wasm, and how much space they are consuming:
Inspect the contents of the contractspecv0 custom section:
Decode the contract specs:
As a starting point, here's a csv of contracts on mainnet at ledger
53458367
, their size, and the size of their spec. Note this list includes all contracts installed. There's no assessment of whether they are actively used, or valuable to the community, and are just one way to consider the problem.Ref: spec-size.csv
Discord discussion thread: https://discord.com/channels/897514728459468821/1283687871491997716
Beta Was this translation helpful? Give feedback.
All reactions