Skip to content

Commit

Permalink
Merge pull request #50 from trailofbits/49-update-examples
Browse files Browse the repository at this point in the history
Update the examples to work with solc v0.5.0+
  • Loading branch information
ESultanik authored Feb 6, 2019
2 parents c0e1565 + 5dd8177 commit 446918d
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 8 deletions.
5 changes: 4 additions & 1 deletion etheno/etheno.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ def post(self, data):
plugin.before_post(data)

method = data['method']

args = ()
kwargs = {}
if 'params' in data:
Expand All @@ -316,12 +315,15 @@ def post(self, data):
del kwargs['from']
else:
args = data['params']

if self.master_client is None:
ret = None
else:
if method == 'eth_getTransactionReceipt':
# for eth_getTransactionReceipt, make sure we block until all clients have mined the transaction
ret = self.master_client.wait_for_transaction(data['params'][0])
if 'id' in data and 'id' in ret:
ret['id'] = data['id']
else:
try:
ret = self.master_client.post(data)
Expand All @@ -342,6 +344,7 @@ def post(self, data):
kwargs['rpc_client_result'] = ret
results.append(function(*args, **kwargs))
else:
self.logger.warn(f"Function {method} of {client} is None!")
results.append(None)
elif isinstance(client, SelfPostingClient):
if method == 'eth_getTransactionReceipt':
Expand Down
4 changes: 2 additions & 2 deletions etheno/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _add_child(self, child):
raise ValueError("Cannot double-add child logger %s to logger %s" % (child.name, self.name))
self.children.append(child)
if self.directory is not None:
child.save_to_directory(os.path.join(self.directory, child.name))
child.save_to_directory(os.path.join(self.directory, child.name.replace(os.sep, '-')))
else:
child._tmpdir = tempfile.TemporaryDirectory()
child.save_to_directory(child._tmpdir.name)
Expand Down Expand Up @@ -219,7 +219,7 @@ def save_to_directory(self, path):
raise ValueError("Logger %s's save directory is already set to %s" % (self.name, path))
self._directory = os.path.realpath(path)
os.makedirs(path, exist_ok=True)
self.save_to_file(os.path.join(path, "%s.log" % self.name), include_descendants=False, log_level=DEBUG)
self.save_to_file(os.path.join(path, "%s.log" % self.name.replace(os.sep, '-')), include_descendants=False, log_level=DEBUG)
for child in self.children:
child.save_to_directory(os.path.join(path, child.name))

Expand Down
2 changes: 1 addition & 1 deletion etheno/truffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def run_migrate(self):

def run(self, args):
self._running = True
if isinstance(args, Sequence):
if isinstance(args, Sequence) and not isinstance(args, str) and not isinstance(args, bytes):
if not isinstance(args, list):
args = list(args)
else:
Expand Down
2 changes: 1 addition & 1 deletion examples/BrokenMetaCoin/contracts/ConvertLib.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.4;
pragma solidity ^0.5.0;

library ConvertLib{
function convert(uint amount,uint conversionRate) public pure returns (uint convertedAmount)
Expand Down
4 changes: 2 additions & 2 deletions examples/BrokenMetaCoin/contracts/MetaCoin.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.18;
pragma solidity ^0.5.0;

import "./ConvertLib.sol";

Expand Down Expand Up @@ -26,7 +26,7 @@ contract MetaCoin {
return metadata[key];
}

function backdoor() {
function backdoor() public {
selfdestruct(msg.sender);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/BrokenMetaCoin/contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.2;
pragma solidity ^0.5.0;

contract Migrations {
address public owner;
Expand Down
7 changes: 7 additions & 0 deletions examples/BrokenMetaCoin/run_etheno.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# First, remove the Truffle build directory.
# This shouldn't be necessary, but Truffle will often fail with
# confusing error messages if it is upgraded between builds.
# So, we just rebuild everything from scratch each time to ensure
# that it always works.
rm -rf build

echo "Running the custom Manticore script ExploitMetaCoinManticoreScript.py"
# Set the max depth for Manticore to 2 because this script only needs to
# find a sequence of two transactions to exploit the bug
Expand Down

0 comments on commit 446918d

Please sign in to comment.