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

Add PacketV2 Protos and CommitmentV2 function #7287

Merged
merged 4 commits into from
Sep 16, 2024

Conversation

chatton
Copy link
Contributor

@chatton chatton commented Sep 12, 2024

Description

This PR adds the PacketV2 protos which we will use internally to convert a PacketV1 to a PacketV2 and commit based on the protocol version field.

I think the final hashing function and structure is not 100% set in stone yet, and might still change based on how the implementation goes.

closes: #XXXX


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.

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to GitHub issue with discussion and accepted design, OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

@chatton chatton marked this pull request as ready for review September 12, 2024 10:21
// identifies the receiving chain.
string destination_id = 3;
// timeout after which the packet times out
string timeout = 4;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not convinced this is the best idea, @damiannolan also pointed out that string parsing is expensive in an EVM environment.

Is there a good reason not to just use uint64 nanos only?

cc @AdityaSripal

Copy link
Member

Choose a reason for hiding this comment

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

I also agree that we should just have uint64

@@ -26,6 +26,7 @@ func CommitPacket(packet Packet) []byte {
case IBC_VERSION_UNSPECIFIED, IBC_VERSION_1:
return commitV1Packet(packet)
case IBC_VERSION_2:
// TODO: convert to PacketV2 and commit.
Copy link
Contributor

Choose a reason for hiding this comment

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

do we have an issue? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

don't think so, this'll just be handled as part of PacketV2 internal logic refactor. Can create an issue for this specifically if you think it's worth it!

// This results in a fixed length preimage.
// NOTE: A fixed length preimage is ESSENTIAL to prevent relayers from being able
// to malleate the packet fields and create a commitment hash that matches the original packet.
func CommitPacketV2(packet PacketV2) []byte {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can also be private no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this'll end up being used in the packet-server package when acting on PacketV2 types and so will be public.

// specifies the destination port of the packet.
string destination_port = 2;
// the payload to be sent to the application.
Payload payload = 3;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this will ever be nullable no?

Copy link

sonarcloud bot commented Sep 12, 2024

Copy link
Contributor

@bznein bznein left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks, @chatton!

@@ -100,6 +101,42 @@ func commitV2Packet(packet Packet) []byte {
return hash[:]
}

// CommitPacketV2 returns the V2 packet commitment bytes. The commitment consists of:
// sha256_hash(timeout) + sha256_hash(destinationID) + sha256_hash(packetData) from a given packet.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// sha256_hash(timeout) + sha256_hash(destinationID) + sha256_hash(packetData) from a given packet.
// sha256_hash(timeout) + sha256_hash(destinationID) + sha256_hash(packetData) for a given packet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry missed this comment, will include this in a follow up!

@@ -26,6 +26,7 @@ func CommitPacket(packet Packet) []byte {
case IBC_VERSION_UNSPECIFIED, IBC_VERSION_1:
return commitV1Packet(packet)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be of course done in a separate PR, but probably we can rename this to commitPacketV1?

@chatton chatton merged commit b52a438 into feat/ibc-eureka Sep 16, 2024
65 checks passed
@chatton chatton deleted the cian/add-packet-v2-protos branch September 16, 2024 07:43
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.

5 participants