Skip to content

Commit 80c6d66

Browse files
committed
make sure reverting multicall is only used as result if revert is intended.
1 parent 2ffdd99 commit 80c6d66

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

IceCreamSwapWeb3/Multicall.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,21 @@ def _inner_call(
121121
multicall_call = self._build_calldata(
122122
calls_with_calldata=calls_with_calldata
123123
)
124+
use_revert = False
124125

125126
try:
126127
raw_returns, gas_usages = self._call_multicall(
127128
multicall_call=multicall_call,
129+
use_revert=use_revert,
128130
retry=False
129131
)
130132
except Exception as e:
131133
if len(calls_with_calldata) == 1:
132134
try:
133135
raw_returns, gas_usages = self._call_multicall(
134136
multicall_call=multicall_call,
135-
retry=len(calls_with_calldata) == 1
137+
use_revert=use_revert,
138+
retry=True
136139
)
137140
except Exception as e:
138141
raw_returns = [e]
@@ -332,7 +335,12 @@ def get_revert_reason(revert_bytes: bytes) -> str:
332335
except Exception:
333336
return revert_bytes
334337

335-
def _call_multicall(self, multicall_call: ContractConstructor | ContractFunction, retry: bool = False):
338+
def _call_multicall(
339+
self,
340+
multicall_call: ContractConstructor | ContractFunction,
341+
use_revert: bool,
342+
retry: bool = False
343+
):
336344
# call transaction
337345
try:
338346
if isinstance(multicall_call, ContractConstructor):
@@ -369,7 +377,11 @@ def _call_multicall(self, multicall_call: ContractConstructor | ContractFunction
369377
assert success, "Undeployed contract constructor reverted"
370378
assert "0x" + address_encoded[-20:].hex() == self.undeployed_contract_address.lower(), "unexpected undeployed contract address"
371379
multicall_result = multicall_result[1:]
380+
if use_revert:
381+
raise ValueError("Multicall did not revert but was expected to")
372382
except ContractLogicError as e:
383+
if not use_revert:
384+
raise
373385
if not e.message.startswith("execution reverted: "):
374386
raise
375387
result_str = e.message.removeprefix("execution reverted: ")

0 commit comments

Comments
 (0)