Commit 87bd4f55 authored by mergify[bot]'s avatar mergify[bot] Committed by GitHub

Merge pull request #4361 from ethereum-optimism/willc/deps

feat(contracts-periphery): Add attestation contract
parents 0899b340 c63f41bf
---
'@eth-optimism/contracts-periphery': patch
---
Add attestation contracts
//SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
/* Testing utilities */
import { Test } from "forge-std/Test.sol";
import { TestERC20 } from "../testing/helpers/TestERC20.sol";
import { TestERC721 } from "../testing/helpers/TestERC721.sol";
import { AssetReceiver } from "../universal/AssetReceiver.sol";
import { AttestationStation } from "../universal/op-nft/AttestationStation.sol";
contract AssetReceiver_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 AssetReceiverTest is AssetReceiver_Initializer {
function setUp() public {
super._setUp();
}
function test_attest_single() 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(
attestationData.about,
attestationData.key,
attestationData.val
),
""
);
// 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() 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;
import { Semver } from "@eth-optimism/contracts-bedrock/contracts/universal/Semver.sol";
/**
* @title AttestationStation
* @dev Contract for creating attestations.
* @notice The AttestationStation contract is a contract for creating on chain attestations
* It has a very simple interface for creating attestations.
* This contract is not yet audited
*/
contract AttestationStation is Semver {
/**
* @notice Struct representing data that is being attested
*
* @custom:field about Address being attested about (not creator/msg.sender)
* @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
* @dev addresses map to attestations map of
* about addresses to key/values
* key/values are a map of bytes32 to bytes
*/
mapping(address => mapping(address => mapping(bytes32 => bytes))) public attestations;
/**
* @notice Emitted when Attestation is created
*
* @param creator Address that attested.
* @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
);
constructor() Semver(0, 0, 1) {}
/**
* @notice Attest to the given data.
* @dev Attests to the given data from the sender.
* @param _attestations The array of attestation data.
*/
function attest(AttestationData[] memory _attestations) public {
uint256 length = _attestations.length;
for (uint256 i = 0; i < length; ) {
AttestationData memory attestation = _attestations[i];
attestations[msg.sender][attestation.about][attestation.key] = attestation.val;
emit AttestationCreated(
msg.sender,
attestation.about,
attestation.key,
attestation.val
);
unchecked {
++i;
}
}
}
}
......@@ -15,7 +15,9 @@ optimizer_runs = 200
remappings = [
'@rari-capital/solmate/=node_modules/@rari-capital/solmate',
'forge-std/=node_modules/forge-std/src',
'ds-test/=node_modules/ds-test/src'
'ds-test/=node_modules/ds-test/src',
'@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/',
'@eth-optimism/contracts-bedrock/=node_modules/@eth-optimism/contracts-bedrock',
]
# The metadata hash can be removed from the bytecode by setting "none"
bytecode_hash = "none"
......@@ -55,7 +55,7 @@
"devDependencies": {
"@defi-wonderland/smock": "^2.0.7",
"@eth-optimism/contracts": "^0.5.39",
"@eth-optimism/contracts-bedrock": "^0.11.0",
"@eth-optimism/contracts-bedrock": "0.10.0",
"@eth-optimism/core-utils": "^0.12.0",
"@eth-optimism/hardhat-deploy-config": "^0.2.5",
"@ethersproject/hardware-wallets": "^5.7.0",
......@@ -64,7 +64,6 @@
"@nomiclabs/hardhat-waffle": "^2.0.3",
"@rari-capital/solmate": "7.0.0-alpha.3",
"@openzeppelin/contracts": "4.6.0",
"@openzeppelin/contracts-upgradeable": "4.7.1",
"@types/chai": "^4.2.18",
"@types/mocha": "^8.2.2",
"@types/node": "^17.0.21",
......
This diff is collapsed.
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