Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only use transactionId in recover functions #23

Merged
merged 4 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions packages/contracts/contracts/TransactionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ contract TransactionManager is ReentrancyGuard, ITransactionManager {
require(txData.preparedBlockNumber > 0, "fulfill: ALREADY_COMPLETED");

// Validate the user has signed
require(recoverFulfillSignature(txData, relayerFee, signature) == txData.user, "fulfill: INVALID_SIGNATURE");
require(recoverFulfillSignature(txData.transactionId, relayerFee, signature) == txData.user, "fulfill: INVALID_SIGNATURE");

// Sanity check: fee <= amount. Allow `=` in case of only wanting to execute
// 0-value crosschain tx, so only providing the fee amount
Expand Down Expand Up @@ -489,7 +489,7 @@ contract TransactionManager is ReentrancyGuard, ITransactionManager {
// When the user could be unlocking funds through a relayer, validate
// their signature and payout the relayer.
if (relayerFee > 0) {
require(recoverCancelSignature(txData, relayerFee, signature) == txData.user, "cancel: INVALID_SIGNATURE");
require(recoverCancelSignature(txData.transactionId, relayerFee, signature) == txData.user, "cancel: INVALID_SIGNATURE");

LibAsset.transferAsset(txData.receivingAssetId, payable(msg.sender), relayerFee);
}
Expand All @@ -508,7 +508,7 @@ contract TransactionManager is ReentrancyGuard, ITransactionManager {
if (txData.expiry >= block.timestamp) {
// Timeout has not expired and tx may only be cancelled by user
// Validate signature
require(recoverCancelSignature(txData, relayerFee, signature) == txData.user, "cancel: INVALID_SIGNATURE");
require(recoverCancelSignature(txData.transactionId, relayerFee, signature) == txData.user, "cancel: INVALID_SIGNATURE");

// NOTE: there is no incentive here for relayers to submit this on
// behalf of the user (i.e. fee not respected) because the user has not
Expand Down Expand Up @@ -560,35 +560,35 @@ contract TransactionManager is ReentrancyGuard, ITransactionManager {

/// @notice Recovers the signer from the signature provided to the `fulfill`
/// function. Returns the address recovered
/// @param txData TransactionData of the transaction being fulfilled
/// @param transactionId Transaction identifier of tx being fulfilled
/// @param relayerFee The fee paid to the relayer for submitting the fulfill
/// tx on behalf of the user.
/// @param signature The signature you are recovering the signer from
function recoverFulfillSignature(
TransactionData calldata txData,
bytes32 transactionId,
uint256 relayerFee,
bytes calldata signature
) internal pure returns (address) {
// Create the signed payload
SignedFulfillData memory payload = SignedFulfillData({transactionId: txData.transactionId, relayerFee: relayerFee});
SignedFulfillData memory payload = SignedFulfillData({transactionId: transactionId, relayerFee: relayerFee});

// Recover
return ECDSA.recover(ECDSA.toEthSignedMessageHash(keccak256(abi.encode(payload))), signature);
}

/// @notice Recovers the signer from the signature provided to the `cancel`
/// function. Returns the address recovered
/// @param txData TransactionData of the transaction being fulfilled
/// @param transactionId Transaction identifier of tx being cancelled
/// @param relayerFee The fee paid to the relayer for submitting the cancel
/// tx on behalf of the user.
/// @param signature The signature you are recovering the signer from
function recoverCancelSignature(TransactionData calldata txData, uint256 relayerFee, bytes calldata signature)
function recoverCancelSignature(bytes32 transactionId, uint256 relayerFee, bytes calldata signature)
internal
pure
returns (address)
{
// Create the signed payload
SignedCancelData memory payload = SignedCancelData({transactionId: txData.transactionId, cancel: "cancel", relayerFee: relayerFee});
SignedCancelData memory payload = SignedCancelData({transactionId: transactionId, cancel: "cancel", relayerFee: relayerFee});

// Recover
return ECDSA.recover(ECDSA.toEthSignedMessageHash(keccak256(abi.encode(payload))), signature);
Expand Down
Loading