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

MCPayment: split recipient and signing address #310

Merged
merged 3 commits into from
Nov 8, 2024
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
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.5.0",
"version": "2.5.1",
"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
Loading