-
Notifications
You must be signed in to change notification settings - Fork 754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeError: 'NoneType' object has no attribute 'get'
in mythril/solidity/features.py
#1809
Comments
Looks like making this small change in the function elif isinstance(value, list):
for item in value:
if item != None:
transfer_vars.update(self.extract_address_variable(item))
return transfer_vars (checking if |
It turns out that objects like With: /*
* @author: Bernhard Mueller (ConsenSys / MythX)
*/
pragma solidity 0.6.4;
interface ICallable {
function callMe() external;
}
contract HardcodedNotGood {
address payable _callable = 0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa;
ICallable callable = ICallable(_callable);
constructor() public payable {
}
function doTransfer(uint256 amount) public {
_callable.transfer(amount);
}
function doSend(uint256 amount) public {
_callable.send(amount);
}
function callLowLevel() public {
_callable.call.value(0).gas(10000)("");
}
function callWithArgs() public {
callable.callMe{gas: 10000}();
}
}
I get: mythril.interfaces.cli [ERROR]: Traceback (most recent call last):
File "~/venv/lib/python3.10/site-packages/mythril/interfaces/cli.py", line 966, in parse_args_and_execute
address = load_code(disassembler, args)
File "~/venv/lib/python3.10/site-packages/mythril/interfaces/cli.py", line 717, in load_code
address, _ = disassembler.load_from_solidity(
File "~/venv/lib/python3.10/site-packages/mythril/mythril/mythril_disassembler.py", line 291, in load_from_solidity
for contract in get_contracts_from_file(
File "~/venv/lib/python3.10/site-packages/mythril/solidity/soliditycontract.py", line 132, in get_contracts_from_file
yield SolidityContract(
File "~/venv/lib/python3.10/site-packages/mythril/solidity/soliditycontract.py", line 197, in __init__
).extract_features()
File "~/venv/lib/python3.10/site-packages/mythril/solidity/features.py", line 28, in extract_features
ether_vars = self.extract_address_variable(node)
File "~/venv/lib/python3.10/site-packages/mythril/solidity/features.py", line 224, in extract_address_variable
transfer_vars.update(self.extract_address_variable(value))
File "~/venv/lib/python3.10/site-packages/mythril/solidity/features.py", line 228, in extract_address_variable
transfer_vars.update(self.extract_address_variable(item))
File "~/venv/lib/python3.10/site-packages/mythril/solidity/features.py", line 224, in extract_address_variable
transfer_vars.update(self.extract_address_variable(value))
File "~/venv/lib/python3.10/site-packages/mythril/solidity/features.py", line 224, in extract_address_variable
transfer_vars.update(self.extract_address_variable(value))
File "~/venv/lib/python3.10/site-packages/mythril/solidity/features.py", line 228, in extract_address_variable
transfer_vars.update(self.extract_address_variable(item))
File "~/venv/lib/python3.10/site-packages/mythril/solidity/features.py", line 210, in extract_address_variable
node.get("nodeType", "") == "ExpressionStatement"
AttributeError: 'str' object has no attribute 'get' Sorry for the delay in reporting this. |
Does the current develop work for you? This example works for me on the develop. |
Yes, surprisingly it did fix that issue. But I found a new one in a different file: mythril.interfaces.cli [ERROR]: Traceback (most recent call last):
File "/home/parakeet/tests/mythril/mythril/interfaces/cli.py", line 966, in parse_args_and_execute
address = load_code(disassembler, args)
File "/home/parakeet/tests/mythril/mythril/interfaces/cli.py", line 717, in load_code
address, _ = disassembler.load_from_solidity(
File "/home/parakeet/tests/mythril/mythril/mythril/mythril_disassembler.py", line 272, in load_from_solidity
if self.check_run_integer_module(file) is False:
File "/home/parakeet/tests/mythril/mythril/mythril/mythril_disassembler.py", line 236, in check_run_integer_module
normalized_version = self.solc_version.lstrip("v")
AttributeError: 'NoneType' object has no attribute 'lstrip' The contract in question does not specify the solidity version (which is wrong) but when I tested it with Mythril Looks like the source is this recent change: |
This mythril version tries to autofind the solidity version, Can you try to paste the first few lines at the top of the file (till |
Here is the contract: contract MarketPlace {
address owner;
uint256 private cost = 100;
uint256 private inventory = 20;
event Purchase(address _buyer, uint256 _amt);
function increasePrice (uint256 increaseCost) public {
require(msg.sender == owner);
cost += increaseCost;
}
function buy() public payable returns (uint256) {
uint256 amt = msg.value / cost;
require(inventory > amt);
inventory -= amt;
emit Purchase(msg.sender, amt);
}
} |
Thanks for the contract, the PR #1812 will fix this |
Description
A Python error is thrown when analysing certain contracts. Earlier versions did not have this issue.
How to Reproduce
After installing (
v0.24
) from the PyPi (following the official documentation), run the following command analysing a certain contract (source code will be provided below):myth a contract.sol
This is the error we get:
Source code of
contract.sol
:Expected behavior
A successful execution with no errors and a number of detections.
Environment
Mythril version v0.24.0
Python 3.11.6
Additional Notes
The same occurs with a lot of other contracts also.
The text was updated successfully, but these errors were encountered: