-
Notifications
You must be signed in to change notification settings - Fork 719
Changed hashing schema implementation to match provider-NIT-4724 #4586
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| ### Changed | ||
| - Change hashing algorithm for address filtering feature to match the provider specs. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ import ( | |
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/google/uuid" | ||
|
|
||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/ethereum/go-ethereum/log" | ||
|
|
||
|
|
@@ -67,11 +69,11 @@ func (s *S3SyncManager) handleHashListData(data []byte, digest string) error { | |
| } | ||
|
|
||
| // parseHashListJSON parses the JSON hash list file. | ||
| // Expected format: {"salt": "hex...", "address_hashes": [{"hash": "hex1"}, {"hash": "hex2"}, ...]} | ||
| func parseHashListJSON(data []byte) ([]byte, []common.Hash, error) { | ||
| // Expected format: {"salt": "uuid-string-representation", "address_hashes": [{"hash": "hex1"}, {"hash": "hex2"}, ...]} | ||
| func parseHashListJSON(data []byte) (uuid.UUID, []common.Hash, error) { | ||
| var payload hashListPayload | ||
| if err := json.Unmarshal(data, &payload); err != nil { | ||
| return nil, nil, fmt.Errorf("JSON unmarshal failed: %w", err) | ||
| return uuid.Nil, nil, fmt.Errorf("JSON unmarshal failed: %w", err) | ||
| } | ||
|
|
||
| // Validate hashing scheme - warn if not Sha256 but continue for forward compatibility | ||
|
|
@@ -80,25 +82,21 @@ func parseHashListJSON(data []byte) ([]byte, []common.Hash, error) { | |
| "scheme", payload.HashingScheme) | ||
| } | ||
|
|
||
| salt, err := hex.DecodeString(trimHexPrefix(payload.Salt)) | ||
| salt, err := uuid.Parse(payload.Salt) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need to enforce that Salt is an uuid here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is no detailed actual spec. we have only code example of the hashing. But from the example and from speaking with them. the address is in form of '0x....' with 20bytes but used with delimiter in a string version. and Salt is UUID using with delimiter too in string version. This implementation is better to catch any deviation and has strong validation that we get the data in right format. we part the 20byte addresses. we parse the 32Byte hashes, we parse the UUID and when do the hashing we use string::string format. In future, the only change we spoke about that they will do is moving everything to binary bytes for hashing.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specification only says that salt is a string.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mahdy-nasr confirmed, with the salt provider, that despite the document that we have access not mentioning this, the salt will be a uuid. |
||
| if err != nil { | ||
| return nil, nil, fmt.Errorf("invalid salt hex: %w", err) | ||
| } | ||
| if len(salt) == 0 { | ||
| return nil, nil, fmt.Errorf("salt cannot be empty") | ||
| return uuid.Nil, nil, err | ||
| } | ||
|
|
||
| hashes := make([]common.Hash, len(payload.AddressHashes)) | ||
| for i, h := range payload.AddressHashes { | ||
| hashBytes, err := hex.DecodeString(trimHexPrefix(h.Hash)) | ||
| if err != nil { | ||
| return nil, nil, fmt.Errorf("invalid hash hex at index %d: %w", i, err) | ||
| return uuid.Nil, nil, fmt.Errorf("invalid hash hex at index %d: %w", i, err) | ||
| } | ||
| if len(hashBytes) != 32 { | ||
| return nil, nil, fmt.Errorf("invalid hash length at index %d: got %d, want 32", i, len(hashBytes)) | ||
| return uuid.Nil, nil, fmt.Errorf("invalid hash length at index %d: got %d, want 32", i, len(hashBytes)) | ||
| } | ||
| copy(hashes[i][:], hashBytes) | ||
| } | ||
|
|
||
| return salt, hashes, nil | ||
| } | ||
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.
add to hashData a string that's just salt.String() + "::0x" so we don't recompute it for every computed hash. It could either be instead of the stored salt or in addition to it