-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(protocol): oz - use excessivelySafeCall instadd of
to.call(...)
(…
- Loading branch information
Showing
7 changed files
with
87 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# ABOUT THIRDPARTY CODE | ||
|
||
- /optimism: code copied from `packages/contracts-bedrock/src/libraries` in https://github.com/ethereum-optimism/optimism/releases/tag/op-batcher%2Fv1.4.3 as-is with only solidity pragma changed. | ||
|
||
- /solmate: code copied from https://github.com/transmissions11/solmate/blob/v7/src/utils/FixedPointMathLib.sol as-is with only solidity pragma changed. | ||
|
||
- /nomad-xyz: code copied from https://github.com/nomad-xyz/ExcessivelySafeCall/blob/main/src/ExcessivelySafeCall.sol with unused coded removed and solidity pragma changed. |
64 changes: 64 additions & 0 deletions
64
packages/protocol/contracts/thirdparty/nomad-xyz/ExcessivelySafeCall.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,64 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
// https://github.com/nomad-xyz/ExcessivelySafeCall/blob/main/src/ExcessivelySafeCall.sol | ||
pragma solidity 0.8.24; | ||
|
||
library ExcessivelySafeCall { | ||
uint256 constant LOW_28_MASK = | ||
0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff; | ||
|
||
/// @notice Use when you _really_ really _really_ don't trust the called | ||
/// contract. This prevents the called contract from causing reversion of | ||
/// the caller in as many ways as we can. | ||
/// @dev The main difference between this and a solidity low-level call is | ||
/// that we limit the number of bytes that the callee can cause to be | ||
/// copied to caller memory. This prevents stupid things like malicious | ||
/// contracts returning 10,000,000 bytes causing a local OOG when copying | ||
/// to memory. | ||
/// @param _target The address to call | ||
/// @param _gas The amount of gas to forward to the remote contract | ||
/// @param _value The value in wei to send to the remote contract | ||
/// @param _maxCopy The maximum number of bytes of returndata to copy | ||
/// to memory. | ||
/// @param _calldata The data to send to the remote contract | ||
/// @return success and returndata, as `.call()`. Returndata is capped to | ||
/// `_maxCopy` bytes. | ||
function excessivelySafeCall( | ||
address _target, | ||
uint256 _gas, | ||
uint256 _value, | ||
uint16 _maxCopy, | ||
bytes memory _calldata | ||
) | ||
internal | ||
returns (bool, bytes memory) | ||
{ | ||
// set up for assembly call | ||
uint256 _toCopy; | ||
bool _success; | ||
bytes memory _returnData = new bytes(_maxCopy); | ||
// dispatch message to recipient | ||
// by assembly calling "handle" function | ||
// we call via assembly to avoid memcopying a very large returndata | ||
// returned by a malicious contract | ||
assembly { | ||
_success := | ||
call( | ||
_gas, // gas | ||
_target, // recipient | ||
_value, // ether value | ||
add(_calldata, 0x20), // inloc | ||
mload(_calldata), // inlen | ||
0, // outloc | ||
0 // outlen | ||
) | ||
// limit our copy to 256 bytes | ||
_toCopy := returndatasize() | ||
if gt(_toCopy, _maxCopy) { _toCopy := _maxCopy } | ||
// Store the length of the copied bytes | ||
mstore(_returnData, _toCopy) | ||
// copy the bytes from returndata[0:_toCopy] | ||
returndatacopy(add(_returnData, 0x20), 0, _toCopy) | ||
} | ||
return (_success, _returnData); | ||
} | ||
} |
File renamed without changes.
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