Commit 39c3b5b6 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

contracts: remove op-nft (#12950)

* contracts: remove op-nft

Remove the `op-nft` package from the contracts package. None of these
contracts are maintained and can be moved to another repo if necessary.
The purpose of this commit is to reduce compilation time. Less files
to compile means less compilation time.

* fix: semver lock step - ran pre-pr.

* fix: use added/modified filter for heavy fuzz

Updates the heavy fuzz filter for CI to only check for added or
modified contracts, now excluding deleted or moved contracts.

---------
Co-authored-by: default avatarBlaine Malone <blainemalone01@gmail.com>
Co-authored-by: default avatarKelvin Fichter <kelvinfichter@gmail.com>
parent f496b075
......@@ -1359,7 +1359,7 @@ workflows:
# Heavily fuzz any fuzz tests within added or modified test files.
name: contracts-bedrock-tests-heavy-fuzz-modified
test_parallelism: 1
test_list: git diff origin/develop...HEAD --name-only -- './test/**/*.t.sol' | sed 's|packages/contracts-bedrock/||'
test_list: git diff origin/develop...HEAD --name-only --diff-filter=AM -- './test/**/*.t.sol' | sed 's|packages/contracts-bedrock/||'
test_timeout: 1h
test_profile: ciheavy
- contracts-bedrock-coverage
......
[
{
"inputs": [
{
"components": [
{
"internalType": "address",
"name": "about",
"type": "address"
},
{
"internalType": "bytes32",
"name": "key",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "val",
"type": "bytes"
}
],
"internalType": "struct AttestationStation.AttestationData[]",
"name": "_attestations",
"type": "tuple[]"
}
],
"name": "attest",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_about",
"type": "address"
},
{
"internalType": "bytes32",
"name": "_key",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "_val",
"type": "bytes"
}
],
"name": "attest",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
},
{
"internalType": "address",
"name": "",
"type": "address"
},
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"name": "attestations",
"outputs": [
{
"internalType": "bytes",
"name": "",
"type": "bytes"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "version",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "creator",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "about",
"type": "address"
},
{
"indexed": true,
"internalType": "bytes32",
"name": "key",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "bytes",
"name": "val",
"type": "bytes"
}
],
"name": "AttestationCreated",
"type": "event"
}
]
\ No newline at end of file
This diff is collapsed.
[
{
"inputs": [
{
"internalType": "contract AttestationStation",
"name": "_attestationStation",
"type": "address"
},
{
"internalType": "address",
"name": "_allowlistAttestor",
"type": "address"
},
{
"internalType": "address",
"name": "_coinbaseQuestAttestor",
"type": "address"
},
{
"internalType": "address",
"name": "_optimistInviter",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "ALLOWLIST_ATTESTOR",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "ATTESTATION_STATION",
"outputs": [
{
"internalType": "contract AttestationStation",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "COINBASE_QUEST_ATTESTOR",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "COINBASE_QUEST_ELIGIBLE_ATTESTATION_KEY",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "OPTIMIST_CAN_MINT_ATTESTATION_KEY",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "OPTIMIST_INVITER",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_claimer",
"type": "address"
}
],
"name": "isAllowedToMint",
"outputs": [
{
"internalType": "bool",
"name": "allowed_",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "version",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
}
]
\ No newline at end of file
[
{
"inputs": [
{
"internalType": "address",
"name": "_inviteGranter",
"type": "address"
},
{
"internalType": "contract AttestationStation",
"name": "_attestationStation",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "ATTESTATION_STATION",
"outputs": [
{
"internalType": "contract AttestationStation",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "CAN_INVITE_ATTESTATION_KEY",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "CLAIMABLE_INVITE_TYPEHASH",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "EIP712_VERSION",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "INVITE_GRANTER",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "MIN_COMMITMENT_PERIOD",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_claimer",
"type": "address"
},
{
"components": [
{
"internalType": "address",
"name": "issuer",
"type": "address"
},
{
"internalType": "bytes32",
"name": "nonce",
"type": "bytes32"
}
],
"internalType": "struct OptimistInviter.ClaimableInvite",
"name": "_claimableInvite",
"type": "tuple"
},
{
"internalType": "bytes",
"name": "_signature",
"type": "bytes"
}
],
"name": "claimInvite",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "_commitment",
"type": "bytes32"
}
],
"name": "commitInvite",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"name": "commitmentTimestamps",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "_name",
"type": "string"
}
],
"name": "initialize",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "inviteCounts",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address[]",
"name": "_accounts",
"type": "address[]"
},
{
"internalType": "uint256",
"name": "_inviteCount",
"type": "uint256"
}
],
"name": "setInviteCounts",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
},
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"name": "usedNonces",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "version",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint8",
"name": "version",
"type": "uint8"
}
],
"name": "Initialized",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "issuer",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "claimer",
"type": "address"
}
],
"name": "InviteClaimed",
"type": "event"
}
]
\ No newline at end of file
......@@ -183,22 +183,6 @@
"initCodeHash": "0xefc6ed9e325c2d614ea0d28c3eabfff1b345f7c6054e90253c6a091c29508267",
"sourceCodeHash": "0xaa08a61448f485b277af57251d2089cc6a80ce0a763bf7184d48ffed5034ef69"
},
"src/periphery/op-nft/AttestationStation.sol": {
"initCodeHash": "0x2e665d9ee554430980f64bcb6d2611a1cb03dbacfd58bb0d6f5d32951a267bde",
"sourceCodeHash": "0xe0bc805b22c7d04b5a9444cddd4c0e1bcb3006c69c03610494277ab2cc83f553"
},
"src/periphery/op-nft/Optimist.sol": {
"initCodeHash": "0x8fccdef5fb6e6d51215b39acc449faad8ba15416699c9b3af77866f4297805a3",
"sourceCodeHash": "0xfa9354827b642803e10415ed30ca789be1bd23d88fac14f7adaa65c6eb1c1643"
},
"src/periphery/op-nft/OptimistAllowlist.sol": {
"initCodeHash": "0x166dd3fc18cb238895f2faa7fdd635af48ce2c54e21ed2d6dae857c3731c4d6c",
"sourceCodeHash": "0x3a5f61046f729c9a70274b8b2a739382987ec5eb77705b259e8a3210a5f43462"
},
"src/periphery/op-nft/OptimistInviter.sol": {
"initCodeHash": "0x28dfa6676702a7abd19609cc773158d1f958210bc0a38c008d67a002dc1df862",
"sourceCodeHash": "0x3a0a294932d6deba043f6a2b46b4e8477ee96e7fb054d7e7229a43ce4352c68d"
},
"src/safe/DeputyGuardianModule.sol": {
"initCodeHash": "0xd95e562f395d4eb6e332f4474dffab660ada9e9da7c79f58fb6052278e0904df",
"sourceCodeHash": "0x45daabe094de0287e244e6fea4f1887b9adc09b07c47dc77361b1678645a1470"
......
[
{
"bytes": "32",
"label": "attestations",
"offset": 0,
"slot": "0",
"type": "mapping(address => mapping(address => mapping(bytes32 => bytes)))"
}
]
\ No newline at end of file
[
{
"bytes": "1",
"label": "_initialized",
"offset": 0,
"slot": "0",
"type": "uint8"
},
{
"bytes": "1",
"label": "_initializing",
"offset": 1,
"slot": "0",
"type": "bool"
},
{
"bytes": "1600",
"label": "__gap",
"offset": 0,
"slot": "1",
"type": "uint256[50]"
},
{
"bytes": "1600",
"label": "__gap",
"offset": 0,
"slot": "51",
"type": "uint256[50]"
},
{
"bytes": "32",
"label": "_name",
"offset": 0,
"slot": "101",
"type": "string"
},
{
"bytes": "32",
"label": "_symbol",
"offset": 0,
"slot": "102",
"type": "string"
},
{
"bytes": "32",
"label": "_owners",
"offset": 0,
"slot": "103",
"type": "mapping(uint256 => address)"
},
{
"bytes": "32",
"label": "_balances",
"offset": 0,
"slot": "104",
"type": "mapping(address => uint256)"
},
{
"bytes": "32",
"label": "_tokenApprovals",
"offset": 0,
"slot": "105",
"type": "mapping(uint256 => address)"
},
{
"bytes": "32",
"label": "_operatorApprovals",
"offset": 0,
"slot": "106",
"type": "mapping(address => mapping(address => bool))"
},
{
"bytes": "1408",
"label": "__gap",
"offset": 0,
"slot": "107",
"type": "uint256[44]"
},
{
"bytes": "1600",
"label": "__gap",
"offset": 0,
"slot": "151",
"type": "uint256[50]"
}
]
\ No newline at end of file
[
{
"bytes": "1",
"label": "_initialized",
"offset": 0,
"slot": "0",
"type": "uint8"
},
{
"bytes": "1",
"label": "_initializing",
"offset": 1,
"slot": "0",
"type": "bool"
},
{
"bytes": "32",
"label": "_HASHED_NAME",
"offset": 0,
"slot": "1",
"type": "bytes32"
},
{
"bytes": "32",
"label": "_HASHED_VERSION",
"offset": 0,
"slot": "2",
"type": "bytes32"
},
{
"bytes": "1600",
"label": "__gap",
"offset": 0,
"slot": "3",
"type": "uint256[50]"
},
{
"bytes": "32",
"label": "commitmentTimestamps",
"offset": 0,
"slot": "53",
"type": "mapping(bytes32 => uint256)"
},
{
"bytes": "32",
"label": "usedNonces",
"offset": 0,
"slot": "54",
"type": "mapping(address => mapping(bytes32 => bool))"
},
{
"bytes": "32",
"label": "inviteCounts",
"offset": 0,
"slot": "55",
"type": "mapping(address => uint256)"
}
]
\ No newline at end of file
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import { ISemver } from "src/universal/interfaces/ISemver.sol";
/// @title AttestationStation
/// @author Optimism Collective
/// @author Gitcoin
/// @notice Where attestations live.
contract AttestationStation is ISemver {
/// @notice Struct representing data that is being attested.
/// @custom:field about Address for which the attestation is about.
/// @custom:field key A bytes32 key for the attestation.
/// @custom:field val The attestation as arbitrary bytes.
struct AttestationData {
address about;
bytes32 key;
bytes val;
}
/// @notice Maps addresses to attestations. Creator => About => Key => Value.
mapping(address => mapping(address => mapping(bytes32 => bytes))) public attestations;
/// @notice Emitted when Attestation is created.
/// @param creator Address that made the attestation.
/// @param about Address attestation is about.
/// @param key Key of the attestation.
/// @param val Value of the attestation.
event AttestationCreated(address indexed creator, address indexed about, bytes32 indexed key, bytes val);
/// @notice Semantic version.
/// @custom:semver 1.2.1-beta.1
string public constant version = "1.2.1-beta.1";
/// @notice Allows anyone to create an attestation.
/// @param _about Address that the attestation is about.
/// @param _key A key used to namespace the attestation.
/// @param _val An arbitrary value stored as part of the attestation.
function attest(address _about, bytes32 _key, bytes memory _val) public {
attestations[msg.sender][_about][_key] = _val;
emit AttestationCreated(msg.sender, _about, _key, _val);
}
/// @notice Allows anyone to create attestations.
/// @param _attestations An array of AttestationData structs.
function attest(AttestationData[] calldata _attestations) external {
uint256 length = _attestations.length;
for (uint256 i = 0; i < length;) {
AttestationData memory attestation = _attestations[i];
attest(attestation.about, attestation.key, attestation.val);
unchecked {
++i;
}
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import { ISemver } from "src/universal/interfaces/ISemver.sol";
import { ERC721BurnableUpgradeable } from
"@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721BurnableUpgradeable.sol";
import { AttestationStation } from "src/periphery/op-nft/AttestationStation.sol";
import { OptimistAllowlist } from "src/periphery/op-nft/OptimistAllowlist.sol";
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
/// @author Optimism Collective
/// @author Gitcoin
/// @title Optimist
/// @notice A Soul Bound Token for real humans only(tm).
contract Optimist is ERC721BurnableUpgradeable, ISemver {
/// @notice Attestation key used by the attestor to attest the baseURI.
bytes32 public constant BASE_URI_ATTESTATION_KEY = bytes32("optimist.base-uri");
/// @notice Attestor who attests to baseURI.
address public immutable BASE_URI_ATTESTOR;
/// @notice Address of the AttestationStation contract.
AttestationStation public immutable ATTESTATION_STATION;
/// @notice Address of the OptimistAllowlist contract.
OptimistAllowlist public immutable OPTIMIST_ALLOWLIST;
/// @notice Semantic version.
/// @custom:semver 2.1.1-beta.1
string public constant version = "2.1.1-beta.1";
/// @param _name Token name.
/// @param _symbol Token symbol.
/// @param _baseURIAttestor Address of the baseURI attestor.
/// @param _attestationStation Address of the AttestationStation contract.
/// @param _optimistAllowlist Address of the OptimistAllowlist contract
constructor(
string memory _name,
string memory _symbol,
address _baseURIAttestor,
AttestationStation _attestationStation,
OptimistAllowlist _optimistAllowlist
) {
BASE_URI_ATTESTOR = _baseURIAttestor;
ATTESTATION_STATION = _attestationStation;
OPTIMIST_ALLOWLIST = _optimistAllowlist;
initialize(_name, _symbol);
}
/// @notice Initializes the Optimist contract.
/// @param _name Token name.
/// @param _symbol Token symbol.
function initialize(string memory _name, string memory _symbol) public initializer {
__ERC721_init(_name, _symbol);
__ERC721Burnable_init();
}
/// @notice Allows an address to mint an Optimist NFT. Token ID is the uint256 representation
/// of the recipient's address. Recipients must be permitted to mint, eventually anyone
/// will be able to mint. One token per address.
/// @param _recipient Address of the token recipient.
function mint(address _recipient) public {
require(isOnAllowList(_recipient), "Optimist: address is not on allowList");
_safeMint(_recipient, tokenIdOfAddress(_recipient));
}
/// @notice Returns the baseURI for all tokens.
/// @return uri_ BaseURI for all tokens.
function baseURI() public view returns (string memory uri_) {
uri_ = string(
abi.encodePacked(
ATTESTATION_STATION.attestations(BASE_URI_ATTESTOR, address(this), bytes32("optimist.base-uri"))
)
);
}
/// @notice Returns the token URI for a given token by ID
/// @param _tokenId Token ID to query.
/// @return uri_ Token URI for the given token by ID.
function tokenURI(uint256 _tokenId) public view virtual override returns (string memory uri_) {
uri_ = string(
abi.encodePacked(
baseURI(),
"/",
// Properly format the token ID as a 20 byte hex string (address).
Strings.toHexString(_tokenId, 20),
".json"
)
);
}
/// @notice Checks OptimistAllowlist to determine whether a given address is allowed to mint
/// the Optimist NFT. Since the Optimist NFT will also be used as part of the
/// Citizens House, mints are currently restricted. Eventually anyone will be able
/// to mint.
/// @return allowed_ Whether or not the address is allowed to mint yet.
function isOnAllowList(address _recipient) public view returns (bool allowed_) {
allowed_ = OPTIMIST_ALLOWLIST.isAllowedToMint(_recipient);
}
/// @notice Returns the token ID for the token owned by a given address. This is the uint256
/// representation of the given address.
/// @return Token ID for the token owned by the given address.
function tokenIdOfAddress(address _owner) public pure returns (uint256) {
return uint256(uint160(_owner));
}
/// @notice Disabled for the Optimist NFT (Soul Bound Token).
function approve(address, uint256) public pure override {
revert("Optimist: soul bound token");
}
/// @notice Disabled for the Optimist NFT (Soul Bound Token).
function setApprovalForAll(address, bool) public virtual override {
revert("Optimist: soul bound token");
}
/// @notice Prevents transfers of the Optimist NFT (Soul Bound Token).
/// @param _from Address of the token sender.
/// @param _to Address of the token recipient.
function _beforeTokenTransfer(address _from, address _to, uint256) internal virtual override {
require(_from == address(0) || _to == address(0), "Optimist: soul bound token");
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import { ISemver } from "src/universal/interfaces/ISemver.sol";
import { AttestationStation } from "src/periphery/op-nft/AttestationStation.sol";
import { OptimistConstants } from "src/periphery/op-nft/libraries/OptimistConstants.sol";
/// @title OptimistAllowlist
/// @notice Source of truth for whether an address is able to mint an Optimist NFT.
/// isAllowedToMint function checks various signals to return boolean value
/// for whether an address is eligible or not.
contract OptimistAllowlist is ISemver {
/// @notice Attestation key used by the AllowlistAttestor to manually add addresses to the
/// allowlist.
bytes32 public constant OPTIMIST_CAN_MINT_ATTESTATION_KEY = bytes32("optimist.can-mint");
/// @notice Attestation key used by Coinbase to issue attestations for Quest participants.
bytes32 public constant COINBASE_QUEST_ELIGIBLE_ATTESTATION_KEY = bytes32("coinbase.quest-eligible");
/// @notice Address of the AttestationStation contract.
AttestationStation public immutable ATTESTATION_STATION;
/// @notice Attestor that issues 'optimist.can-mint' attestations.
address public immutable ALLOWLIST_ATTESTOR;
/// @notice Attestor that issues 'coinbase.quest-eligible' attestations.
address public immutable COINBASE_QUEST_ATTESTOR;
/// @notice Address of OptimistInviter contract that issues 'optimist.can-mint-from-invite'
/// attestations.
address public immutable OPTIMIST_INVITER;
/// @notice Semantic version.
/// @custom:semver 1.1.1-beta.1
string public constant version = "1.1.1-beta.1";
/// @param _attestationStation Address of the AttestationStation contract.
/// @param _allowlistAttestor Address of the allowlist attestor.
/// @param _coinbaseQuestAttestor Address of the Coinbase Quest attestor.
/// @param _optimistInviter Address of the OptimistInviter contract.
constructor(
AttestationStation _attestationStation,
address _allowlistAttestor,
address _coinbaseQuestAttestor,
address _optimistInviter
) {
ATTESTATION_STATION = _attestationStation;
ALLOWLIST_ATTESTOR = _allowlistAttestor;
COINBASE_QUEST_ATTESTOR = _coinbaseQuestAttestor;
OPTIMIST_INVITER = _optimistInviter;
}
/// @notice Checks whether a given address is allowed to mint the Optimist NFT yet. Since the
/// Optimist NFT will also be used as part of the Citizens House, mints are currently
/// restricted. Eventually anyone will be able to mint.
/// Currently, address is allowed to mint if it satisfies any of the following:
/// 1) Has a valid 'optimist.can-mint' attestation from the allowlist attestor.
/// 2) Has a valid 'coinbase.quest-eligible' attestation from Coinbase Quest attestor
/// 3) Has a valid 'optimist.can-mint-from-invite' attestation from the OptimistInviter
/// contract.
/// @param _claimer Address to check.
/// @return allowed_ Whether or not the address is allowed to mint yet.
function isAllowedToMint(address _claimer) public view returns (bool allowed_) {
allowed_ = _hasAttestationFromAllowlistAttestor(_claimer) || _hasAttestationFromCoinbaseQuestAttestor(_claimer)
|| _hasAttestationFromOptimistInviter(_claimer);
}
/// @notice Checks whether an address has a valid 'optimist.can-mint' attestation from the
/// allowlist attestor.
/// @param _claimer Address to check.
/// @return valid_ Whether or not the address has a valid attestation.
function _hasAttestationFromAllowlistAttestor(address _claimer) internal view returns (bool valid_) {
// Expected attestation value is bytes32("true")
valid_ = _hasValidAttestation(ALLOWLIST_ATTESTOR, _claimer, OPTIMIST_CAN_MINT_ATTESTATION_KEY);
}
/// @notice Checks whether an address has a valid attestation from the Coinbase attestor.
/// @param _claimer Address to check.
/// @return valid_ Whether or not the address has a valid attestation.
function _hasAttestationFromCoinbaseQuestAttestor(address _claimer) internal view returns (bool valid_) {
// Expected attestation value is bytes32("true")
valid_ = _hasValidAttestation(COINBASE_QUEST_ATTESTOR, _claimer, COINBASE_QUEST_ELIGIBLE_ATTESTATION_KEY);
}
/// @notice Checks whether an address has a valid attestation from the OptimistInviter contract.
/// @param _claimer Address to check.
/// @return valid_ Whether or not the address has a valid attestation.
function _hasAttestationFromOptimistInviter(address _claimer) internal view returns (bool valid_) {
// Expected attestation value is the inviter's address
valid_ = _hasValidAttestation(
OPTIMIST_INVITER, _claimer, OptimistConstants.OPTIMIST_CAN_MINT_FROM_INVITE_ATTESTATION_KEY
);
}
/// @notice Checks whether an address has a valid truthy attestation.
/// Any attestation val other than bytes32("") is considered truthy.
/// @param _creator Address that made the attestation.
/// @param _about Address attestation is about.
/// @param _key Key of the attestation.
/// @return valid_ Whether or not the address has a valid truthy attestation.
function _hasValidAttestation(address _creator, address _about, bytes32 _key) internal view returns (bool valid_) {
valid_ = ATTESTATION_STATION.attestations(_creator, _about, _key).length > 0;
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
/// @title OptimistConstants
/// @notice Library for storing Optimist related constants that are shared in multiple contracts.
library OptimistConstants {
/// @notice Attestation key issued by OptimistInviter allowing the attested account to mint.
bytes32 internal constant OPTIMIST_CAN_MINT_FROM_INVITE_ATTESTATION_KEY = bytes32("optimist.can-mint-from-invite");
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { OptimistInviter } from "src/periphery/op-nft/OptimistInviter.sol";
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
/// @notice Simple helper contract that helps with testing flow and signature for
/// OptimistInviter contract. Made this a separate contract instead of including
/// in OptimistInviter.t.sol for reusability.
contract OptimistInviterHelper {
/// @notice EIP712 typehash for the ClaimableInvite type.
bytes32 public constant CLAIMABLE_INVITE_TYPEHASH = keccak256("ClaimableInvite(address issuer,bytes32 nonce)");
/// @notice EIP712 typehash for the EIP712Domain type that is included as part of the signature.
bytes32 public constant EIP712_DOMAIN_TYPEHASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
/// @notice Address of OptimistInviter contract we are testing.
OptimistInviter public optimistInviter;
/// @notice OptimistInviter contract name. Used to construct the EIP-712 domain.
string public name;
/// @notice Keeps track of current nonce to generate new nonces for each invite.
uint256 public currentNonce;
constructor(OptimistInviter _optimistInviter, string memory _name) {
optimistInviter = _optimistInviter;
name = _name;
}
/// @notice Returns the hash of the struct ClaimableInvite.
/// @param _claimableInvite ClaimableInvite struct to hash.
/// @return EIP-712 typed struct hash.
function getClaimableInviteStructHash(OptimistInviter.ClaimableInvite memory _claimableInvite)
public
pure
returns (bytes32)
{
return keccak256(abi.encode(CLAIMABLE_INVITE_TYPEHASH, _claimableInvite.issuer, _claimableInvite.nonce));
}
/// @notice Returns a bytes32 nonce that should change everytime. In practice, people should use
/// pseudorandom nonces.
/// @return Nonce that should be used as part of ClaimableInvite.
function consumeNonce() public returns (bytes32) {
return bytes32(keccak256(abi.encode(currentNonce++)));
}
/// @notice Returns a ClaimableInvite with the issuer and current nonce.
/// @param _issuer Issuer to include in the ClaimableInvite.
/// @return ClaimableInvite that can be hashed & signed.
function getClaimableInviteWithNewNonce(address _issuer) public returns (OptimistInviter.ClaimableInvite memory) {
return OptimistInviter.ClaimableInvite(_issuer, consumeNonce());
}
/// @notice Computes the EIP712 digest with default correct parameters.
/// @param _claimableInvite ClaimableInvite struct to hash.
/// @return EIP-712 compatible digest.
function getDigest(OptimistInviter.ClaimableInvite calldata _claimableInvite) public view returns (bytes32) {
return getDigestWithEIP712Domain(
_claimableInvite,
bytes(name),
bytes(optimistInviter.EIP712_VERSION()),
block.chainid,
address(optimistInviter)
);
}
/// @notice Computes the EIP712 digest with the given domain parameters.
/// Used for testing that different domain parameters fail.
/// @param _claimableInvite ClaimableInvite struct to hash.
/// @param _name Contract name to use in the EIP712 domain.
/// @param _version Contract version to use in the EIP712 domain.
/// @param _chainid Chain ID to use in the EIP712 domain.
/// @param _verifyingContract Address to use in the EIP712 domain.
/// @return EIP-712 compatible digest.
function getDigestWithEIP712Domain(
OptimistInviter.ClaimableInvite calldata _claimableInvite,
bytes memory _name,
bytes memory _version,
uint256 _chainid,
address _verifyingContract
)
public
pure
returns (bytes32)
{
bytes32 domainSeparator = keccak256(
abi.encode(EIP712_DOMAIN_TYPEHASH, keccak256(_name), keccak256(_version), _chainid, _verifyingContract)
);
return ECDSA.toTypedDataHash(domainSeparator, getClaimableInviteStructHash(_claimableInvite));
}
}
//SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
/* Testing utilities */
import { Test } from "forge-std/Test.sol";
import { AttestationStation } from "src/periphery/op-nft/AttestationStation.sol";
contract AttestationStation_Initializer is Test {
address alice_attestor = address(128);
address bob = address(256);
address sally = address(512);
function setUp() public {
// Give alice and bob some ETH
vm.deal(alice_attestor, 1 ether);
vm.label(alice_attestor, "alice_attestor");
vm.label(bob, "bob");
vm.label(sally, "sally");
}
}
contract AttestationStationTest is AttestationStation_Initializer {
event AttestationCreated(address indexed creator, address indexed about, bytes32 indexed key, bytes val);
function test_attest_individual_succeeds() external {
AttestationStation attestationStation = new AttestationStation();
vm.expectEmit(true, true, true, true);
emit AttestationCreated(alice_attestor, bob, bytes32("foo"), bytes("bar"));
vm.prank(alice_attestor);
attestationStation.attest({ _about: bob, _key: bytes32("foo"), _val: bytes("bar") });
}
function test_attest_single_succeeds() external {
AttestationStation attestationStation = new AttestationStation();
AttestationStation.AttestationData[] memory attestationDataArr = new AttestationStation.AttestationData[](1);
// alice is going to attest about bob
AttestationStation.AttestationData memory attestationData = AttestationStation.AttestationData({
about: bob,
key: bytes32("test-key:string"),
val: bytes("test-value")
});
// assert the attestation starts empty
assertEq(attestationStation.attestations(alice_attestor, attestationData.about, attestationData.key), "");
// make attestation
vm.prank(alice_attestor);
attestationDataArr[0] = attestationData;
attestationStation.attest(attestationDataArr);
// assert the attestation is there
assertEq(
attestationStation.attestations(alice_attestor, attestationData.about, attestationData.key),
attestationData.val
);
bytes memory new_val = bytes("new updated value");
// make a new attestations to same about and key
attestationData =
AttestationStation.AttestationData({ about: attestationData.about, key: attestationData.key, val: new_val });
vm.prank(alice_attestor);
attestationDataArr[0] = attestationData;
attestationStation.attest(attestationDataArr);
// assert the attestation is updated
assertEq(
attestationStation.attestations(alice_attestor, attestationData.about, attestationData.key),
attestationData.val
);
}
function test_attest_bulk_succeeds() external {
AttestationStation attestationStation = new AttestationStation();
vm.prank(alice_attestor);
AttestationStation.AttestationData[] memory attestationData = new AttestationStation.AttestationData[](3);
attestationData[0] = AttestationStation.AttestationData({
about: bob,
key: bytes32("test-key:string"),
val: bytes("test-value")
});
attestationData[1] =
AttestationStation.AttestationData({ about: bob, key: bytes32("test-key2"), val: bytes("test-value2") });
attestationData[2] = AttestationStation.AttestationData({
about: sally,
key: bytes32("test-key:string"),
val: bytes("test-value3")
});
attestationStation.attest(attestationData);
// assert the attestations are there
assertEq(
attestationStation.attestations(alice_attestor, attestationData[0].about, attestationData[0].key),
attestationData[0].val
);
assertEq(
attestationStation.attestations(alice_attestor, attestationData[1].about, attestationData[1].key),
attestationData[1].val
);
assertEq(
attestationStation.attestations(alice_attestor, attestationData[2].about, attestationData[2].key),
attestationData[2].val
);
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
// Testing utilities
import { Test } from "forge-std/Test.sol";
import { AttestationStation } from "src/periphery/op-nft/AttestationStation.sol";
import { OptimistAllowlist } from "src/periphery/op-nft/OptimistAllowlist.sol";
import { OptimistInviter } from "src/periphery/op-nft/OptimistInviter.sol";
import { OptimistInviterHelper } from "test/mocks/OptimistInviterHelper.sol";
import { OptimistConstants } from "src/periphery/op-nft/libraries/OptimistConstants.sol";
contract OptimistAllowlist_Initializer is Test {
event AttestationCreated(address indexed creator, address indexed about, bytes32 indexed key, bytes val);
address internal alice_allowlistAttestor;
address internal sally_coinbaseQuestAttestor;
address internal ted;
uint256 internal bobPrivateKey;
address internal bob;
AttestationStation attestationStation;
OptimistAllowlist optimistAllowlist;
OptimistInviter optimistInviter;
// Helps with EIP-712 signature generation
OptimistInviterHelper optimistInviterHelper;
function setUp() public {
alice_allowlistAttestor = makeAddr("alice_allowlistAttestor");
sally_coinbaseQuestAttestor = makeAddr("sally_coinbaseQuestAttestor");
ted = makeAddr("ted");
bobPrivateKey = 0xB0B0B0B0;
bob = vm.addr(bobPrivateKey);
vm.label(bob, "bob");
// Give alice and bob and sally some ETH
vm.deal(alice_allowlistAttestor, 1 ether);
vm.deal(sally_coinbaseQuestAttestor, 1 ether);
vm.deal(bob, 1 ether);
vm.deal(ted, 1 ether);
_initializeContracts();
}
function attestAllowlist(address _about) internal {
AttestationStation.AttestationData[] memory attestationData = new AttestationStation.AttestationData[](1);
// we are using true but it can be any non empty value
attestationData[0] = AttestationStation.AttestationData({
about: _about,
key: optimistAllowlist.OPTIMIST_CAN_MINT_ATTESTATION_KEY(),
val: bytes("true")
});
vm.prank(alice_allowlistAttestor);
attestationStation.attest(attestationData);
}
function attestCoinbaseQuest(address _about) internal {
AttestationStation.AttestationData[] memory attestationData = new AttestationStation.AttestationData[](1);
// we are using true but it can be any non empty value
attestationData[0] = AttestationStation.AttestationData({
about: _about,
key: optimistAllowlist.COINBASE_QUEST_ELIGIBLE_ATTESTATION_KEY(),
val: bytes("true")
});
vm.prank(sally_coinbaseQuestAttestor);
attestationStation.attest(attestationData);
}
function inviteAndClaim(address claimer) internal {
address[] memory addresses = new address[](1);
addresses[0] = bob;
vm.prank(alice_allowlistAttestor);
// grant invites to Bob;
optimistInviter.setInviteCounts(addresses, 3);
// issue a new invite
OptimistInviter.ClaimableInvite memory claimableInvite =
optimistInviterHelper.getClaimableInviteWithNewNonce(bob);
// EIP-712 sign with Bob's private key
bytes memory signature = _getSignature(bobPrivateKey, optimistInviterHelper.getDigest(claimableInvite));
bytes32 hashedCommit = keccak256(abi.encode(claimer, signature));
// commit the invite
vm.prank(claimer);
optimistInviter.commitInvite(hashedCommit);
// wait minimum commitment period
vm.warp(optimistInviter.MIN_COMMITMENT_PERIOD() + block.timestamp);
// reveal and claim the invite
optimistInviter.claimInvite(claimer, claimableInvite, signature);
}
/// @notice Get signature as a bytes blob, since SignatureChecker takes arbitrary signature blobs.
function _getSignature(uint256 _signingPrivateKey, bytes32 _digest) internal pure returns (bytes memory) {
(uint8 v, bytes32 r, bytes32 s) = vm.sign(_signingPrivateKey, _digest);
bytes memory signature = abi.encodePacked(r, s, v);
return signature;
}
function _initializeContracts() internal {
attestationStation = new AttestationStation();
optimistInviter = new OptimistInviter(alice_allowlistAttestor, attestationStation);
optimistInviter.initialize("OptimistInviter");
optimistAllowlist = new OptimistAllowlist(
attestationStation, alice_allowlistAttestor, sally_coinbaseQuestAttestor, address(optimistInviter)
);
optimistInviterHelper = new OptimistInviterHelper(optimistInviter, "OptimistInviter");
}
}
contract OptimistAllowlistTest is OptimistAllowlist_Initializer {
function test_constructor_succeeds() external view {
// expect attestationStation to be set
assertEq(address(optimistAllowlist.ATTESTATION_STATION()), address(attestationStation));
assertEq(optimistAllowlist.ALLOWLIST_ATTESTOR(), alice_allowlistAttestor);
assertEq(optimistAllowlist.COINBASE_QUEST_ATTESTOR(), sally_coinbaseQuestAttestor);
assertEq(address(optimistAllowlist.OPTIMIST_INVITER()), address(optimistInviter));
}
/// @notice Base case, a account without any relevant attestations should not be able to mint.
function test_isAllowedToMint_withoutAnyAttestations_fails() external view {
assertFalse(optimistAllowlist.isAllowedToMint(bob));
}
/// @notice After receiving a valid allowlist attestation, the account should be able to mint.
function test_isAllowedToMint_fromAllowlistAttestor_succeeds() external {
attestAllowlist(bob);
assertTrue(optimistAllowlist.isAllowedToMint(bob));
}
/// @notice After receiving a valid attestation from the Coinbase Quest attestor,
/// the account should be able to mint.
function test_isAllowedToMint_fromCoinbaseQuestAttestor_succeeds() external {
attestCoinbaseQuest(bob);
assertTrue(optimistAllowlist.isAllowedToMint(bob));
}
/// @notice Account that received an attestation from the OptimistInviter contract by going
/// through the claim invite flow should be able to mint.
function test_isAllowedToMint_fromInvite_succeeds() external {
inviteAndClaim(bob);
assertTrue(optimistAllowlist.isAllowedToMint(bob));
}
/// @notice Attestation from the wrong allowlist attestor should not allow minting.
function test_isAllowedToMint_fromWrongAllowlistAttestor_fails() external {
// Ted is not the allowlist attestor
vm.prank(ted);
attestationStation.attest(bob, optimistAllowlist.OPTIMIST_CAN_MINT_ATTESTATION_KEY(), bytes("true"));
assertFalse(optimistAllowlist.isAllowedToMint(bob));
}
/// @notice Coinbase quest attestation from wrong attestor should not allow minting.
function test_isAllowedToMint_fromWrongCoinbaseQuestAttestor_fails() external {
// Ted is not the coinbase quest attestor
vm.prank(ted);
attestationStation.attest(bob, optimistAllowlist.COINBASE_QUEST_ELIGIBLE_ATTESTATION_KEY(), bytes("true"));
assertFalse(optimistAllowlist.isAllowedToMint(bob));
}
/// @notice Claiming an invite on the non-official OptimistInviter contract should not allow
/// minting.
function test_isAllowedToMint_fromWrongOptimistInviter_fails() external {
vm.prank(ted);
attestationStation.attest(bob, OptimistConstants.OPTIMIST_CAN_MINT_FROM_INVITE_ATTESTATION_KEY, bytes("true"));
assertFalse(optimistAllowlist.isAllowedToMint(bob));
}
/// @notice Having multiple signals, even if one is invalid, should still allow minting.
function test_isAllowedToMint_withMultipleAttestations_succeeds() external {
attestAllowlist(bob);
attestCoinbaseQuest(bob);
inviteAndClaim(bob);
assertTrue(optimistAllowlist.isAllowedToMint(bob));
// A invalid attestation, as Ted is not allowlist attestor
vm.prank(ted);
attestationStation.attest(bob, optimistAllowlist.OPTIMIST_CAN_MINT_ATTESTATION_KEY(), bytes("true"));
// Since Bob has at least one valid attestation, he should be allowed to mint
assertTrue(optimistAllowlist.isAllowedToMint(bob));
}
/// @notice Having falsy attestation value should not allow minting.
function test_isAllowedToMint_fromAllowlistAttestorWithFalsyValue_fails() external {
// First sends correct attestation
attestAllowlist(bob);
bytes32 key = optimistAllowlist.OPTIMIST_CAN_MINT_ATTESTATION_KEY();
vm.expectEmit(true, true, true, false);
emit AttestationCreated(alice_allowlistAttestor, bob, key, bytes("dsafsds"));
// Invalidates existing attestation
vm.prank(alice_allowlistAttestor);
attestationStation.attest(bob, key, bytes(""));
assertFalse(optimistAllowlist.isAllowedToMint(bob));
}
/// @notice Having falsy attestation value from Coinbase attestor should not allow minting.
function test_isAllowedToMint_fromCoinbaseQuestAttestorWithFalsyValue_fails() external {
// First sends correct attestation
attestAllowlist(bob);
bytes32 key = optimistAllowlist.OPTIMIST_CAN_MINT_ATTESTATION_KEY();
vm.expectEmit(true, true, true, true);
emit AttestationCreated(alice_allowlistAttestor, bob, key, bytes(""));
// Invalidates existing attestation
vm.prank(alice_allowlistAttestor);
attestationStation.attest(bob, key, bytes(""));
assertFalse(optimistAllowlist.isAllowedToMint(bob));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment