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

compiling, 0.8.17 and 0.8.18 #183

Open
wants to merge 3 commits into
base: erc721
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[profile.default]
solc = "0.8.17"
bytecode_hash = "none"
optimizer = true
via_ir = true
Expand Down
4 changes: 2 additions & 2 deletions src/ERC20/AllowanceTransfer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ pragma solidity 0.8.17;
import {ERC20} from "solmate/src/tokens/ERC20.sol";
import {SafeTransferLib} from "solmate/src/utils/SafeTransferLib.sol";
import {PermitHash} from "./libraries/PermitHash.sol";
import {SignatureVerification} from "../shared/SignatureVerification.sol";
import {SignatureVerification} from "../ERC20/SignatureVerification.sol";
import {EIP712} from "./EIP712.sol";
import {IAllowanceTransfer} from "./interfaces/IAllowanceTransfer.sol";
import {SignatureExpired, InvalidNonce} from "../shared/PermitErrors.sol";
import {SignatureExpired, InvalidNonce} from "./PermitErrors.sol";
import {Allowance} from "./libraries/Allowance.sol";

contract AllowanceTransfer is IAllowanceTransfer, EIP712 {
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/ERC20/SignatureTransfer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
pragma solidity 0.8.17;

import {ISignatureTransfer} from "./interfaces/ISignatureTransfer.sol";
import {SignatureExpired, InvalidNonce} from "../shared/PermitErrors.sol";
import {SignatureExpired, InvalidNonce} from "./PermitErrors.sol";
import {ERC20} from "solmate/src/tokens/ERC20.sol";
import {SafeTransferLib} from "solmate/src/utils/SafeTransferLib.sol";
import {SignatureVerification} from "../shared/SignatureVerification.sol";
import {SignatureVerification} from "./SignatureVerification.sol";
import {PermitHash} from "./libraries/PermitHash.sol";
import {EIP712} from "./EIP712.sol";

Expand Down
47 changes: 47 additions & 0 deletions src/ERC20/SignatureVerification.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import {IERC1271} from "./interfaces/IERC1271.sol";

library SignatureVerification {
/// @notice Thrown when the passed in signature is not a valid length
error InvalidSignatureLength();

/// @notice Thrown when the recovered signer is equal to the zero address
error InvalidSignature();

/// @notice Thrown when the recovered signer does not equal the claimedSigner
error InvalidSigner();

/// @notice Thrown when the recovered contract signature is incorrect
error InvalidContractSignature();

bytes32 constant UPPER_BIT_MASK = (0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);

function verify(bytes calldata signature, bytes32 hash, address claimedSigner) internal view {
bytes32 r;
bytes32 s;
uint8 v;

if (claimedSigner.code.length == 0) {
if (signature.length == 65) {
(r, s) = abi.decode(signature, (bytes32, bytes32));
v = uint8(signature[64]);
} else if (signature.length == 64) {
// EIP-2098
bytes32 vs;
(r, vs) = abi.decode(signature, (bytes32, bytes32));
s = vs & UPPER_BIT_MASK;
v = uint8(uint256(vs >> 255)) + 27;
} else {
revert InvalidSignatureLength();
}
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) revert InvalidSignature();
if (signer != claimedSigner) revert InvalidSigner();
} else {
bytes4 magicValue = IERC1271(claimedSigner).isValidSignature(hash, signature);
if (magicValue != IERC1271.isValidSignature.selector) revert InvalidContractSignature();
}
}
}
12 changes: 7 additions & 5 deletions src/ERC721/AllowanceTransferERC721.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
pragma solidity 0.8.18;

