Skip to content

Commit

Permalink
MCPayment: split recipient and signing address
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk committed Nov 6, 2024
1 parent 64284ff commit c53e270
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
4 changes: 2 additions & 2 deletions contracts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@iden3/contracts",
"description": "Smart Contract library for Solidity",
"version": "2.4.5",
"version": "2.4.6",
"files": [
"**/*.sol",
"/build/contracts/*.json",
Expand Down
20 changes: 8 additions & 12 deletions contracts/payment/MCPayment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ contract MCPayment is Ownable2StepUpgradeable, EIP712Upgradeable {
bytes memory signature
) external {
_checkERC20Payment(paymentData, signature);
_transferERC20(paymentData, signature);
_transferERC20(paymentData);
}

function payERC20Permit(
Expand Down Expand Up @@ -187,7 +187,7 @@ contract MCPayment is Ownable2StepUpgradeable, EIP712Upgradeable {
r,
s
);
_transferERC20(paymentData, signature);
_transferERC20(paymentData);
}

function isPaymentDone(address recipient, uint256 nonce) external view returns (bool) {
Expand All @@ -209,7 +209,7 @@ contract MCPayment is Ownable2StepUpgradeable, EIP712Upgradeable {
keccak256(paymentData.metadata)
)
);
if (!_isSignatureValid(structHash, signature, paymentData.recipient)) {
if (!_isSignatureValid(structHash, signature)) {
revert InvalidSignature("MCPayment: invalid signature for Iden3PaymentRailsRequestV1");
}
}
Expand All @@ -230,7 +230,7 @@ contract MCPayment is Ownable2StepUpgradeable, EIP712Upgradeable {
)
);

if (!_isSignatureValid(structHash, signature, paymentData.recipient)) {
if (!_isSignatureValid(structHash, signature)) {
revert InvalidSignature(
"MCPayment: invalid signature for Iden3PaymentRailsERC20RequestV1"
);
Expand All @@ -253,10 +253,7 @@ contract MCPayment is Ownable2StepUpgradeable, EIP712Upgradeable {
}
}

function _transferERC20(
Iden3PaymentRailsERC20RequestV1 memory paymentData,
bytes memory signature
) internal {
function _transferERC20(Iden3PaymentRailsERC20RequestV1 memory paymentData) internal {
IERC20 token = IERC20(paymentData.tokenAddress);
if (token.transferFrom(msg.sender, address(this), paymentData.amount)) {
MCPaymentStorage storage $ = _getMCPaymentStorage();
Expand All @@ -277,13 +274,12 @@ contract MCPayment is Ownable2StepUpgradeable, EIP712Upgradeable {

function _isSignatureValid(
bytes32 structHash,
bytes memory signature,
address recipient
bytes memory signature
) internal view returns (bool) {
bytes32 hashTypedData = _hashTypedDataV4(structHash);
(address recovered, ECDSA.RecoverError err, ) = hashTypedData.tryRecover(signature);
(, ECDSA.RecoverError err, ) = hashTypedData.tryRecover(signature);

if (err != ECDSA.RecoverError.NoError || recovered != recipient) {
if (err != ECDSA.RecoverError.NoError) {
return false;
}

Expand Down

0 comments on commit c53e270

Please sign in to comment.