-
Notifications
You must be signed in to change notification settings - Fork 3
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: use abi encoding of ICS20Transfer payload #117
base: main
Are you sure you want to change the base?
feat: use abi encoding of ICS20Transfer payload #117
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #117 +/- ##
==========================================
- Coverage 94.10% 93.89% -0.21%
==========================================
Files 9 9
Lines 339 311 -28
==========================================
- Hits 319 292 -27
+ Misses 20 19 -1 ☔ View full report in Codecov by Sentry. |
@@ -0,0 +1,42 @@ | |||
module github.com/cosmos/solidity-ibc-eureka/abigen | |||
|
|||
go 1.22.7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the setup as the e2e tests. But maybe we should just fully update it to go 1.23 soon...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to open a deps(e2e)
pr anytime, and I'll approve fast :)
Repository: "ghcr.io/cosmos/ibc-go-wasm-simd", // FOR LOCAL IMAGE USE: Docker Image Name | ||
Version: "feat-ibc-eureka", // FOR LOCAL IMAGE USE: Docker Image Tag | ||
Repository: "ghcr.io/cosmos/ibc-go-wasm-simd", // FOR LOCAL IMAGE USE: Docker Image Name | ||
Version: "gjermund-7591-ics20-abi-encoding", // FOR LOCAL IMAGE USE: Docker Image Tag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one can only be updated once cosmos/ibc-go#7592 is merged. We could wait, but I'd rather just update this in a PR so we're not blocked on ibc-go reviewing which might take time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, should it be merged soon ahead of the security audit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I would think so.
@@ -39,12 +44,14 @@ generate-abi: | |||
jq '.abi' out/ERC20.sol/ERC20.json > abi/ERC20.json | |||
jq '.abi' out/IBCERC20.sol/IBCERC20.json > abi/IBCERC20.json | |||
jq '.abi' out/IBCStore.sol/IBCStore.json > abi/IBCStore.json | |||
abigen --abi abi/ICS02Client.json --pkg ics02client --type Contract --out e2e/interchaintestv8/types/ics02client/contract.go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly just different ordering to have some level of separation between types generated for e2e tests only and the ones that should be public in abigen/
.
That, and adding ICS20Lib.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also remove the files from types
that have been moved to abigen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was done already
A quick comment on the test coverage. I believe it went down a little bit because some of the old parsing logic was well tested... I looked over the main parts of the ICS20Lib that has some branches that are not unit tested right now, and it does not seem worth spending time on them, as they will all be replaced by new functions from OpenZeppelin in their next release (which should be early next year it looks like). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm. I left a couple comments
README.md
Outdated
| `multicall/recvPacket` | Receiving _back_ an `ERC20` token. | ~228,000 | ~220,000 | | ||
| `multicall/ackPacket` | Acknowledging an ICS20 packet. | ~141,000 | ~135,000 | | ||
| `multicall/recvPacket` | Receiving _back_ an `ERC20` token. | ~208,000 | ~201,000 | | ||
| `multicall/ackPacket` | Acknowledging an ICS20 packet. | ~121,000 | ~115,000 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
@@ -0,0 +1,42 @@ | |||
module github.com/cosmos/solidity-ibc-eureka/abigen | |||
|
|||
go 1.22.7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to open a deps(e2e)
pr anytime, and I'll approve fast :)
Repository: "ghcr.io/cosmos/ibc-go-wasm-simd", // FOR LOCAL IMAGE USE: Docker Image Name | ||
Version: "feat-ibc-eureka", // FOR LOCAL IMAGE USE: Docker Image Tag | ||
Repository: "ghcr.io/cosmos/ibc-go-wasm-simd", // FOR LOCAL IMAGE USE: Docker Image Name | ||
Version: "gjermund-7591-ics20-abi-encoding", // FOR LOCAL IMAGE USE: Docker Image Tag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, should it be merged soon ahead of the security audit?
src/utils/ICS20Lib.sol
Outdated
/** | ||
* @notice Encodes a `FungibleTokenPacketData` struct into ABI-encoded bytes. | ||
* | ||
* @dev This function uses `abi.encode` to convert a `FungibleTokenPacketData` struct into its ABI-encoded | ||
* `bytes` representation. The resulting bytes can be transmitted or stored for decoding later. | ||
* | ||
* @param payload The `FungibleTokenPacketData` struct to encode. | ||
* @return Encoded `bytes` representation of the input struct. | ||
* | ||
* @dev What this function does: | ||
* - Converts the `FungibleTokenPacketData` struct into a `bytes` array using ABI encoding. | ||
* - Ensures the resulting bytes are compatible with `abi.decode` for the same struct. | ||
* - Preserves the field order and data structure of the input struct during encoding. | ||
* | ||
* @dev What this function does NOT do: | ||
* - It does not validate the content of the `FungibleTokenPacketData` struct before encoding. | ||
* For example: | ||
* - Does not check if `amount` is greater than 0. | ||
* - Does not verify that `receiver` or `sender` are valid addresses or non-empty strings. | ||
* - Does not validate the format or expected content of `denom` or `memo`. | ||
* - It does not ensure compatibility with external systems unless they adhere to the same ABI encoding rules. | ||
* | ||
* @dev Recommended validation to avoid issues: | ||
* - Validate the fields of the `FungibleTokenPacketData` struct before calling this function: | ||
* - Ensure `amount > 0`. | ||
* - Check that `receiver` and `sender` are non-empty and, if required, valid address strings. | ||
* - Validate `denom` against expected formats or whitelisted values, if applicable. | ||
* - Optionally validate `memo` for length or allowed characters. | ||
* - Ensure that the consumer of the encoded bytes uses the same ABI decoding standard. | ||
*/ | ||
function encodePayload(FungibleTokenPacketData memory payload) internal pure returns (bytes memory) { | ||
return abi.encode(payload); | ||
} | ||
|
||
/** | ||
* @notice Decodes ABI-encoded bytes into a `FungibleTokenPacketData` struct. | ||
* | ||
* @dev This function uses `abi.decode` to decode a `bytes` payload into a `FungibleTokenPacketData` struct. | ||
* It assumes that the input data is correctly ABI-encoded and matches the structure of `FungibleTokenPacketData`. | ||
* | ||
* @param data ABI-encoded bytes representing a `FungibleTokenPacketData`. | ||
* @return Decoded `FungibleTokenPacketData` struct. | ||
* | ||
* @dev What this function does: | ||
* - Decodes the `bytes` payload into the expected `FungibleTokenPacketData` struct. | ||
* - Ensures that the payload conforms to the ABI encoding of `FungibleTokenPacketData` (field types and order). | ||
* - Reverts if the input data is not properly ABI-encoded. | ||
* | ||
* @dev What this function does NOT do: | ||
* - Validate the logical correctness or semantic meaning of the decoded fields. | ||
* For example: | ||
* - Does not check if `amount` is greater than 0. | ||
* - Does not verify that `receiver` or `sender` are valid addresses or non-empty strings. | ||
* - Does not validate the format, length, or expected content of `denom` or `memo`. | ||
* - Does not validate whether the payload matches a specific JSON schema or key order. | ||
* | ||
* @dev Recommended validation to avoid exploits: | ||
* - After decoding, validate each field of the struct: | ||
* - Ensure `amount > 0`. | ||
* - Check that `receiver` and `sender` are non-empty and, if required, valid address strings. | ||
* - Validate `denom` against expected formats or whitelisted values, if applicable. | ||
* - Optionally validate `memo` for length or allowed characters. | ||
* - Implement JSON key-order validation if strict ordering is required. | ||
* - Consider using a try/catch block for decoding, or handle decoding errors explicitly to ensure | ||
* the function does not fail silently or revert without providing clear error messages. | ||
*/ | ||
function decodePayload(bytes memory data) external pure returns (FungibleTokenPacketData memory) { | ||
return abi.decode(data, (FungibleTokenPacketData)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need these functions given that they don't perform any validation. I also don't support making these functions external to be used in e2e tests. We should keep the number of external functions as small as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is fair actually. I'll remove them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this actually saved us some gas, so updated the benchmarks again :)
@@ -39,12 +44,14 @@ generate-abi: | |||
jq '.abi' out/ERC20.sol/ERC20.json > abi/ERC20.json | |||
jq '.abi' out/IBCERC20.sol/IBCERC20.json > abi/IBCERC20.json | |||
jq '.abi' out/IBCStore.sol/IBCStore.json > abi/IBCStore.json | |||
abigen --abi abi/ICS02Client.json --pkg ics02client --type Contract --out e2e/interchaintestv8/types/ics02client/contract.go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also remove the files from types
that have been moved to abigen.
Description
closes: #116
Based off of the work done in: #102
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.
godoc
comments.Files changed
in the GitHub PR explorer.SonarCloud Report
in the comment section below once CI passes.