forked from evmos/ethermint
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
126 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
local config = import 'default.jsonnet'; | ||
|
||
config { | ||
'ethermint_9000-1'+: { | ||
'app-config'+: { | ||
'json-rpc'+: { | ||
'return-data-limit': 3594241, // memory_byte_size + 1 | ||
}, | ||
}, | ||
}, | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/integration_tests/hardhat/contracts/TestExploitContract.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
contract TestExploitContract { | ||
function dos() public pure { | ||
assembly { | ||
return(0, 0x36d800) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from concurrent.futures import ThreadPoolExecutor, as_completed | ||
from pathlib import Path | ||
|
||
import pytest | ||
import requests | ||
from pystarport import ports | ||
|
||
from .network import setup_custom_ethermint | ||
from .utils import CONTRACTS, deploy_contract | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def custom_ethermint(tmp_path_factory): | ||
path = tmp_path_factory.mktemp("exploit") | ||
yield from setup_custom_ethermint( | ||
path, 26910, Path(__file__).parent / "configs/exploit.jsonnet" | ||
) | ||
|
||
|
||
def call(port, params): | ||
url = f"http://127.0.0.1:{ports.evmrpc_port(port)}" | ||
rsp = requests.post(url, json=params) | ||
assert rsp.status_code == 200 | ||
return rsp.json() | ||
|
||
|
||
def run_test(provider, concurrent, batch, expect_cb): | ||
_, res = deploy_contract(provider.w3, CONTRACTS["TestExploitContract"]) | ||
param = { | ||
"jsonrpc": "2.0", | ||
"method": "eth_call", | ||
"params": [ | ||
{ | ||
"data": "0x5e67164c", | ||
"to": res["contractAddress"], | ||
}, | ||
"latest", | ||
], | ||
"id": 1, | ||
} | ||
params = [] | ||
for _ in range(batch): | ||
params.append(param) | ||
with ThreadPoolExecutor(concurrent) as executor: | ||
tasks = [ | ||
executor.submit(call, provider.base_port(0), params) | ||
for _ in range(0, concurrent) | ||
] | ||
results = [future.result() for future in as_completed(tasks)] | ||
assert len(results) == concurrent | ||
for result in results: | ||
expect_cb(result) | ||
|
||
|
||
def test_call(ethermint): | ||
concurrent = 2 | ||
batch = 1 | ||
|
||
def expect_cb(result): | ||
for item in result: | ||
assert "error" in item | ||
assert "exceeding limit" in item["error"]["message"] | ||
|
||
run_test(ethermint, concurrent, batch, expect_cb) | ||
|
||
|
||
def test_large_call(custom_ethermint): | ||
concurrent = 2 | ||
batch = 1 | ||
|
||
def expect_cb(result): | ||
for item in result: | ||
assert "error" not in item | ||
|
||
run_test(custom_ethermint, concurrent, batch, expect_cb) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters