Skip to content
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

ICS20 Inconsistencies with spec and improvements to code #65

Closed
8 of 16 tasks
ebuchman opened this issue Oct 29, 2020 · 2 comments · Fixed by #5791
Closed
8 of 16 tasks

ICS20 Inconsistencies with spec and improvements to code #65

ebuchman opened this issue Oct 29, 2020 · 2 comments · Fixed by #5791
Assignees

Comments

@ebuchman
Copy link
Member

ebuchman commented Oct 29, 2020

Surfaced from Informal Systems IBC Audit of cosmos-sdk hash 82f15f306e8a6a2e9ae3e122c348b579c43a3d92 and ics hash eb31a56467a48cd7eb4c2232705ad0fc632f9a19.

This is a working list of inconsistencies between the code and the spec of ICS20 that will continue to be updated. Most of these are issues with the spec, but there's a few places where the code could be improved.

  • Spec has a setup function which calls BindPort and ClaimCapability and should run once when module is created. But Code calls these functions during OnChainOpenInit and OnChanOpenTry instead.
  • Spec uses undefined newAddress() in onChanOpenInit and onChanOpenTry and stores it in a map under the channel id. Code uses a deterministic function of the portID and channelID, ie. newAddress(portID, channelID). With crossing-hellos we could have a safety problem according to this spec as we can execute onChanOpenInit (creates escrow address E1), then createOutgoingPacket using E1, then onChanOpenTry we creates a new escrow address E2 that replaces E1, so money is gone. It seems that at code level we don't have this problem as implementation does not follow spec, i.e., it generates escrow account based on portId/channelID. But if someone follows the spec, then we have safety problem.
  • OnChanCloseInit causes rollback in code (returns an error) but is NoOp in spec
  • Naming inconsistency: TransferCoins in the spec
    vs. SendCoins in the code
  • FungibleTokenPacketData: amount is uint256 in spec and uint64 in the code.
  • module binds to "transfer" port in the code, and to "bank" in the spec
  • In the spec onRecvPacket prefix should contain "/" at the end to be aligned with the code.
  • createOutgoingPacket spec has unused source argument
  • createOutgoingPacket spec is missing sequence number when constructing a Packet and calling sendPacket
  • Denom hashing and coin traces aren't mentioned in the spec but play an essential role - should at least link to ADR001
  • Code is missing explicit createOutgoingPacket function - either keeper.SendTransfer should be renamed to CreateOutgoingPacket or it should call such a function.
  • GetReceiveEnabled check in OnRecvPacket code is not found in spec. Is this really how IBC application functionality should be enabled/disabled by governance? Is there a more generic approach?
  • refundPacketToken spec does not return errors, but there are fallible operations in the code (ie. SendCoins and MintCoins). If we cannot 'mint vouchers back to sender' there is a problem. Either the code should clarify/assert that errors are not possible, or errors should be handled somehow more severely.
  • English text for Data Structures has the wording "and whether the sending chain is the source of the asset", which is missing both from the pseudo-code and from the implementation.

Additionally, some places where the code could be improved for maintainability:

  • In OnAcknowledgementPacket, the default branch of a switch statement is used for success logic. This is bit risky to maintain if additional error codes get added in the future (in the ICS it simply says if (!ack.success)). Rather, all error and success cases for the ack.Response should be handled explicitly and the default should be an error.
  • OnRecvPacket converts all errors equally into Acknowledgements. The ICS specifies that errors from Transfer and Mint should be converted to acknowledgements, but keeper.OnRecvPacket can also error in other ways, like on data.ValidateBasic, or if receiving is not enabled, or the receiver address is incorrectly decoded. Probably these last error types should be genuine errors (ie. cause rollbacks) or they should be captured in the spec.
@AdityaSripal
Copy link
Member

AdityaSripal commented Nov 6, 2020

Spec has a setup function which calls BindPort and ClaimCapability and should run once when module is created. But Code calls these functions during OnChainOpenInit and OnChanOpenTry instead.

This isn't true, BindPort does happen when module is initialized here, this will call BindPort on portKeeper and claim the resultant port capability: https://github.com/cosmos/cosmos-sdk/blob/master/x/ibc/applications/transfer/keeper/genesis.go#L20
The capability that is being claimed in OnChanOpenInit and OnChanOpenTry is the channel capability. This can be made more clear in code and docs.
Though the functionality of setUp is split up in code across app initialization logic and InitChain logic.

OnChanCloseInit causes rollback in code (returns an error) but is NoOp in spec

I believe spec should change right? cc: @cwgoes

module binds to "transfer" port in the code, and to "bank" in the spec

I believe spec should change. No need to add confusion between transfer module and bank module.

@cwgoes
Copy link
Contributor

cwgoes commented Nov 9, 2020

I believe spec should change right? cc: @cwgoes

Yes, this should change in the spec.

I believe spec should change. No need to add confusion between transfer module and bank module.

Aye, sure.

@colin-axner colin-axner transferred this issue from cosmos/cosmos-sdk Mar 5, 2021
@cwgoes cwgoes removed their assignment Sep 25, 2021
faddat referenced this issue in notional-labs/ibc-go Feb 23, 2022
Rest server allows proper wasm code download
faddat referenced this issue in notional-labs/ibc-go Mar 1, 2022
* Patch ci-chains.sh

* relayer config init

* Migrate message generation to PathEnd

* parallel query functions for connections, clientstates, channels, clientconsstates

* migrate handshakes to use concurrent queries

* add query balance command

* add debug logging for all transactions

* fix validateConfig function signature

* Update logging

* better errors

* Add raw xfer command to dev-chains.sh

* More accurate logging

* Panic on nil proof

* Tweak some heights

* More offsets

* Fix several off-by-one errors

* Add time.Sleep for now

* Change created port to transfer

* Speed up and add more stringent checks to ci-chains

* kick ci

* change caching

* Change denom

* Flip boolean

* Fix commit

* Update go.sum

* xfer modification

* modify xfer command

* switch source in the xfer command

* args right and dev-chains.sh update

* push tx query

* Fix other direction

* Transfer n0token, not stake

* Fix the account receiver

* Update dev-chains

* fix embarassing misspelling

* Fix identifiers

* Fix denom

* WORKING

* query until proo isn't nil

* update naming

* Path name arg to flag in most commands

* last little bit of cleanup

Co-authored-by: Jack Zampolin <[email protected]>
faddat referenced this issue in notional-labs/ibc-go Mar 1, 2022
Add relay-alpha config for chain-id 'dos-ibc'
CosmosCar pushed a commit to caelus-labs/ibc-go that referenced this issue Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants