forked from tronprotocol/trident
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(abi): support abiV2 include static/dynamics arrays, struct #5
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
Closed
Closed
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
4b6b23a
feat(abi): support abiV2 include static/dynamics arrays, struct
0xbigapple 0b1c8e0
fix(abi): revert encode/buildEventSignature and add new function en…
0xbigapple a96b254
fix(abi): fix utf8String bytes32PaddedLength, fix Non-ASCII Charact…
0xbigapple 83d18d3
fix: add offset pointers for DynamicArray containing dynamic StaticAr…
0xbigapple 4a9bc2c
refactor(abi): unify static struct slot counting via bytes32PaddedLength
0xbigapple 6951d9a
feat(abi): support StaticArray fields including dynamic-element variants
0xbigapple acfc4fd
fix(abi): throw explicit error when decoding empty array of generic s…
0xbigapple 91ba349
test(abi): add ABI encode/decode compatibility tests with fixture data
0xbigapple b512792
security(abi): validate TypeReference depth at decoder entry
0xbigapple cfa0fee
security(abi): validate TypeReference depth at decoder entry
0xbigapple d2e4050
security(abi): centralize reflective type loading via safeLoadTypeCla…
0xbigapple 8505480
fix(abi): fix reviewer feedback
0xbigapple 7179b20
test(abi): clean up lint warnings in ABI test code
0xbigapple 761cba2
docs(abi): add @deprecated Javadoc for legacy array constructors; sim…
0xbigapple 11fc7ba
fix(abi): harden TypeDecoder edge cases in decoding paths
0xbigapple 00cf825
fix(abi): repair struct constructor-reflection decoding in place
0xbigapple 6fa1b4a
fix(abi): decode static arrays of dynamic elements on constructor-ref…
0xbigapple fd54a0f
fix(abi): serialize innerTypes tuples in signatures; reject unsupport…
0xbigapple 93ef68d
fix(abi): harden encode/decode paths per ABI review
0xbigapple 5833369
docs(abi): document pitfalls deliberately kept as-is
0xbigapple 034b6e2
refactor(abi): consolidate decoder and array-type helper logic
0xbigapple 13cabee
fix(abi): align Utf8String.bytes32PaddedLength with web3j length-word…
0xbigapple 3918043
fix(abi): propagate ClassNotFoundException from isDynamic(TypeReferen…
0xbigapple a257c8a
fix(abi): harden signature building, packed gate, and TVM type semantics
0xbigapple 4c2475e
Merge branch 'release_1.0.0' into feature/support-dynamics-abi
0xbigapple 83843c5
test(abi): aggregate compatibility tests to quiet passing output; fix…
0xbigapple File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
abi/src/main/java/org/tron/trident/abi/CustomErrorEncoder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package org.tron.trident.abi; | ||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import org.tron.trident.abi.datatypes.CustomError; | ||
| import org.tron.trident.abi.datatypes.Type; | ||
| import org.tron.trident.crypto.Hash; | ||
| import org.tron.trident.utils.Numeric; | ||
|
|
||
| /** | ||
| * Ethereum custom error encoding. Further limited details are available <a | ||
| * href="https://docs.soliditylang.org/en/develop/abi-spec.html#errors">here</a>. | ||
| */ | ||
| public class CustomErrorEncoder { | ||
|
|
||
| private CustomErrorEncoder() { | ||
| } | ||
|
|
||
| public static String encode(CustomError error) { | ||
| return calculateSignatureHash( | ||
| buildErrorSignature(error.getName(), error.getParameters())); | ||
| } | ||
|
|
||
| static <T extends Type> String buildErrorSignature( | ||
| String errorName, List<TypeReference<T>> parameters) { | ||
|
|
||
| StringBuilder result = new StringBuilder(); | ||
| result.append(errorName); | ||
| result.append("("); | ||
| String params = | ||
| parameters.stream().map(Utils::getTypeName).collect(Collectors.joining(",")); | ||
| result.append(params); | ||
| result.append(")"); | ||
| return result.toString(); | ||
| } | ||
|
|
||
| public static String calculateSignatureHash(String errorSignature) { | ||
| byte[] input = errorSignature.getBytes(StandardCharsets.UTF_8); | ||
| byte[] hash = Hash.sha3(input); | ||
| return Numeric.toHexString(hash).substring(2); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
P1: Custom error selectors should be the first 4 bytes of the hash, not the full 32-byte digest.
Prompt for AI agents