Skip to content

Fix constructor input decoding to preserve full ABI payload#954

Merged
kyonRay merged 6 commits into
release-3.9.0from
copilot/fix-corrupted-constructor-params
Jul 16, 2026
Merged

Fix constructor input decoding to preserve full ABI payload#954
kyonRay merged 6 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

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.06%. Comparing base (ab0390c) to head (f871b45).

Additional details and impacted files
@@               Coverage Diff                @@
##             release-3.9.0     #954   +/-   ##
================================================
  Coverage            64.05%   64.06%           
+ Complexity            4567     4566    -1     
================================================
  Files                  430      430           
  Lines                17628    17634    +6     
  Branches              1969     1969           
================================================
+ Hits                 11292    11297    +5     
  Misses                5576     5576           
- Partials               760      761    +1     
Flag Coverage Δ
unittest 64.06% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kyonRay

kyonRay commented Jul 16, 2026

Copy link
Copy Markdown
Member

Codecov Report

❌ Patch coverage is 28.57143% with 5 lines in your changes missing coverage. Please review. ✅ Project coverage is 64.04%. Comparing base (ab0390c) to head (30a2891).

Files with missing lines Patch % Lines
...ava/org/fisco/bcos/sdk/v3/codec/ContractCodec.java 28.57% 5 Missing ⚠️
Additional details and impacted files

@@                 Coverage Diff                 @@
##             release-3.9.0     #954      +/-   ##
===================================================
- Coverage            64.05%   64.04%   -0.02%     
  Complexity            4567     4567              
===================================================
  Files                  430      430              
  Lines                17628    17634       +6     
  Branches              1969     1969              
===================================================
+ Hits                 11292    11293       +1     
- Misses                5576     5581       +5     
  Partials               760      760              

Flag Coverage Δ
unittest 64.04% <28.57%> (-0.02%) ⬇️
Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness. 📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:

@copilot fix coverage

Copilot AI commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

[Codecov](https://app.codecov.io/gh/FISCO-BCOS/java-sdk/pull/954?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FISCO-B...

Added focused coverage for the constructor decode paths in commit f871b45.

  • Added testDecodeConstructorInputWithoutParams to cover the empty-params return path.
  • Added testDecodeConstructorInputWithInvalidPayload to cover the failure/exception path.

Also re-ran ABICodecTest and verifyGoogleJavaFormat successfully.

Copilot AI requested a review from kyonRay July 16, 2026 09:06
@kyonRay kyonRay merged commit 84ea6f8 into release-3.9.0 Jul 16, 2026
5 of 6 checks passed
@kyonRay kyonRay deleted the copilot/fix-corrupted-constructor-params branch July 16, 2026 09:30
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