From 1bd928750958586c76a6a1812a3931f9d2448c88 Mon Sep 17 00:00:00 2001 From: Dickson Date: Tue, 1 Sep 2026 02:04:43 +0000 Subject: [PATCH] fix(cheatcodes): preserve non-empty zero bytecode --- src/kontrol/kdist/cheatcodes.md | 2 +- src/tests/integration/test-data/foundry-prove-all | 1 + .../foundry/test/AccountParamsTest.t.sol | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/kontrol/kdist/cheatcodes.md b/src/kontrol/kdist/cheatcodes.md index dfbc0f190..c9f66578d 100644 --- a/src/kontrol/kdist/cheatcodes.md +++ b/src/kontrol/kdist/cheatcodes.md @@ -1392,7 +1392,7 @@ We don't care about the values because they will be processed in the `custom_ste rule #setCode ACCTID CODE => .K ... ACCTID - _ => #if #asWord(CODE) ==Int 0 #then .Bytes #else CODE #fi + _ => #if lengthBytes(CODE) ==Int 0 #then .Bytes #else CODE #fi ... ``` diff --git a/src/tests/integration/test-data/foundry-prove-all b/src/tests/integration/test-data/foundry-prove-all index c37ddfc25..d845183be 100644 --- a/src/tests/integration/test-data/foundry-prove-all +++ b/src/tests/integration/test-data/foundry-prove-all @@ -1,6 +1,7 @@ AccountParamsTest.testDealConcrete() AccountParamsTest.testDealSymbolic(uint256) AccountParamsTest.testEtchConcrete() +AccountParamsTest.testEtchEmptyAndZero() AccountParamsTest.testEtchSymbolic(bytes) AccountParamsTest.testFail_GetNonce_false() AccountParamsTest.testFail_GetNonce_true() diff --git a/src/tests/integration/test-data/foundry/test/AccountParamsTest.t.sol b/src/tests/integration/test-data/foundry/test/AccountParamsTest.t.sol index 1f1a39931..f8af49be8 100644 --- a/src/tests/integration/test-data/foundry/test/AccountParamsTest.t.sol +++ b/src/tests/integration/test-data/foundry/test/AccountParamsTest.t.sol @@ -21,6 +21,21 @@ contract AccountParamsTest is Test { assertEq(address(124).code, code); } + function testEtchEmptyAndZero() public { + address emptyAddress = address(124); + address zeroAddress = address(125); + bytes memory emptyCode = bytes(""); + bytes memory zeroCode = hex"00"; + + vm.etch(emptyAddress, emptyCode); + vm.etch(zeroAddress, zeroCode); + + assertEq(emptyAddress.code, emptyCode); + assertEq(emptyAddress.code.length, 0); + assertEq(zeroAddress.code, zeroCode); + assertEq(zeroAddress.code.length, 1); + } + function testEtchSymbolic(bytes calldata code) public { vm.etch(address(124), code); assertEq(address(124).code, code);