trailofbits / manticore

Symbolic execution tool
https://blog.trailofbits.com/2017/04/27/manticore-symbolic-execution-for-humans/
GNU Affero General Public License v3.0
3.68k stars 472 forks source link

User-friendly Throwing Warning or Error when Account Executing with Insufficient Balance #2551

Open CharesFang opened 2 years ago

CharesFang commented 2 years ago

Description

Just take a case from the wiki doc (I pasted the code at the end); I want to create a contract_count by executing the solidity_create_contract function. However, many users met the same situation as me that we just received nothing but a None object. The Manticore would not throw any warning or error, which is really frustrated. I checked the doc several times and spent nearly half of a day trying to find the main cause. Finally, I got that Manticore would just return a None when the account executed commands with insufficient balance. And the unit of balance is really minor, so we have to give the user_account a really big number.

Suggestion

I just think that the Manticore should throw some kind of warnings/errors when the EVM executed some functions but failed due to the insufficient balances, and then users would know how to handle such situations.

Appendix

My test script is as follows, replace the path variable with your own solc abspath.

import unittest
from manticore.ethereum import ManticoreEVM

path = "YOUR_SOLC_PATH"

class MTestCase(unittest.TestCase):
    def test_deploy_contract(self):
        m = ManticoreEVM()
        user_account = m.create_account(balance=1000)
        # user_account = m.create_account(balance=10**20) # This statement will successfully pass the test.
        source_code = '''
        pragma solidity >=0.4.24 <0.6.0;
        contract Simple {
            function f(uint a) payable public{
                if (a == 65) {
                    revert();
                }
            }
        }
        '''
        # Initiate the contract
        contract_account = m.solidity_create_contract(source_code, owner=user_account, compile_args={'solc': path})

        self.assertIsNotNone(contract_account)

if __name__ == '__main__':
    unittest.main()