kroma-network / kroma

A developer-friendly, rollup-based Ethereum Layer 2 solution that offers low fees and EVM equivalence.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

contracts/test/SafeCallt.sol:SafeCall_call_test:testFuzz_call_succeeds fails

chokobole opened this issue · comments

Issue Type

Bug

Kanvas Version

0.1.0

OS Platform and Distribution

Linux Ubuntu 22.04

Go version

go1.19.3 linux/amd64

Node version

v16.14.2

Current Behaviour?

fuzzing test is failed.

Standalone code to reproduce the issue

// pakcages/contracts/contracts/test/SafeCall.t.sol:8
function testFuzz_call_succeeds(
    address from,
    address to,
    uint256 gas,
    uint64 value,
    bytes memory data
) external {
    // override the input
    from = address(0x000000000000000000000000000000000000A4b1);
    to = address(0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f);
    gas = 4077681571;
    value = 8133;
    data = hex"0000000000000000000000000000000000000000000000000000000000000126";
    vm.assume(from.balance == 0);
    vm.assume(to.balance == 0);
    // no precompiles (mainnet)
    assumeNoPrecompiles(to, 1);
    // don't call the vm
    vm.assume(to != address(vm));
    vm.assume(from != address(vm));
    // don't call the console
    vm.assume(to != address(0x000000000000000000636F6e736F6c652e6c6f67));
    // don't call the create2 deployer
    vm.assume(to != address(0x4e59b44847b379578588920cA78FbF26c0B4956C));

    assertEq(from.balance, 0, "from balance is 0");
    vm.deal(from, value);
    assertEq(from.balance, value, "from balance not dealt");

    uint256[2] memory balancesBefore = [from.balance, to.balance];

    vm.expectCall(to, value, data);
    vm.prank(from);
    bool success = SafeCall.call(to, gas, value, data);

    assertTrue(success, "call not successful");
    if (from == to) {
        assertEq(from.balance, balancesBefore[0], "Self-send did not change balance");
    } else {
        assertEq(from.balance, balancesBefore[0] - value, "from balance not drained");
        assertEq(to.balance, balancesBefore[1] + value, "to balance received");
    }
}

Relevant log output

> forge test --match-test testFuzz_call_succeeds  -vvv
Running 1 test for contracts/test/SafeCall.t.sol:SafeCall_call_Test
[FAIL. Reason: Assertion failed. Counterexample: calldata=0xe28f97dc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000, args=[0x0000000000000000000000000000000000000000, 0x0000000000000000000000000000000000000000, 0, 0, 0x]] testFuzz_call_succeeds(address,address,uint256,uint64,bytes) (runs: 0, μ: 0, ~: 0)
Logs:
  Error: call not successful
  Error: Assertion Failed
  Error: from balance not drained
  Error: a == b not satisfied [uint]
    Expected: 0
      Actual: 8133
  Error: to balance received
  Error: a == b not satisfied [uint]
    Expected: 8133
      Actual: 0

Traces:
  [51846] SafeCall_call_Test::testFuzz_call_succeeds(0x0000000000000000000000000000000000000000, 0x0000000000000000000000000000000000000000, 0, 0, 0x) 
    ├─ [0] VM::assume(true) [staticcall]
    │   └─  ()
    ├─ [0] VM::assume(true) [staticcall]
    │   └─  ()
    ├─ [0] VM::assume(true) [staticcall]
    │   └─  ()
    ├─ [0] VM::assume(true) [staticcall]
    │   └─  ()
    ├─ [0] VM::assume(true) [staticcall]
    │   └─  ()
    ├─ [0] VM::assume(true) [staticcall]
    │   └─  ()
    ├─ [0] VM::assume(true) [staticcall]
    │   └─  ()
    ├─ [0] VM::deal(0x000000000000000000000000000000000000A4b1, 8133) 
    │   └─  ()
    ├─ [0] VM::expectCall(FFIInterface: [0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f], 8133, 0x0000000000000000000000000000000000000000000000000000000000000126) 
    │   └─  ()
    ├─ [0] VM::prank(0x000000000000000000000000000000000000A4b1) 
    │   └─  ()
    ├─ [45] FFIInterface::00000000{value: 8133}(00000000000000000000000000000000000000000000000000000126) 
    │   └─  ()
    ├─ emit log_named_string(key: Error, val: call not successful)
    ├─ emit log(: Error: Assertion Failed)
    ├─ [0] VM::store(VM: [0x7109709ECfa91a80626fF3989D68f67F5b1DD12D], 0x6661696c65640000000000000000000000000000000000000000000000000000, 0x0000000000000000000000000000000000000000000000000000000000000001) 
    │   └─  ()
    ├─ emit log_named_string(key: Error, val: from balance not drained)
    ├─ emit log(: Error: a == b not satisfied [uint])
    ├─ emit log_named_uint(key:   Expected, val: 0)
    ├─ emit log_named_uint(key:     Actual, val: 8133)
    ├─ [0] VM::store(VM: [0x7109709ECfa91a80626fF3989D68f67F5b1DD12D], 0x6661696c65640000000000000000000000000000000000000000000000000000, 0x0000000000000000000000000000000000000000000000000000000000000001) 
    │   └─  ()
    ├─ emit log_named_string(key: Error, val: to balance received)
    ├─ emit log(: Error: a == b not satisfied [uint])
    ├─ emit log_named_uint(key:   Expected, val: 8133)
    ├─ emit log_named_uint(key:     Actual, val: 0)
    ├─ [0] VM::store(VM: [0x7109709ECfa91a80626fF3989D68f67F5b1DD12D], 0x6661696c65640000000000000000000000000000000000000000000000000000, 0x0000000000000000000000000000000000000000000000000000000000000001) 
    │   └─  ()
    └─  ()

Test result: FAILED. 0 passed; 1 failed; finished in 22.46ms

Failing tests:
Encountered 1 failing test in contracts/test/SafeCall.t.sol:SafeCall_call_Test
[FAIL. Reason: Assertion failed. Counterexample: calldata=0xe28f97dc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000, args=[0x0000000000000000000000000000000000000000, 0x0000000000000000000000000000000000000000, 0, 0, 0x]] testFuzz_call_succeeds(address,address,uint256,uint64,bytes) (runs: 0, μ: 0, ~: 0)

Encountered a total of 1 failing tests, 0 tests succeeded
commented

Forge test using deterministic addresses.
When a deterministic deployment address is injected, the problem occures.