Skip to content

Fix constructor input decoding to preserve full ABI payload#954

Open
Copilot wants to merge 4 commits into
release-3.9.0from
copilot/fix-corrupted-constructor-params
Open

Fix constructor input decoding to preserve full ABI payload#954
Copilot wants to merge 4 commits into
release-3.9.0from
copilot/fix-corrupted-constructor-params

Conversation

Copilot AI commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

ContractCodec.decodeConstructorInput(abi, bin, input) was decoding constructor args through the method-input path, which incorrectly drops the first 4 bytes as if a function selector were present. Constructor calldata has no selector after the bytecode, so the first parameter was truncated and decoded incorrectly.

  • Constructor decode path

    • Route decodeConstructorInput(...) through direct ABI payload decoding instead of decodeMethodAndGetInputObject(...).
    • This aligns the object-returning path with decodeConstructorInputToString(...), which already decodes the full constructor parameter bytes.
  • Regression coverage

    • Add a focused constructor round-trip test with actual parameters (uint256, string).
    • Verify decodeConstructorInput(...) now returns the same values represented by the already-correct string decode path.
  • Behavioral impact

    • Method input decoding remains unchanged.
    • Constructor decoding now preserves the full encoded parameter payload instead of stripping a non-existent selector.
public List<Object> decodeConstructorInput(String abi, String bin, String input)
        throws ContractCodecException {
    String paramsInput = StringUtils.substringAfter(input, bin);
    if (paramsInput.isEmpty()) {
        return new ArrayList<>();
    }

    ContractABIDefinition contractABIDefinition = this.abiDefinitionFactory.loadABI(abi);
    ABIDefinition abiDefinition = contractABIDefinition.getConstructor();
    ABIObject inputObject = ABIObjectFactory.createInputObject(abiDefinition);
    return ContractCodecTools.decodeJavaObject(inputObject, paramsInput, isWasm);
}

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.decodeConstructorInput to avoid stripping bytes Fix constructor input decoding to preserve full ABI payload Jun 16, 2026
Copilot AI requested a review from kyonRay June 16, 2026 03:37
@kyonRay kyonRay marked this pull request as ready for review June 17, 2026 04:02
Copilot AI review requested due to automatic review settings June 17, 2026 04:02

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

Fixes ContractCodec.decodeConstructorInput(...) to decode constructor calldata correctly by decoding the full ABI-encoded parameter payload (constructor input has no 4-byte selector to strip), aligning behavior with decodeConstructorInputToString(...).

Changes:

  • Route decodeConstructorInput(...) through direct ABI payload decoding (instead of method-input decoding that strips 4 bytes).
  • Add a regression test that round-trips constructor params (uint256, string) and asserts object/string decode consistency.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/main/java/org/fisco/bcos/sdk/v3/codec/ContractCodec.java Updates constructor input decoding to avoid dropping the first 4 bytes and decode full parameter payload.
src/test/java/org/fisco/bcos/sdk/v3/test/codec/ABICodecTest.java Adds a focused constructor decode test with parameters to prevent regressions.

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

Comment on lines +684 to +691
try {
return ContractCodecTools.decodeJavaObject(inputObject, paramsInput, isWasm);
} catch (Exception e) {
logger.error(" exception in decodeConstructorInput : {}", e.getMessage());
}
String errorMsg = " cannot decode in decodeConstructorInput with appropriate interface ABI";
logger.error(errorMsg);
throw new ContractCodecException(errorMsg);
@kyonRay kyonRay changed the base branch from master to release-3.9.0 June 22, 2026 09:28
@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