Skip to content

Commit

Permalink
refactor(contracts): <- add amount field in IPReceiver receiveUserData()
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviera9 committed Mar 15, 2024
1 parent 4c48651 commit 5359eb0
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
3 changes: 2 additions & 1 deletion contracts/interfaces/IPReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ interface IPReceiver {
/*
* @dev Function called when userData.length > 0 when minting the pToken
*
* @param amount
* @param userData
*/
function receiveUserData(bytes calldata userData) external;
function receiveUserData(uint256 amount, bytes calldata userData) external;
}
2 changes: 1 addition & 1 deletion contracts/pToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ contract PToken is
// This way, a user also has the option include userData even when minting to an externally owned account.
// Here excessivelySafeCall executes a low-level call which does not revert the caller transaction if the callee reverts,
// with the increased protection for returnbombing, i.e. the returndata copy is limited to 256 bytes.
bytes memory data = abi.encodeWithSelector(IPReceiver.receiveUserData.selector, userData);
bytes memory data = abi.encodeWithSelector(IPReceiver.receiveUserData.selector, value, userData);
(bool success,) = recipient.excessivelySafeCall(gasleft() - gasReserve, 0, 0, data);
if (!success) emit ReceiveUserDataFailed();
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/pTokenNoGSN.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ contract PTokenNoGSN is
// This way, a user also has the option include userData even when minting to an externally owned account.
// Here excessivelySafeCall executes a low-level call which does not revert the caller transaction if the callee reverts,
// with the increased protection for returnbombing, i.e. the returndata copy is limited to 256 bytes.
bytes memory data = abi.encodeWithSelector(IPReceiver.receiveUserData.selector, userData);
bytes memory data = abi.encodeWithSelector(IPReceiver.receiveUserData.selector, value, userData);
(bool success,) = recipient.excessivelySafeCall(gasleft() - gasReserve, 0, 0, data);
if (!success) emit ReceiveUserDataFailed();
}
Expand Down
12 changes: 6 additions & 6 deletions contracts/test-contracts/PReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ pragma solidity ^0.6.2;
import {IPReceiver} from "../interfaces/IPReceiver.sol";

contract PReceiver is IPReceiver {
event UserData(bytes data);
event UserData(uint256 amount, bytes data);

function receiveUserData(bytes calldata userData) external override {
emit UserData(userData);
function receiveUserData(uint256 amount, bytes calldata userData) external override {
emit UserData(amount, userData);
}
}

contract PReceiverReverting is IPReceiver {
function receiveUserData(bytes calldata) external override {
function receiveUserData(uint256, bytes calldata) external override {
require(false, "Revert!");
}
}

contract NotImplementingReceiveUserDataFxn {}

contract PReceiverRevertingReturnBombing is IPReceiver {
function receiveUserData(bytes calldata) external override {
function receiveUserData(uint256, bytes calldata) external override {
assembly {
return(0, 1000000)
}
}
}

contract PReceiverRevertingReturnBombingReverting is IPReceiver {
function receiveUserData(bytes calldata) external override {
function receiveUserData(uint256, bytes calldata) external override {
assembly {
revert(0, 1000000)
}
Expand Down
1 change: 1 addition & 0 deletions test/05-ptoken.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ USE_GSN.map(_useGSN =>
assertMintEvent(events, recipientContract.address, OWNER.address, AMOUNT, data, operatorData)
const userDataEvent = recipientContract.interface.parseLog(events.at(-1))
assert.strictEqual(userDataEvent.name, 'UserData')
assert.strictEqual(userDataEvent.args.amount.toNumber(), AMOUNT)
assert.strictEqual(userDataEvent.args.data, data)
})

Expand Down

0 comments on commit 5359eb0

Please sign in to comment.