Skip to content

Commit

Permalink
Merge pull request #161 from ethereum-attestation-service/upgrade
Browse files Browse the repository at this point in the history
Upgrade to Solidity 0.8.28
  • Loading branch information
lbeder authored Jan 29, 2025
2 parents 038bcd3 + 90c0b2f commit d223e17
Show file tree
Hide file tree
Showing 32 changed files with 1,551 additions and 1,258 deletions.
7 changes: 0 additions & 7 deletions contracts/Common.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,3 @@ struct Attestation {
bool revocable; // Whether the attestation is revocable.
bytes data; // Custom attestation data.
}

/// @notice A helper function to work with unchecked iterators in loops.
function uncheckedInc(uint256 i) pure returns (uint256 j) {
unchecked {
j = i + 1;
}
}
35 changes: 17 additions & 18 deletions contracts/EAS.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.27;
pragma solidity 0.8.28;

import { Address } from "@openzeppelin/contracts/utils/Address.sol";

Expand All @@ -14,8 +14,7 @@ import {
EMPTY_UID,
InvalidLength,
NotFound,
NO_EXPIRATION_TIME,
uncheckedInc
NO_EXPIRATION_TIME
} from "./Common.sol";

// prettier-ignore
Expand Down Expand Up @@ -79,7 +78,7 @@ contract EAS is IEAS, Semver, EIP1271Verifier {

/// @dev Creates a new EAS instance.
/// @param registry The address of the global schema registry.
constructor(ISchemaRegistry registry) Semver(1, 3, 0) EIP1271Verifier("EAS", "1.3.0") {
constructor(ISchemaRegistry registry) Semver(1, 4, 0) EIP1271Verifier("EAS", "1.4.0") {
if (address(registry) == address(0)) {
revert InvalidRegistry();
}
Expand Down Expand Up @@ -126,7 +125,7 @@ contract EAS is IEAS, Semver, EIP1271Verifier {
// possible to send too much ETH anyway.
uint256 availableValue = msg.value;

for (uint256 i = 0; i < length; i = uncheckedInc(i)) {
for (uint256 i = 0; i < length; ++i) {
// The last batch is handled slightly differently: if the total available ETH wasn't spent in full and there
// is a remainder - it will be refunded back to the attester (something that we can only verify during the
// last and final batch).
Expand Down Expand Up @@ -181,7 +180,7 @@ contract EAS is IEAS, Semver, EIP1271Verifier {
// possible to send too much ETH anyway.
uint256 availableValue = msg.value;

for (uint256 i = 0; i < length; i = uncheckedInc(i)) {
for (uint256 i = 0; i < length; ++i) {
// The last batch is handled slightly differently: if the total available ETH wasn't spent in full and there
// is a remainder - it will be refunded back to the attester (something that we can only verify during the
// last and final batch).
Expand All @@ -200,7 +199,7 @@ contract EAS is IEAS, Semver, EIP1271Verifier {
}

// Verify signatures. Please note that the signatures are assumed to be signed with increasing nonces.
for (uint256 j = 0; j < dataLength; j = uncheckedInc(j)) {
for (uint256 j = 0; j < dataLength; ++j) {
_verifyAttest(
DelegatedAttestationRequest({
schema: multiDelegatedRequest.schema,
Expand Down Expand Up @@ -262,7 +261,7 @@ contract EAS is IEAS, Semver, EIP1271Verifier {
uint256 availableValue = msg.value;

uint256 length = multiRequests.length;
for (uint256 i = 0; i < length; i = uncheckedInc(i)) {
for (uint256 i = 0; i < length; ++i) {
// The last batch is handled slightly differently: if the total available ETH wasn't spent in full and there
// is a remainder - it will be refunded back to the attester (something that we can only verify during the
// last and final batch).
Expand All @@ -289,7 +288,7 @@ contract EAS is IEAS, Semver, EIP1271Verifier {
uint256 availableValue = msg.value;

uint256 length = multiDelegatedRequests.length;
for (uint256 i = 0; i < length; i = uncheckedInc(i)) {
for (uint256 i = 0; i < length; ++i) {
// The last batch is handled slightly differently: if the total available ETH wasn't spent in full and there
// is a remainder - it will be refunded back to the attester (something that we can only verify during the
// last and final batch).
Expand All @@ -308,7 +307,7 @@ contract EAS is IEAS, Semver, EIP1271Verifier {
}

// Verify signatures. Please note that the signatures are assumed to be signed with increasing nonces.
for (uint256 j = 0; j < dataLength; j = uncheckedInc(j)) {
for (uint256 j = 0; j < dataLength; ++j) {
_verifyRevoke(
DelegatedRevocationRequest({
schema: multiDelegatedRequest.schema,
Expand Down Expand Up @@ -354,7 +353,7 @@ contract EAS is IEAS, Semver, EIP1271Verifier {
uint64 time = _time();

uint256 length = data.length;
for (uint256 i = 0; i < length; i = uncheckedInc(i)) {
for (uint256 i = 0; i < length; ++i) {
_revokeOffchain(msg.sender, data[i], time);
}

Expand All @@ -366,7 +365,7 @@ contract EAS is IEAS, Semver, EIP1271Verifier {
uint64 time = _time();

uint256 length = data.length;
for (uint256 i = 0; i < length; i = uncheckedInc(i)) {
for (uint256 i = 0; i < length; ++i) {
_timestamp(data[i], time);
}

Expand Down Expand Up @@ -421,7 +420,7 @@ contract EAS is IEAS, Semver, EIP1271Verifier {
Attestation[] memory attestations = new Attestation[](length);
uint256[] memory values = new uint256[](length);

for (uint256 i = 0; i < length; i = uncheckedInc(i)) {
for (uint256 i = 0; i < length; ++i) {
AttestationRequestData memory request = data[i];

// Ensure that either no expiration time was set or that it was set in the future.
Expand Down Expand Up @@ -508,7 +507,7 @@ contract EAS is IEAS, Semver, EIP1271Verifier {
Attestation[] memory attestations = new Attestation[](length);
uint256[] memory values = new uint256[](length);

for (uint256 i = 0; i < length; i = uncheckedInc(i)) {
for (uint256 i = 0; i < length; ++i) {
RevocationRequestData memory request = data[i];

Attestation storage attestation = _db[request.uid];
Expand Down Expand Up @@ -635,7 +634,7 @@ contract EAS is IEAS, Semver, EIP1271Verifier {
ISchemaResolver resolver = schemaRecord.resolver;
if (address(resolver) == address(0)) {
// Ensure that we don't accept payments if there is no resolver.
for (uint256 i = 0; i < length; i = uncheckedInc(i)) {
for (uint256 i = 0; i < length; ++i) {
if (values[i] != 0) {
revert NotPayable();
}
Expand All @@ -651,7 +650,7 @@ contract EAS is IEAS, Semver, EIP1271Verifier {
uint256 totalUsedValue = 0;
bool isResolverPayable = resolver.isPayable();

for (uint256 i = 0; i < length; i = uncheckedInc(i)) {
for (uint256 i = 0; i < length; ++i) {
uint256 value = values[i];

// Ensure that we don't accept payments which can't be forwarded to the resolver.
Expand Down Expand Up @@ -760,10 +759,10 @@ contract EAS is IEAS, Semver, EIP1271Verifier {

uint256 currentIndex = 0;
uint256 uidListLength = uidLists.length;
for (uint256 i = 0; i < uidListLength; i = uncheckedInc(i)) {
for (uint256 i = 0; i < uidListLength; ++i) {
bytes32[] memory currentUIDs = uidLists[i];
uint256 currentUIDsLength = currentUIDs.length;
for (uint256 j = 0; j < currentUIDsLength; j = uncheckedInc(j)) {
for (uint256 j = 0; j < currentUIDsLength; ++j) {
uids[currentIndex] = currentUIDs[j];

unchecked {
Expand Down
8 changes: 4 additions & 4 deletions contracts/Indexer.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.27;
pragma solidity 0.8.28;

import { IEAS, Attestation } from "./IEAS.sol";
import { EMPTY_UID, uncheckedInc } from "./Common.sol";
import { EMPTY_UID } from "./Common.sol";
import { Semver } from "./Semver.sol";

/// @title Indexer
Expand Down Expand Up @@ -38,7 +38,7 @@ contract Indexer is Semver {

/// @dev Creates a new Indexer instance.
/// @param eas The address of the global EAS contract.
constructor(IEAS eas) Semver(1, 3, 0) {
constructor(IEAS eas) Semver(1, 4, 0) {
if (address(eas) == address(0)) {
revert InvalidEAS();
}
Expand All @@ -61,7 +61,7 @@ contract Indexer is Semver {
/// @param attestationUIDs The UIDs of the attestations to index.
function indexAttestations(bytes32[] calldata attestationUIDs) external {
uint256 length = attestationUIDs.length;
for (uint256 i = 0; i < length; i = uncheckedInc(i)) {
for (uint256 i = 0; i < length; ++i) {
_indexAttestation(attestationUIDs[i]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/SchemaRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.27;
pragma solidity 0.8.28;

import { ISchemaResolver } from "./resolver/ISchemaResolver.sol";

Expand All @@ -17,7 +17,7 @@ contract SchemaRegistry is ISchemaRegistry, Semver {
mapping(bytes32 uid => SchemaRecord schemaRecord) private _registry;

/// @dev Creates a new SchemaRegistry instance.
constructor() Semver(1, 3, 0) {}
constructor() Semver(1, 4, 0) {}

/// @inheritdoc ISchemaRegistry
function register(string calldata schema, ISchemaResolver resolver, bool revocable) external returns (bytes32) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/eip1271/EIP1271Verifier.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.27;
pragma solidity 0.8.28;

import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { EIP712 } from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
Expand Down
17 changes: 8 additions & 9 deletions contracts/eip712/proxy/EIP712Proxy.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.27;
pragma solidity 0.8.28;

import { EIP712 } from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
Expand All @@ -14,8 +14,7 @@ import {
InvalidLength,
InvalidSignature,
NotFound,
NO_EXPIRATION_TIME,
uncheckedInc
NO_EXPIRATION_TIME
} from "../../Common.sol";

// prettier-ignore
Expand Down Expand Up @@ -217,7 +216,7 @@ contract EIP712Proxy is Semver, EIP712 {
uint256 length = multiDelegatedRequests.length;
MultiAttestationRequest[] memory multiRequests = new MultiAttestationRequest[](length);

for (uint256 i = 0; i < length; i = uncheckedInc(i)) {
for (uint256 i = 0; i < length; ++i) {
MultiDelegatedProxyAttestationRequest calldata multiDelegatedRequest = multiDelegatedRequests[i];
AttestationRequestData[] calldata data = multiDelegatedRequest.data;

Expand All @@ -228,7 +227,7 @@ contract EIP712Proxy is Semver, EIP712 {
}

// Verify EIP712 signatures. Please note that the signatures are assumed to be signed with increasing nonces.
for (uint256 j = 0; j < dataLength; j = uncheckedInc(j)) {
for (uint256 j = 0; j < dataLength; ++j) {
_verifyAttest(
DelegatedProxyAttestationRequest({
schema: multiDelegatedRequest.schema,
Expand All @@ -248,12 +247,12 @@ contract EIP712Proxy is Semver, EIP712 {
// Store all attesters, according to the order of the attestation requests.
uint256 uidCounter = 0;

for (uint256 i = 0; i < length; i = uncheckedInc(i)) {
for (uint256 i = 0; i < length; ++i) {
MultiDelegatedProxyAttestationRequest calldata multiDelegatedRequest = multiDelegatedRequests[i];
AttestationRequestData[] calldata data = multiDelegatedRequest.data;

uint256 dataLength = data.length;
for (uint256 j = 0; j < dataLength; j = uncheckedInc(j)) {
for (uint256 j = 0; j < dataLength; ++j) {
_attesters[uids[uidCounter]] = multiDelegatedRequest.attester;

unchecked {
Expand Down Expand Up @@ -326,7 +325,7 @@ contract EIP712Proxy is Semver, EIP712 {
uint256 length = multiDelegatedRequests.length;
MultiRevocationRequest[] memory multiRequests = new MultiRevocationRequest[](length);

for (uint256 i = 0; i < length; i = uncheckedInc(i)) {
for (uint256 i = 0; i < length; ++i) {
MultiDelegatedProxyRevocationRequest memory multiDelegatedRequest = multiDelegatedRequests[i];
RevocationRequestData[] memory data = multiDelegatedRequest.data;

Expand All @@ -337,7 +336,7 @@ contract EIP712Proxy is Semver, EIP712 {
}

// Verify EIP712 signatures. Please note that the signatures are assumed to be signed with increasing nonces.
for (uint256 j = 0; j < dataLength; j = uncheckedInc(j)) {
for (uint256 j = 0; j < dataLength; ++j) {
RevocationRequestData memory requestData = data[j];

_verifyRevoke(
Expand Down
12 changes: 6 additions & 6 deletions contracts/eip712/proxy/examples/PermissionedEIP712Proxy.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.27;
pragma solidity 0.8.28;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { Ownable, Ownable2Step } from "@openzeppelin/contracts/access/Ownable2Step.sol";

// prettier-ignore
import {
Expand All @@ -15,11 +15,11 @@ import {

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

import { AccessDenied, uncheckedInc } from "../../../Common.sol";
import { AccessDenied } from "../../../Common.sol";

/// @title PermissionedEIP712Proxy
/// @notice A sample EIP712 proxy that allows only a specific address to attest.
contract PermissionedEIP712Proxy is EIP712Proxy, Ownable {
contract PermissionedEIP712Proxy is EIP712Proxy, Ownable2Step {
/// @dev Creates a new PermissionedEIP712Proxy instance.
/// @param eas The address of the global EAS contract.
/// @param name The user readable name of the signing domain.
Expand All @@ -40,7 +40,7 @@ contract PermissionedEIP712Proxy is EIP712Proxy, Ownable {
MultiDelegatedProxyAttestationRequest[] calldata multiDelegatedRequests
) public payable override returns (bytes32[] memory) {
uint256 length = multiDelegatedRequests.length;
for (uint256 i = 0; i < length; i = uncheckedInc(i)) {
for (uint256 i = 0; i < length; ++i) {
// Ensure that only the owner is allowed to delegate attestations.
_verifyAttester(multiDelegatedRequests[i].attester);
}
Expand All @@ -61,7 +61,7 @@ contract PermissionedEIP712Proxy is EIP712Proxy, Ownable {
MultiDelegatedProxyRevocationRequest[] calldata multiDelegatedRequests
) public payable override {
uint256 length = multiDelegatedRequests.length;
for (uint256 i = 0; i < length; i = uncheckedInc(i)) {
for (uint256 i = 0; i < length; ++i) {
// Ensure that only the owner is allowed to delegate revocations.
_verifyAttester(multiDelegatedRequests[i].revoker);
}
Expand Down
8 changes: 4 additions & 4 deletions contracts/resolver/SchemaResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity ^0.8.4;

import { AccessDenied, InvalidEAS, InvalidLength, uncheckedInc } from "./../Common.sol";
import { AccessDenied, InvalidEAS, InvalidLength } from "./../Common.sol";
import { IEAS, Attestation } from "./../IEAS.sol";
import { Semver } from "./../Semver.sol";
import { ISchemaResolver } from "./ISchemaResolver.sol";
Expand All @@ -18,7 +18,7 @@ abstract contract SchemaResolver is ISchemaResolver, Semver {

/// @dev Creates a new resolver.
/// @param eas The address of the global EAS contract.
constructor(IEAS eas) Semver(1, 3, 0) {
constructor(IEAS eas) Semver(1, 4, 0) {
if (address(eas) == address(0)) {
revert InvalidEAS();
}
Expand Down Expand Up @@ -66,7 +66,7 @@ abstract contract SchemaResolver is ISchemaResolver, Semver {
// possible to send too much ETH anyway.
uint256 remainingValue = msg.value;

for (uint256 i = 0; i < length; i = uncheckedInc(i)) {
for (uint256 i = 0; i < length; ++i) {
// Ensure that the attester/revoker doesn't try to spend more than available.
uint256 value = values[i];
if (value > remainingValue) {
Expand Down Expand Up @@ -108,7 +108,7 @@ abstract contract SchemaResolver is ISchemaResolver, Semver {
// possible to send too much ETH anyway.
uint256 remainingValue = msg.value;

for (uint256 i = 0; i < length; i = uncheckedInc(i)) {
for (uint256 i = 0; i < length; ++i) {
// Ensure that the attester/revoker doesn't try to spend more than available.
uint256 value = values[i];
if (value > remainingValue) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/resolver/examples/AttestationResolver.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.27;
pragma solidity 0.8.28;

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

Expand Down
2 changes: 1 addition & 1 deletion contracts/resolver/examples/AttesterResolver.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.27;
pragma solidity 0.8.28;

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

Expand Down
2 changes: 1 addition & 1 deletion contracts/resolver/examples/DataResolver.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.27;
pragma solidity 0.8.28;

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

Expand Down
2 changes: 1 addition & 1 deletion contracts/resolver/examples/ExpirationTimeResolver.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.27;
pragma solidity 0.8.28;

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

Expand Down
Loading

0 comments on commit d223e17

Please sign in to comment.