Commit a22f52b0 authored by Andreas Bigger's avatar Andreas Bigger

Port EAS contracts to triple slash natspec styling

parent 15460387
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
// A representation of an empty/uninitialized UID. // A representation of an empty/uninitialized UID.
...@@ -14,18 +13,14 @@ error InvalidLength(); ...@@ -14,18 +13,14 @@ error InvalidLength();
error InvalidSignature(); error InvalidSignature();
error NotFound(); error NotFound();
/** /// @dev A struct representing EIP712 signature data.
* @dev A struct representing EIP712 signature data.
*/
struct EIP712Signature { struct EIP712Signature {
uint8 v; // The recovery ID. uint8 v; // The recovery ID.
bytes32 r; // The x-coordinate of the nonce R. bytes32 r; // The x-coordinate of the nonce R.
bytes32 s; // The signature data. bytes32 s; // The signature data.
} }
/** /// @dev A struct representing a single attestation.
* @dev A struct representing a single attestation.
*/
struct Attestation { struct Attestation {
bytes32 uid; // A unique identifier of the attestation. bytes32 uid; // A unique identifier of the attestation.
bytes32 schema; // The unique identifier of the schema. bytes32 schema; // The unique identifier of the schema.
...@@ -42,26 +37,18 @@ struct Attestation { ...@@ -42,26 +37,18 @@ struct Attestation {
// Maximum upgrade forward-compatibility storage gap. // Maximum upgrade forward-compatibility storage gap.
uint32 constant MAX_GAP = 50; uint32 constant MAX_GAP = 50;
/** /// @dev A helper function to work with unchecked iterators in loops.
* @dev A helper function to work with unchecked iterators in loops. /// @param i The index to increment.
* /// @return j The incremented index.
* @param i The index to increment.
*
* @return j The incremented index.
*/
function uncheckedInc(uint256 i) pure returns (uint256 j) { function uncheckedInc(uint256 i) pure returns (uint256 j) {
unchecked { unchecked {
j = i + 1; j = i + 1;
} }
} }
/** /// @dev A helper function that converts a string to a bytes32.
* @dev A helper function that converts a string to a bytes32. /// @param str The string to convert.
* /// @return The converted bytes32.
* @param str The string to convert.
*
* @return The converted bytes32.
*/
function stringToBytes32(string memory str) pure returns (bytes32) { function stringToBytes32(string memory str) pure returns (bytes32) {
bytes32 result; bytes32 result;
...@@ -72,13 +59,9 @@ function stringToBytes32(string memory str) pure returns (bytes32) { ...@@ -72,13 +59,9 @@ function stringToBytes32(string memory str) pure returns (bytes32) {
return result; return result;
} }
/** /// @dev A helper function that converts a bytes32 to a string.
* @dev A helper function that converts a bytes32 to a string. /// @param data The bytes32 data to convert.
* /// @return The converted string.
* @param data The bytes32 data to convert.
*
* @return The converted string.
*/
function bytes32ToString(bytes32 data) pure returns (string memory) { function bytes32ToString(bytes32 data) pure returns (string memory) {
bytes memory byteArray = new bytes(32); bytes memory byteArray = new bytes(32);
......
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import { ISchemaResolver } from "./resolver/ISchemaResolver.sol"; import { ISchemaResolver } from "./resolver/ISchemaResolver.sol";
/** /// @title A struct representing a record for a submitted schema.
* @title A struct representing a record for a submitted schema.
*/
struct SchemaRecord { struct SchemaRecord {
bytes32 uid; // The unique identifier of the schema. bytes32 uid; // The unique identifier of the schema.
ISchemaResolver resolver; // Optional schema resolver. ISchemaResolver resolver; // Optional schema resolver.
...@@ -17,31 +14,20 @@ struct SchemaRecord { ...@@ -17,31 +14,20 @@ struct SchemaRecord {
/// @title ISchemaRegistry /// @title ISchemaRegistry
/// @notice The interface of global attestation schemas for the Ethereum Attestation Service protocol. /// @notice The interface of global attestation schemas for the Ethereum Attestation Service protocol.
interface ISchemaRegistry { interface ISchemaRegistry {
/** /// @dev Emitted when a new schema has been registered
* @dev Emitted when a new schema has been registered /// @param uid The schema UID.
* /// @param registerer The address of the account used to register the schema.
* @param uid The schema UID.
* @param registerer The address of the account used to register the schema.
*/
event Registered(bytes32 indexed uid, address registerer); event Registered(bytes32 indexed uid, address registerer);
/** /// @dev Submits and reserves a new schema
* @dev Submits and reserves a new schema /// @param schema The schema data schema.
* /// @param resolver An optional schema resolver.
* @param schema The schema data schema. /// @param revocable Whether the schema allows revocations explicitly.
* @param resolver An optional schema resolver. /// @return The UID of the new schema.
* @param revocable Whether the schema allows revocations explicitly.
*
* @return The UID of the new schema.
*/
function register(string calldata schema, ISchemaResolver resolver, bool revocable) external returns (bytes32); function register(string calldata schema, ISchemaResolver resolver, bool revocable) external returns (bytes32);
/** /// @dev Returns an existing schema by UID
* @dev Returns an existing schema by UID /// @param uid The UID of the schema to retrieve.
* /// @return The schema data members.
* @param uid The UID of the schema to retrieve.
*
* @return The schema data members.
*/
function getSchema(bytes32 uid) external view returns (SchemaRecord memory); function getSchema(bytes32 uid) external view returns (SchemaRecord memory);
} }
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity 0.8.19; pragma solidity 0.8.19;
import { Semver } from "../universal/Semver.sol"; import { Semver } from "../universal/Semver.sol";
...@@ -22,14 +21,10 @@ contract SchemaRegistry is ISchemaRegistry, Semver { ...@@ -22,14 +21,10 @@ contract SchemaRegistry is ISchemaRegistry, Semver {
// Upgrade forward-compatibility storage gap // Upgrade forward-compatibility storage gap
uint256[MAX_GAP - 1] private __gap; uint256[MAX_GAP - 1] private __gap;
/** /// @dev Creates a new SchemaRegistry instance.
* @dev Creates a new SchemaRegistry instance.
*/
constructor() Semver(1, 0, 0) {} constructor() Semver(1, 0, 0) {}
/** /// @inheritdoc ISchemaRegistry
* @inheritdoc ISchemaRegistry
*/
function register(string calldata schema, ISchemaResolver resolver, bool revocable) external returns (bytes32) { function register(string calldata schema, ISchemaResolver resolver, bool revocable) external returns (bytes32) {
SchemaRecord memory schemaRecord = SchemaRecord({ SchemaRecord memory schemaRecord = SchemaRecord({
uid: EMPTY_UID, uid: EMPTY_UID,
...@@ -51,20 +46,14 @@ contract SchemaRegistry is ISchemaRegistry, Semver { ...@@ -51,20 +46,14 @@ contract SchemaRegistry is ISchemaRegistry, Semver {
return uid; return uid;
} }
/** /// @inheritdoc ISchemaRegistry
* @inheritdoc ISchemaRegistry
*/
function getSchema(bytes32 uid) external view returns (SchemaRecord memory) { function getSchema(bytes32 uid) external view returns (SchemaRecord memory) {
return _registry[uid]; return _registry[uid];
} }
/** /// @dev Calculates a UID for a given schema.
* @dev Calculates a UID for a given schema. /// @param schemaRecord The input schema.
* /// @return schema UID.
* @param schemaRecord The input schema.
*
* @return schema UID.
*/
function _getUID(SchemaRecord memory schemaRecord) private pure returns (bytes32) { function _getUID(SchemaRecord memory schemaRecord) private pure returns (bytes32) {
return keccak256(abi.encodePacked(schemaRecord.schema, schemaRecord.resolver, schemaRecord.revocable)); return keccak256(abi.encodePacked(schemaRecord.schema, schemaRecord.resolver, schemaRecord.revocable));
} }
......
...@@ -36,59 +36,44 @@ abstract contract EIP712Verifier is EIP712 { ...@@ -36,59 +36,44 @@ abstract contract EIP712Verifier is EIP712 {
// Upgrade forward-compatibility storage gap // Upgrade forward-compatibility storage gap
uint256[MAX_GAP - 1] private __gap; uint256[MAX_GAP - 1] private __gap;
/** /// @dev Creates a new EIP712Verifier instance.
* @dev Creates a new EIP712Verifier instance. /// @param version The current major version of the signing domain
*
* @param version The current major version of the signing domain
*/
constructor(string memory name, string memory version) EIP712(name, version) { constructor(string memory name, string memory version) EIP712(name, version) {
_name = stringToBytes32(name); _name = stringToBytes32(name);
} }
/** /// @notice Returns the domain separator used in the encoding of the signatures for attest, and revoke.
* @dev Returns the domain separator used in the encoding of the signatures for attest, and revoke.
*/
function getDomainSeparator() external view returns (bytes32) { function getDomainSeparator() external view returns (bytes32) {
return _domainSeparatorV4(); return _domainSeparatorV4();
} }
/** /// @notice Returns the current nonce per-account.
* @dev Returns the current nonce per-account. /// @param account The requested account.
* /// @return The current nonce.
* @param account The requested account.
*
* @return The current nonce.
*/
function getNonce(address account) external view returns (uint256) { function getNonce(address account) external view returns (uint256) {
return _nonces[account]; return _nonces[account];
} }
/** /// @notice Returns the EIP712 type hash for the attest function.
* Returns the EIP712 type hash for the attest function. /// @return The EIP712 attest function type hash.
*/
function getAttestTypeHash() external pure returns (bytes32) { function getAttestTypeHash() external pure returns (bytes32) {
return ATTEST_TYPEHASH; return ATTEST_TYPEHASH;
} }
/** /// @notice Returns the EIP712 type hash for the revoke function.
* Returns the EIP712 type hash for the revoke function. /// @return hash_ The EIP712 revoke function type hash.
*/
function getRevokeTypeHash() external pure returns (bytes32) { function getRevokeTypeHash() external pure returns (bytes32) {
return REVOKE_TYPEHASH; return REVOKE_TYPEHASH;
} }
/** /// @notice Returns the EIP712 name.
* Returns the EIP712 name. /// @return The EIP712 name.
*/
function getName() external view returns (string memory) { function getName() external view returns (string memory) {
return bytes32ToString(_name); return bytes32ToString(_name);
} }
/** /// @notice Verifies delegated attestation request.
* @dev Verifies delegated attestation request. /// @param request The arguments of the delegated attestation request.
*
* @param request The arguments of the delegated attestation request.
*/
function _verifyAttest(DelegatedAttestationRequest memory request) internal { function _verifyAttest(DelegatedAttestationRequest memory request) internal {
AttestationRequestData memory data = request.data; AttestationRequestData memory data = request.data;
EIP712Signature memory signature = request.signature; EIP712Signature memory signature = request.signature;
...@@ -118,11 +103,8 @@ abstract contract EIP712Verifier is EIP712 { ...@@ -118,11 +103,8 @@ abstract contract EIP712Verifier is EIP712 {
} }
} }
/** /// @notice Verifies delegated revocation request.
* @dev Verifies delegated revocation request. /// @param request The arguments of the delegated revocation request.
*
* @param request The arguments of the delegated revocation request.
*/
function _verifyRevoke(DelegatedRevocationRequest memory request) internal { function _verifyRevoke(DelegatedRevocationRequest memory request) internal {
RevocationRequestData memory data = request.data; RevocationRequestData memory data = request.data;
EIP712Signature memory signature = request.signature; EIP712Signature memory signature = request.signature;
......
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import { Attestation } from "../Common.sol"; import { Attestation } from "../Common.sol";
...@@ -7,50 +6,33 @@ import { Attestation } from "../Common.sol"; ...@@ -7,50 +6,33 @@ import { Attestation } from "../Common.sol";
/// @title ISchemaResolver /// @title ISchemaResolver
/// @notice The interface of an optional schema resolver. /// @notice The interface of an optional schema resolver.
interface ISchemaResolver { interface ISchemaResolver {
/** /// @notice Checks if the resolve can be sent ETH.
* @dev Returns whether the resolver supports ETH transfers. /// @return Whether the resolver supports ETH transfers.
*/
function isPayable() external pure returns (bool); function isPayable() external pure returns (bool);
/** /// @notice Processes an attestation and verifies whether it's valid.
* @dev Processes an attestation and verifies whether it's valid. /// @param attestation The new attestation.
* /// @return Whether the attestation is valid.
* @param attestation The new attestation.
*
* @return Whether the attestation is valid.
*/
function attest(Attestation calldata attestation) external payable returns (bool); function attest(Attestation calldata attestation) external payable returns (bool);
/** /// @notice Processes multiple attestations and verifies whether they are valid.
* @dev Processes multiple attestations and verifies whether they are valid. /// @param attestations The new attestations.
* /// @param values Explicit ETH amounts which were sent with each attestation.
* @param attestations The new attestations. /// @return Whether all the attestations are valid.
* @param values Explicit ETH amounts which were sent with each attestation.
*
* @return Whether all the attestations are valid.
*/
function multiAttest( function multiAttest(
Attestation[] calldata attestations, Attestation[] calldata attestations,
uint256[] calldata values uint256[] calldata values
) external payable returns (bool); ) external payable returns (bool);
/** /// @notice Processes an attestation revocation and verifies if it can be revoked.
* @dev Processes an attestation revocation and verifies if it can be revoked. /// @param attestation The existing attestation to be revoked.
* /// @return Whether the attestation can be revoked.
* @param attestation The existing attestation to be revoked.
*
* @return Whether the attestation can be revoked.
*/
function revoke(Attestation calldata attestation) external payable returns (bool); function revoke(Attestation calldata attestation) external payable returns (bool);
/** /// @notice Processes revocation of multiple attestation and verifies they can be revoked.
* @dev Processes revocation of multiple attestation and verifies they can be revoked. /// @param attestations The existing attestations to be revoked.
* /// @param values Explicit ETH amounts which were sent with each revocation.
* @param attestations The existing attestations to be revoked. /// @return Whether the attestations can be revoked.
* @param values Explicit ETH amounts which were sent with each revocation.
*
* @return Whether the attestations can be revoked.
*/
function multiRevoke( function multiRevoke(
Attestation[] calldata attestations, Attestation[] calldata attestations,
uint256[] calldata values uint256[] calldata values
......
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity 0.8.19; pragma solidity 0.8.19;
import { Semver } from "../../universal/Semver.sol"; import { Semver } from "../../universal/Semver.sol";
...@@ -19,11 +18,8 @@ abstract contract SchemaResolver is ISchemaResolver, Semver { ...@@ -19,11 +18,8 @@ abstract contract SchemaResolver is ISchemaResolver, Semver {
// The global EAS contract. // The global EAS contract.
IEAS internal immutable _eas; IEAS internal immutable _eas;
/** /// @dev Creates a new resolver.
* @dev Creates a new resolver. /// @param eas The address of the global EAS contract.
*
* @param eas The address of the global EAS contract.
*/
constructor(IEAS eas) Semver(1, 0, 0) { constructor(IEAS eas) Semver(1, 0, 0) {
if (address(eas) == address(0)) { if (address(eas) == address(0)) {
revert InvalidEAS(); revert InvalidEAS();
...@@ -32,41 +28,31 @@ abstract contract SchemaResolver is ISchemaResolver, Semver { ...@@ -32,41 +28,31 @@ abstract contract SchemaResolver is ISchemaResolver, Semver {
_eas = eas; _eas = eas;
} }
/** /// @dev Ensures that only the EAS contract can make this call.
* @dev Ensures that only the EAS contract can make this call.
*/
modifier onlyEAS() { modifier onlyEAS() {
_onlyEAS(); _onlyEAS();
_; _;
} }
/** /// @inheritdoc ISchemaResolver
* @inheritdoc ISchemaResolver
*/
function isPayable() public pure virtual returns (bool) { function isPayable() public pure virtual returns (bool) {
return false; return false;
} }
/** /// @dev ETH callback.
* @dev ETH callback.
*/
receive() external payable virtual { receive() external payable virtual {
if (!isPayable()) { if (!isPayable()) {
revert NotPayable(); revert NotPayable();
} }
} }
/** /// @inheritdoc ISchemaResolver
* @inheritdoc ISchemaResolver
*/
function attest(Attestation calldata attestation) external payable onlyEAS returns (bool) { function attest(Attestation calldata attestation) external payable onlyEAS returns (bool) {
return onAttest(attestation, msg.value); return onAttest(attestation, msg.value);
} }
/** /// @inheritdoc ISchemaResolver
* @inheritdoc ISchemaResolver
*/
function multiAttest( function multiAttest(
Attestation[] calldata attestations, Attestation[] calldata attestations,
uint256[] calldata values uint256[] calldata values
...@@ -100,16 +86,12 @@ abstract contract SchemaResolver is ISchemaResolver, Semver { ...@@ -100,16 +86,12 @@ abstract contract SchemaResolver is ISchemaResolver, Semver {
return true; return true;
} }
/** /// @inheritdoc ISchemaResolver
* @inheritdoc ISchemaResolver
*/
function revoke(Attestation calldata attestation) external payable onlyEAS returns (bool) { function revoke(Attestation calldata attestation) external payable onlyEAS returns (bool) {
return onRevoke(attestation, msg.value); return onRevoke(attestation, msg.value);
} }
/** /// @inheritdoc ISchemaResolver
* @inheritdoc ISchemaResolver
*/
function multiRevoke( function multiRevoke(
Attestation[] calldata attestations, Attestation[] calldata attestations,
uint256[] calldata values uint256[] calldata values
...@@ -143,35 +125,25 @@ abstract contract SchemaResolver is ISchemaResolver, Semver { ...@@ -143,35 +125,25 @@ abstract contract SchemaResolver is ISchemaResolver, Semver {
return true; return true;
} }
/** /// @notice A resolver callback that should be implemented by child contracts.
* @dev A resolver callback that should be implemented by child contracts. /// @param attestation The new attestation.
* /// @param value An explicit ETH amount that was sent to the resolver. Please note that this value is verified in
* @param attestation The new attestation. /// both attest() and multiAttest() callbacks EAS-only callbacks and that in case of multi attestations, it'll
* @param value An explicit ETH amount that was sent to the resolver. Please note that this value is verified in /// usually hold that msg.value != value, since msg.value aggregated the sent ETH amounts for all the attestations
* both attest() and multiAttest() callbacks EAS-only callbacks and that in case of multi attestations, it'll /// in the batch.
* usually hold that msg.value != value, since msg.value aggregated the sent ETH amounts for all the attestations /// @return Whether the attestation is valid.
* in the batch.
*
* @return Whether the attestation is valid.
*/
function onAttest(Attestation calldata attestation, uint256 value) internal virtual returns (bool); function onAttest(Attestation calldata attestation, uint256 value) internal virtual returns (bool);
/** /// @notice Processes an attestation revocation and verifies if it can be revoked.
* @dev Processes an attestation revocation and verifies if it can be revoked. /// @param attestation The existing attestation to be revoked.
* /// @param value An explicit ETH amount that was sent to the resolver. Please note that this value is verified in
* @param attestation The existing attestation to be revoked. /// both revoke() and multiRevoke() callbacks EAS-only callbacks and that in case of multi attestations, it'll
* @param value An explicit ETH amount that was sent to the resolver. Please note that this value is verified in /// usually hold that msg.value != value, since msg.value aggregated the sent ETH amounts for all the attestations
* both revoke() and multiRevoke() callbacks EAS-only callbacks and that in case of multi attestations, it'll /// in the batch.
* usually hold that msg.value != value, since msg.value aggregated the sent ETH amounts for all the attestations /// @return Whether the attestation can be revoked.
* in the batch.
*
* @return Whether the attestation can be revoked.
*/
function onRevoke(Attestation calldata attestation, uint256 value) internal virtual returns (bool); function onRevoke(Attestation calldata attestation, uint256 value) internal virtual returns (bool);
/** /// @notice Ensures that only the EAS contract can make this call.
* @dev Ensures that only the EAS contract can make this call.
*/
function _onlyEAS() private view { function _onlyEAS() private view {
if (msg.sender != address(_eas)) { if (msg.sender != address(_eas)) {
revert AccessDenied(); revert AccessDenied();
......
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