import {ERC721} from "solmate/src/tokens/ERC721.sol";
import {PermitHashERC721} from "./libraries/PermitHashERC721.sol";
import {SignatureVerification} from "../shared/SignatureVerification.sol";
import {SignatureVerification} from "../ERC721/SignatureVerification.sol";
import {EIP712ERC721} from "./EIP712ERC721.sol";
import {IAllowanceTransferERC721} from "./interfaces/IAllowanceTransferERC721.sol";
import {SignatureExpired, InvalidNonce} from "../shared/PermitErrors.sol";
import {SignatureExpired, InvalidNonce} from "./PermitErrors.sol";
import {AllowanceERC721} from "./libraries/AllowanceERC721.sol";

contract AllowanceTransferERC721 is IAllowanceTransferERC721, EIP712ERC721 {
Expand All @@ -19,12 +19,14 @@ contract AllowanceTransferERC721 is IAllowanceTransferERC721, EIP712ERC721 {
/// @notice Maps users to tokens to tokenId and information about the approval, including the approved spender, on the token
/// @dev Indexed in the order of token owner address, token address, and tokenId
/// @dev The stored word saves the allowed spender, expiration on the allowance, and nonce
mapping(address => mapping(address => mapping(uint256 => PackedAllowance))) public allowance;
mapping(address owner => mapping(address token => mapping(uint256 tokenId => PackedAllowance allowed))) public
allowance;

/// @notice Maps users to tokens to spender and sets whether or not the spender has operator status on an entire token collection.
/// @dev Indexed in the order of token owner address, token address, then spender address.
/// @dev Sets a timestamp at which the spender no longer has operator status. Max expiration is type(uint48).max
mapping(address => mapping(address => mapping(address => PackedOperatorAllowance))) public operators;
mapping(address owner => mapping(address token => mapping(address spender => PackedOperatorAllowance))) public
operators;

/// @inheritdoc IAllowanceTransferERC721
function approve(address token, address spender, uint256 tokenId, uint48 expiration) external {
Expand Down
2 changes: 1 addition & 1 deletion src/ERC721/EIP712ERC721.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
pragma solidity 0.8.18;

/// @notice EIP712 helpers for Permit2 for ERC721s
/// @dev Maintains cross-chain replay protection in the event of a fork
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ERC721/Permit2ERC721.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
pragma solidity 0.8.18;

import {SignatureTransferERC721} from "./SignatureTransferERC721.sol";
import {AllowanceTransferERC721} from "./AllowanceTransferERC721.sol";
Expand Down
11 changes: 11 additions & 0 deletions src/ERC721/PermitErrors.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;

/// @notice Shared errors between signature based transfers and allowance based transfers.

/// @notice Thrown when validating an inputted signature that is stale
/// @param signatureDeadline The timestamp at which a signature is no longer valid
error SignatureExpired(uint256 signatureDeadline);

/// @notice Thrown when validating that the inputted nonce has not been used
error InvalidNonce();
8 changes: 4 additions & 4 deletions src/ERC721/SignatureTransferERC721.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
pragma solidity 0.8.18;

import {ISignatureTransferERC721} from "./interfaces/ISignatureTransferERC721.sol";
import {SignatureExpired, InvalidNonce} from "../shared/PermitErrors.sol";
import {SignatureExpired, InvalidNonce} from "./PermitErrors.sol";
import {ERC721} from "solmate/src/tokens/ERC721.sol";
import {SafeTransferLib} from "solmate/src/utils/SafeTransferLib.sol";
import {SignatureVerification} from "../shared/SignatureVerification.sol";
import {SignatureVerification} from "../ERC721/SignatureVerification.sol";
import {PermitHashERC721} from "./libraries/PermitHashERC721.sol";
import {EIP712ERC721} from "./EIP712ERC721.sol";

Expand All @@ -15,7 +15,7 @@ contract SignatureTransferERC721 is ISignatureTransferERC721, EIP712ERC721 {
using PermitHashERC721 for PermitBatchTransferFrom;

/// @inheritdoc ISignatureTransferERC721
mapping(address => mapping(uint256 => uint256)) public nonceBitmap;
mapping(address owner => mapping(uint256 word => uint256 bitmap)) public nonceBitmap;

/// @inheritdoc ISignatureTransferERC721
function permitTransferFrom(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
pragma solidity ^0.8.18;

import {IERC1271} from "./IERC1271.sol";

Expand Down
2 changes: 1 addition & 1 deletion src/ERC721/interfaces/IAllowanceTransferERC721.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
pragma solidity ^0.8.18;

/// @title AllowanceTransfer
/// @notice Handles ERC721 token permissions through signature based allowance setting and ERC721 token transfers by checking stored permissions
Expand Down
2 changes: 1 addition & 1 deletion src/ERC721/interfaces/ISignatureTransferERC721.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
pragma solidity ^0.8.18;

/// @title SignatureTransfer
/// @notice Handles ERC721 token transfers through signature based actions
Expand Down
2 changes: 1 addition & 1 deletion src/ERC721/libraries/AllowanceERC721.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
pragma solidity ^0.8.18;

import {IAllowanceTransferERC721} from "../interfaces/IAllowanceTransferERC721.sol";

Expand Down
2 changes: 1 addition & 1 deletion src/ERC721/libraries/PermitHashERC721.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
pragma solidity ^0.8.18;

import {IAllowanceTransferERC721} from "../interfaces/IAllowanceTransferERC721.sol";
import {ISignatureTransferERC721} from "../interfaces/ISignatureTransferERC721.sol";
Expand Down
2 changes: 1 addition & 1 deletion test/AllowanceTransferInvariants.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "forge-std/Test.sol";
import {TokenProvider} from "./utils/TokenProvider.sol";
import {Permit2} from "../src/ERC20/Permit2.sol";
import {IAllowanceTransfer} from "../src/ERC20/interfaces/IAllowanceTransfer.sol";
import {SignatureVerification} from "../src/shared/SignatureVerification.sol";
import {SignatureVerification} from "../src/ERC20/SignatureVerification.sol";
import {PermitSignature} from "./utils/PermitSignature.sol";
import {InvariantTest} from "./utils/InvariantTest.sol";
import {MockERC20} from "./mocks/MockERC20.sol";
Expand Down
4 changes: 2 additions & 2 deletions test/AllowanceTransferTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import "forge-std/Test.sol";
import {TokenProvider} from "./utils/TokenProvider.sol";
import {Permit2} from "../src/ERC20/Permit2.sol";
import {PermitSignature} from "./utils/PermitSignature.sol";
import {SignatureVerification} from "../src/shared/SignatureVerification.sol";
import {SignatureVerification} from "../src/ERC20/SignatureVerification.sol";
import {AddressBuilder} from "./utils/AddressBuilder.sol";
import {StructBuilder} from "./utils/StructBuilder.sol";
import {AmountBuilder} from "./utils/AmountBuilder.sol";
import {AllowanceTransfer} from "../src/ERC20/AllowanceTransfer.sol";
import {SignatureExpired, InvalidNonce} from "../src/shared/PermitErrors.sol";
import {SignatureExpired, InvalidNonce} from "../src/ERC20/PermitErrors.sol";
import {IAllowanceTransfer} from "../src/ERC20/interfaces/IAllowanceTransfer.sol";
import {GasSnapshot} from "forge-gas-snapshot/GasSnapshot.sol";

Expand Down
6 changes: 3 additions & 3 deletions test/AllowanceTransferTestERC721.t.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
pragma solidity ^0.8.18;

import "forge-std/Test.sol";
import {TokenProvider} from "./utils/TokenProvider.sol";
import {Permit2ERC721} from "../src/ERC721/Permit2ERC721.sol";
import {PermitSignatureERC721} from "./utils/PermitSignatureERC721.sol";
import {SignatureVerification} from "../src/shared/SignatureVerification.sol";
import {SignatureVerification} from "../src/ERC20/SignatureVerification.sol";
import {AddressBuilder} from "./utils/AddressBuilder.sol";
import {StructBuilder} from "./utils/StructBuilder.sol";
import {AmountBuilder} from "./utils/AmountBuilder.sol";
import {AllowanceTransferERC721} from "../src/ERC721/AllowanceTransferERC721.sol";
import {SignatureExpired, InvalidNonce} from "../src/shared/PermitErrors.sol";
import {SignatureExpired, InvalidNonce} from "../src/ERC721/PermitErrors.sol";
import {IAllowanceTransferERC721} from "../src/ERC721/interfaces/IAllowanceTransferERC721.sol";
import {GasSnapshot} from "forge-gas-snapshot/GasSnapshot.sol";
import {MockERC721} from "./mocks/MockERC721.sol";
Expand Down
2 changes: 1 addition & 1 deletion test/Permit2Lib.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {MockPermit2Lib} from "./mocks/MockPermit2Lib.sol";
import {SafeCast160} from "../src/ERC20/libraries/SafeCast160.sol";
import {MockPermitWithSmallDS, MockPermitWithLargerDS} from "./mocks/MockPermitWithDS.sol";
import {MockNonPermitNonERC20WithDS} from "./mocks/MockNonPermitNonERC20WithDS.sol";
import {SignatureVerification} from "../src/shared/SignatureVerification.sol";
import {SignatureVerification} from "../src/ERC20/SignatureVerification.sol";
import {MockFallbackERC20} from "./mocks/MockFallbackERC20.sol";

contract Permit2LibTest is Test, PermitSignature, GasSnapshot {
Expand Down
4 changes: 2 additions & 2 deletions test/SignatureTransfer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.17;

import "forge-std/Test.sol";
import {SafeERC20, IERC20, IERC20Permit} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
import {SignatureVerification} from "../src/shared/SignatureVerification.sol";
import {SignatureVerification} from "../src/ERC20/SignatureVerification.sol";
import {TokenProvider} from "./utils/TokenProvider.sol";
import {PermitSignature} from "./utils/PermitSignature.sol";
import {AddressBuilder} from "./utils/AddressBuilder.sol";
Expand All @@ -13,7 +13,7 @@ import {Permit2} from "../src/ERC20/Permit2.sol";
import {SignatureTransfer} from "../src/ERC20/SignatureTransfer.sol";
import {GasSnapshot} from "forge-gas-snapshot/GasSnapshot.sol";
import {ISignatureTransfer} from "../src/ERC20/interfaces/ISignatureTransfer.sol";
import {InvalidNonce, SignatureExpired} from "../src/shared/PermitErrors.sol";
import {InvalidNonce, SignatureExpired} from "../src/ERC20/PermitErrors.sol";

contract SignatureTransferTest is Test, PermitSignature, TokenProvider, GasSnapshot {
using AddressBuilder for address[];
Expand Down
2 changes: 1 addition & 1 deletion test/TypehashGeneration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {ISignatureTransfer} from "../src/ERC20/interfaces/ISignatureTransfer.sol
import {MockSignatureVerification} from "./mocks/MockSignatureVerification.sol";
import {MockHash} from "./mocks/MockHash.sol";
import {AddressBuilder} from "./utils/AddressBuilder.sol";
import {SignatureVerification} from "../src/shared/SignatureVerification.sol";
import {SignatureVerification} from "../src/ERC20/SignatureVerification.sol";

contract TypehashGeneration is Test, PermitSignature {
using PermitHash for *;
Expand Down
106 changes: 53 additions & 53 deletions test/mocks/MockPermit2ERC721.sol
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
// // SPDX-License-Identifier: MIT
// pragma solidity ^0.8.17;

import {Permit2ERC721} from "../../src/ERC721/Permit2ERC721.sol";
import {IAllowanceTransferERC721} from "../../src/ERC721/interfaces/IAllowanceTransferERC721.sol";
import {SignatureTransferERC721} from "../../src/ERC721/SignatureTransferERC721.sol";
import {AllowanceERC721} from "../../src/ERC721/libraries/AllowanceERC721.sol";
import {IMockPermit2} from "../mocks/IMockPermit2.sol";
// import {Permit2ERC721} from "../../src/ERC721/Permit2ERC721.sol";
// import {IAllowanceTransferERC721} from "../../src/ERC721/interfaces/IAllowanceTransferERC721.sol";
// import {SignatureTransferERC721} from "../../src/ERC721/SignatureTransferERC721.sol";
// import {AllowanceERC721} from "../../src/ERC721/libraries/AllowanceERC721.sol";
// import {IMockPermit2} from "../mocks/IMockPermit2.sol";

contract MockPermit2ERC721 is IMockPermit2, Permit2ERC721 {
function doStore(address from, address token, address spender, uint256 tokenId, uint256 word) public override {
IAllowanceTransferERC721.PackedAllowance storage allowed = allowance[from][token][tokenId];
assembly {
sstore(allowed.slot, word)
}
}
// contract MockPermit2ERC721 is Permit2ERC721 {
// function doStore(address from, address token, address spender, uint256 tokenId, uint256 word) public override {
// IAllowanceTransferERC721.PackedAllowance storage allowed = allowance[from][token][tokenId];
// assembly {
// sstore(allowed.slot, word)
// }
// }

function getStore(address from, address token, address spender, uint256 tokenId)
public
view
override
returns (uint256 word)
{
IAllowanceTransferERC721.PackedAllowance storage allowed = allowance[from][token][tokenId];
assembly {
word := sload(allowed.slot)
}
}
// function getStore(address from, address token, address spender, uint256 tokenId)
// public
// view
// override
// returns (uint256 word)
// {
// IAllowanceTransferERC721.PackedAllowance storage allowed = allowance[from][token][tokenId];
// assembly {
// word := sload(allowed.slot)
// }
// }

function mockUpdateSome(
address from,
address token,
address spender,
uint160 updateData,
uint256 tokenId,
uint48 expiration
) public override {
// spender input unused in 721 case
IAllowanceTransferERC721.PackedAllowance storage allowed = allowance[from][token][tokenId];
AllowanceERC721.updateSpenderAndExpiration(allowed, address(updateData), expiration);
}
// function mockUpdateSome(
// address from,
// address token,
// address spender,
// uint160 updateData,
// uint256 tokenId,
// uint48 expiration
// ) public override {
// // spender input unused in 721 case
// IAllowanceTransferERC721.PackedAllowance storage allowed = allowance[from][token][tokenId];
// AllowanceERC721.updateSpenderAndExpiration(allowed, address(updateData), expiration);
// }

function mockUpdateAll(
address from,
address token,
address spender,
uint160 updateData,
uint256 tokenId,
uint48 expiration,
uint48 nonce
) public override {
IAllowanceTransferERC721.PackedAllowance storage allowed = allowance[from][token][tokenId];
AllowanceERC721.updateAll(allowed, address(updateData), expiration, nonce);
}
// function mockUpdateAll(
// address from,
// address token,
// address spender,
// uint160 updateData,
// uint256 tokenId,
// uint48 expiration,
// uint48 nonce
// ) public override {
// IAllowanceTransferERC721.PackedAllowance storage allowed = allowance[from][token][tokenId];
// AllowanceERC721.updateAll(allowed, address(updateData), expiration, nonce);
// }

function useUnorderedNonce(address from, uint256 nonce) public override {
_useUnorderedNonce(from, nonce);
}
}
// function useUnorderedNonce(address from, uint256 nonce) public override {
// _useUnorderedNonce(from, nonce);
// }
// }
2 changes: 1 addition & 1 deletion test/mocks/MockSignatureVerification.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import {SignatureVerification} from "../../src/shared/SignatureVerification.sol";
import {SignatureVerification} from "../../src/ERC20/SignatureVerification.sol";

contract MockSignatureVerification {
function verify(bytes calldata sig, bytes32 hashed, address signer) public view {
Expand Down
Loading