-
Notifications
You must be signed in to change notification settings - Fork 40
fix: align address decoding with Solidity canonical behavior #803
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
fix: align address decoding with Solidity canonical behavior #803
Conversation
pdp/contract/utils_test.go
Outdated
| t.Errorf("Case 2 failed: Expected %x, got %x", input2, decoded2.Bytes()) | ||
| } | ||
|
|
||
| // Case 3: Input longer than 20 bytes → use last 20 bytes only |
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.
don't enumerate comments
pdp/contract/utils.go
Outdated
| func DecodeAddressCanonical(input []byte) common.Address { | ||
| b := make([]byte, 20) | ||
| inLen := len(input) | ||
| if inLen >= 20 { |
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.
|
@wjmelements done with the changes |
pdp/contract/utils.go
Outdated
| // DecodeAddressCapability implements the Solidity behavior of | ||
| // address(uint160(BigEndian.decode(input))). | ||
| func DecodeAddressCapability(input []byte) common.Address { | ||
| // If input is longer, we must take the *head* of the slice first. |
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.
wrong #758 (comment)
pdp/contract/utils_test.go
Outdated
| t.Errorf("Case 2 (exact) failed: Expected %s, got %s", expected2.Hex(), decoded2.Hex()) | ||
| } | ||
|
|
||
| // Case 3: Input > 20 bytes but <= 32 bytes → use last 20 bytes |
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.
pdp/contract/utils_test.go
Outdated
| t.Errorf("Case 3 (medium) failed: Expected %s, got %s", expected2.Hex(), decoded3.Hex()) | ||
| } | ||
|
|
||
| // Case 4: Input > 32 bytes → take first 32, then last 20 from that |
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.
pdp/contract/utils_test.go
Outdated
| t.Errorf("Case 1 (short) failed: Expected %s, got %s", expected1.Hex(), decoded1.Hex()) | ||
| } | ||
|
|
||
| // Case 2: Exactly 20 bytes input → use as is |
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.
pdp/contract/utils_test.go
Outdated
|
|
||
| // TestDecodeAddressCapability tests the canonical address decoding. | ||
| func TestDecodeAddressCapability(t *testing.T) { | ||
| // Case 1: Input shorter than 20 bytes → left pad with zeros |
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.
pdp/contract/utils_test.go
Outdated
| // These 8 bytes should be IGNORED (they are after byte 32) | ||
| 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, | ||
| } | ||
| // The expected result is the last 20 bytes *of the first 32 bytes* |
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.
wrong
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.
Please consult the test cases I provided for you
#758 (comment)
pdp/contract/utils_test.go
Outdated
| t.Errorf("Case 1 (short) failed: Expected %s, got %s", expected1.Hex(), decoded1.Hex()) | ||
| } | ||
|
|
||
| // Case 2: Exactly 20 bytes input → use as is |
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.
just make these into separate test cases instead of cramming them into the same test case
|
@wjmelements done with the changes |
wjmelements
left a comment
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.
Kindly read the instructions more carefully. If you have been using AI, please stop.
pdp/contract/utils_test.go
Outdated
| 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, | ||
| } | ||
|
|
||
| // The expected result is the last 20 bytes *of the first 32 bytes*, which is expectedAddr |
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.
|
@wjmelements I’ve pushed the updated changes now. Just to clarify — I did not use any AI for this. I was a bit confused earlier, so I took some extra time to understand the instructions properly. Everything in this update is written and reviewed by me. Please let me know if any further adjustments are needed. |
|
@wjmelements done with the changes |
Description
This PR fixes inconsistent decoding of Ethereum addresses from byte slices in the ServiceProviderRegistry and related code, addressing issue #758.
DecodeAddressCanonicalfunction matching Solidity'saddress(uint160(BigEndian.decode(bytes))).Issue
Fixes #758
Please review the decoding logic and scope of changes. Happy to include tests or make adjustments as needed.