Skip to content

fix(core): correctly encode dynamic constructor params on contract deploy - #223

Merged
kuny0707 merged 1 commit into
tronprotocol:release_1.0.0from
0xbigapple:fix/constructor-dynamic-param-abi-encoding
Aug 6, 2026
Merged

fix(core): correctly encode dynamic constructor params on contract deploy#223
kuny0707 merged 1 commit into
tronprotocol:release_1.0.0from
0xbigapple:fix/constructor-dynamic-param-abi-encoding

Conversation

@0xbigapple

Copy link
Copy Markdown
Collaborator

What does this PR do?

Utils.encodeParameter and ContractConstructor.encodeParameter now delegate to
FunctionEncoder.encodeConstructor — the canonical head/tail tuple encoder already used
for function-call encoding — instead of concatenating per-parameter TypeEncoder.encode()
output. Dynamic-type parameters (string / bytes / array) now carry their offset
pointer in the ABI tuple head.

Why are these changes required?

This PR has been tested by:
ConstructorDynamicParamDeployTest (added, @Disabled by default — requires a funded Nile
private key in application-test.properties) deploys a constructor(string) contract
through ApiWrapper.deployContract, asserts the deploy succeeds, then reads the stored
value back with a constant name() call.

Extra details

… head

Utils.encodeParameter and ContractConstructor.encodeParameter concatenated
per-parameter TypeEncoder.encode() output, which omits the offset pointer that
dynamic types (string/bytes/array) require in the ABI tuple head. Deploying a
contract whose constructor takes any dynamic parameter (e.g. a TRC20-style
constructor with string name/symbol) produced malformed calldata that reverted
on-chain. Static-only parameters encoded correctly and were unaffected.

Both methods now delegate to FunctionEncoder.encodeConstructor, the canonical
head/tail tuple encoder already used for function-call encoding, so the two
deploy paths (ApiWrapper.deployContract, Contract.createSmartContract) are fixed
without changing their call sites.

Add a Nile on-chain integration test (disabled by default) that deploys a
contract with a dynamic string constructor parameter and reads the stored value
back.
@0xbigapple
0xbigapple requested a review from 317787106 August 5, 2026 13:21
@kuny0707
kuny0707 merged commit 9de85d9 into tronprotocol:release_1.0.0 Aug 6, 2026
3 checks passed
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