Skip to content

fix: use eth_abi to decode governance response in GovernanceEthereum#2591

Open
Wanbogang wants to merge 1 commit into
OpenMind:mainfrom
Wanbogang:fix/ethereum-governance-web3
Open

fix: use eth_abi to decode governance response in GovernanceEthereum#2591
Wanbogang wants to merge 1 commit into
OpenMind:mainfrom
Wanbogang:fix/ethereum-governance-web3

Conversation

@Wanbogang

Copy link
Copy Markdown
Contributor

Summary

Fixes the fragile manual ABI decoding in GovernanceEthereum.decode_eth_response (issue #1824).

Problem

The old decode_eth_response parsed 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 existing web3==7.6.0 dependency, so no new dependency is added). This decodes the ABI-encoded response correctly regardless of offset.

Scope (intentionally minimal)

  • Only one source file changed (src/inputs/plugins/ethereum_governance.py): the import and the body of decode_eth_response.
  • No test files touched — the existing 16 tests in tests/inputs/plugins/test_ethereum_governance.py all pass unchanged.
  • No public API change, async flow untouched, no behavior change for valid responses (verified by round-trip encode/decode).

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).

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
@Wanbogang Wanbogang requested review from a team as code owners June 1, 2026 15:13
@github-actions github-actions Bot added robotics Robotics code changes python Python code labels Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Python code robotics Robotics code changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant