question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Forking mainnet results in erroneous revert reason

See original GitHub issue

This issue has been noticed by the Compound team before when forking the mainnet, and can be reproduced using the tests in this commit.

Steps to Reproduce

  1. Clone the above repository at the specified commit
  2. Run npm install
  3. Compile contracts and run tests with npx oz compile && npx mocha --exit --timeout 0 test/endaoment-test.js
  4. The tests will fail with the following console output
$ npx oz compile && npx mocha --exit --timeout 0 test/endaoment-test.js
Nothing to compile, all contracts are up to date.


  Endaoment
    ✓ should see the deployed Endaoment contract
    1) should allow a membership proposal & vote


  1 passing (39s)
  1 failing

  1) Endaoment
       should allow a membership proposal & vote:
     Error: Returned error: VM Exception while processing transaction: revert Endaoment::processProposal - token transfer to guild bank failed -- Reason given: re-entered.
     at PromiEvent (node_modules/@truffle/contract/lib/promievent.js:9:30)
      at TruffleContract.processProposal (node_modules/@truffle/contract/lib/execute.js:169:26)
      at Context.it (test/endaoment-test.js:61:29)
      at process._tickCallback (internal/process/next_tick.js:68:7)

Explanation

In the file endaoment-test.js we are failing in the test called “should allow a membership proposal & vote” at the line await this.instance.processProposal(0, {from: summoner});

This line calls the function processProposal() in Endaoment.sol. The failure occurs in the following section of that function:

// transfer tokens to guild bank
require(
    guildBank.deposit(proposal.tokenTribute),
    "Endaoment::processProposal - token transfer to guild bank failed"
);

This line is calling the deposit() function in GuildBank.sol. This function is shown below for convenience:

function deposit(uint256 amount) public onlyOwner returns (bool) {
    bool transferSuccess = approvedToken.transferFrom(msg.sender, address(this), amount);
    if (!transferSuccess) {
        return false;
    }
    
    uint256 mintCode = cToken.mint(amount);
    if (0 == mintCode) {
        return false;
    }
    emit Deposit(amount);
    return true;
}

Now, the statement if (0 == mintCode) is incorrect, and really should be if (0 != mintCode). However, this mistake in the code means the function should return false and therefore the contract should error solely with the error message “Endaoment::processProposal - token transfer to guild bank failed”.

Instead, you can see the cToken error message of “re-entered” is included. This is from the nonReentrant modifier of cTokens, but because there is no reentrancy here this should not have been triggered.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
seesemichaeljcommented, Aug 17, 2020

Hey @davidlucid I’m looking into the issue now and proposed patch from https://github.com/compound-finance/ganache-core/pull/5, so hopefully soon!

3reactions
0xTimepunkcommented, Mar 10, 2021

I am having this issue too with the latest ganache version. Anyone?

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found