trufflesuite / truffle

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
14.02k stars 2.31k forks source link

Calldata array variables get corrupted if you view them after a nested scope in the debugger #4055

Closed 0xfoobar closed 3 years ago

0xfoobar commented 3 years ago

Issue

You have no idea how long it took me to whittle this one down :) When you view variables in the Truffle debugger with the v command while inspecting a transaction, sometimes calldata arrays are corrupted. For example, I pass in an array of length 1 in web3js, but when viewed in the Truffle debugger, it is of length 324 with random bytes inserted throughout.

This only occurs sometimes, and I noticed that if I stuck a breakpoint at the beginning of the function and inspected the variables, they were normal. It was only after entering & existing a nested scope that they became corrupted.

Steps to Reproduce

contract Example {

  constructor() {}

    function calldataCorruptionTest(uint[] calldata data) public returns (bool) {
        bool retval;
        {
            uint something = 3;
            retval = true;
        }
        return retval;
    }
}

Now call this in web3js with something like

const instance = await Example.deployed();
tx = await instance.contract.methods.calldataCorruptionTest(
  [0]
).send({
  "from": accounts[0],
  "gasLimit": 100000
});

Then enter the debugger with truffle debug $TXHASH and enter a breakpoint within the function. Note the array corruption by entering v. Now remove the nested scope from the function and repeat. Note that the array now looks good.

Example Corruption

Data should be 0, but is a large number instead. Screen Shot 2021-05-19 at 10 32 55 PM

haltman-at commented 3 years ago

Aha, thanks so much for reproducing this one! I'll take a look.

haltman-at commented 3 years ago

OK, I have verified that the problem exists, thanks for catching this! Will have to figure out what's going on here.

haltman-at commented 3 years ago

OK, put up a PR that should solve this!