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

feat: update solidity implementation to work with new packet commitment keys #101

Conversation

gjermundgaraba
Copy link
Contributor

Description

Still a couple of PRs left to be merged on the ibc-go side, so still using a separate branch for the simapp image, but that should be done with a simple change with #94.

It looks like no major changes in terms of gas cost, so didn't update the benchmarks this time around.

closes: #98


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Linked to GitHub issue with discussion and accepted design, OR link to spec that describes this work.
  • Wrote unit and integration tests.
  • Added relevant natspec and godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

Copy link

codecov bot commented Nov 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.62%. Comparing base (f78f4e6) to head (957ab0c).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #101      +/-   ##
==========================================
+ Coverage   98.59%   98.62%   +0.02%     
==========================================
  Files          12       12              
  Lines         357      364       +7     
  Branches       11       11              
==========================================
+ Hits          352      359       +7     
  Misses          5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -33,7 +32,7 @@ library ICS24Host {
pure
returns (bytes memory)
{
return abi.encodePacked("commitments/channels/", channelId, "/sequences/", Strings.toString(sequence));
return abi.encodePacked(channelId, uint8(1), uint64ToBigEndian(sequence));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does big endian make any difference in encode packed? If encodePacked is using little endian by default, could we ask ibc-go to use little endian instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can check if this would be fine with spec @AdityaSripal @sangier, but this is the current ibc-go implementation, so I suggest we do that change in a separate issue in that case.

Copy link
Member

@AdityaSripal AdityaSripal Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its better for it to be bigEndian since it allows us to reverseIterate in order. So ordered trees will have better iterators with this key format

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does anyone actually iterate these keys in reverse order? Asking because we might be more gas efficient if we don't do this in solidity, and simplifies the implementation.

/// @notice Convert a uint64 to big endian bytes representation
/// @param value The uint64 value
/// @return The big endian bytes representation
function uint64ToBigEndian(uint64 value) internal pure returns (bytes8) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanna understand better why we need this function and:

  1. If we can get rid of this by using little endian in ibc-go or some other change in ibc-go
  2. If we can find an external library that has this audited function. (Not super needed)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the reasoning I believe: cosmos/ibc-go#7132

  1. Lets ask speccers about it
  2. I have not been able to find a library that does this

Copy link
Member

@AdityaSripal AdityaSripal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commitment looks quite clean!

@@ -33,7 +32,7 @@ library ICS24Host {
pure
returns (bytes memory)
{
return abi.encodePacked("commitments/channels/", channelId, "/sequences/", Strings.toString(sequence));
return abi.encodePacked(channelId, uint8(1), uint64ToBigEndian(sequence));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does anyone actually iterate these keys in reverse order? Asking because we might be more gas efficient if we don't do this in solidity, and simplifies the implementation.

Copy link
Member

@srdtrk srdtrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm! Great work

@srdtrk srdtrk merged commit 2de017c into main Nov 18, 2024
17 checks passed
@srdtrk srdtrk deleted the gjermund/98-update-solidity-implementation-to-work-with-new-packet-commitment-keys branch November 18, 2024 04:09
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 this pull request may close these issues.

Update solidity implementation to work with new packet commitment keys
3 participants