Skip to content

Commit

Permalink
fix(contracts): <- use excessivelySafeCall() instead of call()
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviera9 committed Feb 16, 2024
1 parent e64ae6d commit c2ba176
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion contracts/pToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ contract PToken is
ERC777GSNUpgradeable,
ERC777WithAdminOperatorUpgradeable
{
using ExcessivelySafeCall for address;

bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes4 public ORIGIN_CHAIN_ID;

Expand Down Expand Up @@ -79,6 +81,7 @@ contract PToken is
recipient != address(this) ,
"Recipient cannot be the token contract address!"
);
uint256 gasReserve = 1000; // enough gas to ensure we eventually emit, and return
_mint(recipient, value, userData, operatorData);
if (userData.length > 0) {
// pNetwork aims to deliver cross chain messages successfully regardless of what the user may do with them.
Expand All @@ -88,7 +91,7 @@ contract PToken is
// a try/catch block fails to catch the revert caused if the receiver is not in fact a contract.
// This way, a user also has the option include userData even when minting to an externally owned account.
bytes memory data = abi.encodeWithSelector(IPReceiver.receiveUserData.selector, userData);
(bool success, ) = recipient.call(data);
(bool success,) = recipient.excessivelySafeCall(gasleft() - gasReserve, 0, 256, data);
if (!success) emit ReceiveUserDataFailed();
}
return true;
Expand Down
5 changes: 4 additions & 1 deletion contracts/pTokenNoGSN.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ contract PTokenNoGSN is
AccessControlUpgradeable,
ERC777WithAdminOperatorUpgradeable
{
using ExcessivelySafeCall for address;

bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes4 public ORIGIN_CHAIN_ID;

Expand Down Expand Up @@ -82,6 +84,7 @@ contract PTokenNoGSN is
recipient != address(this) ,
"Recipient cannot be the token contract address!"
);
uint256 gasReserve = 1000; // enough gas to ensure we eventually emit, and return
_mint(recipient, value, userData, operatorData);
if (userData.length > 0) {
// pNetwork aims to deliver cross chain messages successfully regardless of what the user may do with them.
Expand All @@ -91,7 +94,7 @@ contract PTokenNoGSN is
// a try/catch block fails to catch the revert caused if the receiver is not in fact a contract.
// This way, a user also has the option include userData even when minting to an externally owned account.
bytes memory data = abi.encodeWithSelector(IPReceiver.receiveUserData.selector, userData);
(bool success, ) = recipient.call(data);
(bool success,) = recipient.excessivelySafeCall(gasleft() - gasReserve, 0, 256, data);
if (!success) emit ReceiveUserDataFailed();
}
return true;
Expand Down

0 comments on commit c2ba176

Please sign in to comment.