-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider using shorter port IDs #1600
Comments
Thanks Simon for bringing this up. Storage efficiency does make sense and should be a goal. We do store the ibc-port with the contract-info to make it queryable. |
That's a good point I was not aware of
The storage layout is in the spec and cannot be changed without breaking IBC light clients.
Yeah, but this is 60 bytes less for every single IBC related entry than what wasmd uses. Overall, I share your sentiment. There are two strong arguments to keep it as is:
Closing for now but happy to re-open if someone finds this later and has additional thoughs on the topic. |
Currently the IBC ports assigned to contracts are in the form
wasm.<contract address as bech32>
. This is pretty long, e.g.wasm.juno1qr84ktm57q5t02u04ddk5r8s79axdzglad6tfdd9g2xgt4hkh6jsgeq9x2
is 68 bytes long.Now those ports are used as keys in IBC storage as defined in https://github.com/cosmos/ibc/tree/main/spec/core/ics-004-channel-and-packet-semantics#store-paths, e.g.
In KV databases it seems to be important to use short keys in order to keep them efficient. This allows faster lookups in the file system and more elements in memory. This was discussed by people much more knowledgeable than me in the SDK repo but it is plausible when looking at the basics of those databases.
So right now we waste something like 50 bytes for every IBC related db entry key due to the way the ports are constructed. I wonder if we can and should use a more compact format, such as
wasm.<hex of 16 byte hash>
which is 37 bytes longwasm.<account number>
(e.g.wasm.516737
) which is 11 bytes longwasm.<countract address counter>
(e.g.wasm.15165
) which remains slightly shorter than 2. assuming most accounts on a chain are not contracts.Option 1. would work and is pre-image resistent but not collision-resistant. This might become an issue if an attacker can freely brute force addresses which Instantiate2 makes possible. So I'd not do this as-is.
Option 2. is nice I think but assumes we always have that number from a different module available. This might be risky to assume as account numbers are made for signing and nothing else.
Option 3. is probably nice.
The problem wil all of the above is that a
ContractFromPortID
would require a lookup instead of just stripping off the prefix.The text was updated successfully, but these errors were encountered: