Skip to content

Fix indexed event decoding for non-dynamic topic values#955

Open
Copilot wants to merge 4 commits into
release-3.9.0from
copilot/fix-contractcodec-decode-indexed-event
Open

Fix indexed event decoding for non-dynamic topic values#955
Copilot wants to merge 4 commits into
release-3.9.0from
copilot/fix-contractcodec-decode-indexed-event

Conversation

Copilot AI commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

ContractCodec.decodeIndexedEvent(log, abiDefinition) mishandled non-dynamic indexed event params such as address indexed and uint256 indexed. The by-interface event decode path could drop or fail on common event shapes because bare VALUE topics were routed through the JSON struct decoder.

  • Decoder path correction

    • Decode non-dynamic indexed VALUE params directly from the 32-byte topic payload via the existing ABI decode path.
    • Preserve the existing behavior for dynamic indexed params and non-value indexed objects.
  • Behavioral impact

    • Restores correct decoding for common indexed event signatures, including address, uintN, and other static value types.
    • Unblocks decodeEventByInterface(...) / decodeIndexedEvent(...) for standard transfer-style events.
  • Regression coverage

    • Add focused event-decoding coverage for an ABI with indexed address and indexed uint256.
    • Assert correctness across:
      • decodeIndexedEvent(...)
      • decodeEventByInterface(...)
      • decodeEventByInterfaceToString(...)

Example shape covered by the regression test:

event Transfer(address indexed from, uint256 indexed id, uint256 value);

Before this change, the indexed topics for from / id could fail in the by-interface decode path; after this change, they decode to their expected values.

Copilot AI and others added 2 commits March 4, 2026 13:34
* Initial plan

* Remove fisco-bcos.org URL, replace with GitHub repo URL in build.gradle

Co-authored-by: kyonRay <32325790+kyonRay@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: kyonRay <32325790+kyonRay@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix ContractCodec.decodeIndexedEvent for non-dynamic indexed params Fix indexed event decoding for non-dynamic topic values Jun 16, 2026
Copilot AI requested a review from kyonRay June 16, 2026 03:38
@kyonRay kyonRay marked this pull request as ready for review June 17, 2026 04:03
Copilot AI review requested due to automatic review settings June 17, 2026 04:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes decoding of non-dynamic indexed event parameters (e.g., address indexed, uint256 indexed) in ContractCodec.decodeIndexedEvent(...), ensuring the by-interface event decode APIs correctly return indexed values instead of dropping/failing on them.

Changes:

  • Decode non-dynamic indexed VALUE parameters directly from the 32-byte topic payload using the ABI decode path.
  • Add a regression test covering indexed address + indexed uint256 across decodeIndexedEvent(...), decodeEventByInterface(...), and decodeEventByInterfaceToString(...).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/main/java/org/fisco/bcos/sdk/v3/codec/ContractCodec.java Fixes decodeIndexedEvent to properly decode non-dynamic indexed VALUE params from topic bytes.
src/test/java/org/fisco/bcos/sdk/v3/test/codec/abi/ABIEventTest.java Adds a focused regression test for indexed address/uint256 event decoding across multiple decode entry points.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1043 to +1047
} else if (indexedObject.getType() == ABIObject.ObjectType.VALUE) {
ABIObject decodedIndexedObject =
ContractCodecTools.decode(
indexedObject, Hex.decode(log.getTopics().get(i)), isWasm);
topics.add(contractCodecJsonWrapper.decode(decodedIndexedObject).asText());
Comment on lines +3 to +7
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import org.fisco.bcos.sdk.v3.codec.abi.TypeEncoder;
import org.fisco.bcos.sdk.v3.codec.abi.tools.TopicTools;
Comment on lines +51 to +58
List<String> topics = new ArrayList<>();
topics.add(Numeric.toHexString(abiCodec.getFunctionEncoder().buildMethodId(eventSignature)));
TopicTools topicTools = new TopicTools(TestUtils.getCryptoSuite());
topics.add(topicTools.addressToTopic(from));
topics.add(topicTools.integerToTopic(id));

EventLog log = new EventLog(Numeric.toHexString(TypeEncoder.encode(new Uint256(value))), topics);
ABIDefinition abiDefinition = TestUtils.getContractABIDefinition(indexedAbi).getEvents().get("Transfer").get(0);
@kyonRay kyonRay changed the base branch from master to release-3.9.0 June 22, 2026 09:29
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants