fix: use eth_abi to decode governance response in GovernanceEthereum#2591
Open
Wanbogang wants to merge 1 commit into
Open
fix: use eth_abi to decode governance response in GovernanceEthereum#2591Wanbogang wants to merge 1 commit into
Wanbogang wants to merge 1 commit into
Conversation
The manual hex parsing in decode_eth_response assumed a fixed ABI layout (reading the string length from a hard-coded offset), which could silently return wrong data if the response layout shifted. Replace it with eth_abi.decode(['string'], ...) from web3, which parses the ABI-encoded response correctly regardless of offset. No public API change; existing tests pass unchanged. Addresses OpenMind#1824
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes the fragile manual ABI decoding in
GovernanceEthereum.decode_eth_response(issue #1824).Problem
The old
decode_eth_responseparsed the eth_call result by hand, reading the string length from a hard-coded byte offset (response_bytes[96:128]) and slicing from a fixed position. This assumes a specific ABI layout — if the response layout shifts, it silently returns wrong data rather than failing loudly.Fix
Replace the manual parsing with
eth_abi.decode(["string"], ...)(eth_abi ships with the existingweb3==7.6.0dependency, so no new dependency is added). This decodes the ABI-encoded response correctly regardless of offset.Scope (intentionally minimal)
src/inputs/plugins/ethereum_governance.py): the import and the body ofdecode_eth_response.tests/inputs/plugins/test_ethereum_governance.pyall pass unchanged.This is a much smaller, more focused version of my earlier attempt (#2069), which got stuck on test-file structure. This time the test files are left exactly as-is.
All checks pass locally: ruff, ruff format, typos, and pytest (16 passed).