Truffle: Truffle debug crashes when inspecting memory array

Created on 4 Mar 2019  路  4Comments  路  Source: trufflesuite/truffle

Issue

Truffle debug crashes when inspecting memory array

Steps to Reproduce

Games.sol

pragma solidity 0.5.4;

contract Games {
    enum GameState { 
        Invalid,
        odd,
        even
    }

    struct Game {
        GameState state;
        bytes32 gameId;
    }

    mapping(bytes32 => Game) public games;

    function recordMany(bytes32[] memory _games) public {
        for (uint i=0; i<_games.length; i++) {
            Game storage game = games[_games[i]];
            game.state = GameState.odd;
        }
    }
}

games.test.js

const Games = artifacts.require("Games")

const {randomHex} = web3.utils

contract('Games', async (accounts) => {
  let gameIds = []
  let gamesInstance

  before(async () => {
    for(i=0; i < 2; i++) {
      gameIds.push(randomHex(32))
    }
    gamesInstance = await Games.deployed()
  })

  describe.only('#recordMany', async () => {
    it('get all games states', async () => {
      await gamesInstance.recordMany(gameIds)
    })
  })
})

  1. run tests
  2. start debugging of test's tx
  3. show local variables (v) at line 19

truffle_debug

Expected Behavior

v should show local variables

Actual Results

an exception thrown

TypeError: Cannot read property '10' of undefined
    at Object.storageSize (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-decoder/dist/allocate/storage.js:162:1)
    at storageSizeAndAllocate (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-decoder/dist/allocate/storage.js:245:1)

Environment

  • Operating System:
  • Ethereum client:
    Truffle v5.0.6 (core: 5.0.6)
    Solidity - 0.5.4 (solc-js)
    Node v11.8.0

Bug submitted by peppersec.com

Debugger bug

All 4 comments

Thanks for raising this issue! We'll look into it and someone will get back to you.

OK, I've created PR #1788 to fix this bug. For what it's worth, the problem is not related to memory arrays; rather it was related to local variables of struct storage type, hence why it occurred on line 19, where the local Game storage game was declared.

(Edit: For what it's worth, a local storage variable that was a statically-sized array of structs would also have triggered the bug.)

It was discovered during one of the security audits we have been performing with truffle suite. Thanks again to Truffle team for building amazing tools for auditors.

Just released Truffle v5.0.7 containing the fix for this. Could you try it out and let us know if it's not fixed? Thanks again!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ripper234 picture ripper234  路  4Comments

ferittuncer picture ferittuncer  路  3Comments

rotcivegaf picture rotcivegaf  路  3Comments

maximilianh picture maximilianh  路  3Comments

arunmitteam picture arunmitteam  路  3Comments