Skip to content

check EIP1271 signatures #635

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion contracts/extension/Ownable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ abstract contract Ownable is IOwnable {
}

/// @dev Lets a contract admin set a new owner for the contract. The new owner must be a contract admin.
function _setupOwner(address _newOwner) internal {
function _setupOwner(address _newOwner) internal virtual {
address _prevOwner = _owner;
_owner = _newOwner;

Expand Down
42 changes: 39 additions & 3 deletions contracts/prebuilts/unaudited/airdrop/Airdrop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
import "../../../eip/interface/IERC721.sol";
import "../../../eip/interface/IERC1155.sol";

interface IEIP1271 {
function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4);
}

contract Airdrop is EIP712, Initializable, Ownable {
using ECDSA for bytes32;

Expand Down Expand Up @@ -98,6 +102,8 @@
"AirdropRequestERC1155(bytes32 uid,address tokenAddress,uint256 expirationTimestamp,AirdropContentERC1155[] contents)AirdropContentERC1155(address recipient,uint256 tokenId,uint256 amount)"
);

bytes4 private constant EIP1271_MAGIC_VALUE = 0x1626ba7e;

address private constant NATIVE_TOKEN_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

/*///////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -486,7 +492,17 @@

bytes32 digest = _hashTypedData(structHash);
address recovered = digest.recover(signature);
return recovered == owner();

address _owner = owner();
if (recovered != _owner) {
try IEIP1271(_owner).isValidSignature(digest, signature) returns (bytes4 magicValue) {
return magicValue == EIP1271_MAGIC_VALUE;
} catch {}

return false;
}

return true;
}

function _verifyRequestSignerERC721(
Expand All @@ -500,7 +516,17 @@

bytes32 digest = _hashTypedData(structHash);
address recovered = digest.recover(signature);
return recovered == owner();

address _owner = owner();
if (recovered != _owner) {
try IEIP1271(_owner).isValidSignature(digest, signature) returns (bytes4 magicValue) {
return magicValue == EIP1271_MAGIC_VALUE;
} catch {}

return false;
}

return true;
}

function _verifyRequestSignerERC1155(
Expand All @@ -514,6 +540,16 @@

bytes32 digest = _hashTypedData(structHash);
address recovered = digest.recover(signature);
return recovered == owner();

address _owner = owner();
if (recovered != _owner) {
try IEIP1271(_owner).isValidSignature(digest, signature) returns (bytes4 magicValue) {
return magicValue == EIP1271_MAGIC_VALUE;
} catch {}

return false;
}

return true;
}
}
Loading