Skip to content
Merged
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
8 changes: 4 additions & 4 deletions contract3/OCR3AttestationVerifierBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ abstract contract OCR3AttestationVerifierBase {
/// @param n The number of keys expected to be set by this call. Must match the actual number of keys present in
/// the `ocr3SignerPublicKeys` parameter. The maximum number of keys supported is 32 (based on the width of
/// the attribution bitmask).
/// @param ocr3SignerPublicKeys A concatenation of `n` public keys from the OCR3 signers. The exact format of the
/// keys depends on the signature scheme used for verification (for example, for ECDSA, addresses of 20 bytes
/// each would be used).
function _setVerificationKeys(uint8 n, bytes calldata ocr3SignerPublicKeys) internal virtual;
/// @param ocr3SignerPublicKeys The `n` public keys of the OCR3 signers. The exact encoding depends on the
/// signature scheme used for verification (for example, ECDSA expects `abi.encode(address[])`, whereas BLS
/// expects a concatenation of fixed-size keys).
function _setAttestationVerificationKeys(uint8 n, bytes calldata ocr3SignerPublicKeys) internal virtual;

/// @notice Verifies the attestation for the given report.
/// Reverts if the attestation could not be verified successfully.
Expand Down
10 changes: 5 additions & 5 deletions contract3/OCR3AttestationVerifierErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
pragma solidity ^0.8.19;

// Raised when the number of provided verification keys does not match the expected number of keys (parameter: n).
error InvalidNumberOfKeys();
error InvalidNumberOfAttestationVerificationKeys();

// Raised when the provided verification keys are of invalid size.
error KeysOfInvalidSize();
error AttestationVerificationKeysOfInvalidSize();

// Raised when an attempt to set more than 32 verification keys is made.
// An upper limit of 32 keys is enforced by the width of the bitmask used for the attribution data.
error MaximumNumberOfKeysExceeded();
error MaximumNumberOfAttestationVerificationKeysExceeded();

// Raised when a provided verification key is found invalid.
// Potential causes for invalid keys are, for example:
// - ECDSA: the value 0x0000000000000000000000000000000000000000
// - BLS: a key with an invalid proof-of-possession
error InvalidKey();
error InvalidAttestationVerificationKey();

// Raised when a duplicate verification key is provided during key set.
// Each key must be unique to ensure correct attribution during attestation verification.
error DuplicateKey();
error DuplicateAttestationVerificationKey();

// Raised when the signature verification failed for the provided attestation.
error InvalidAttestation();
Expand Down
6 changes: 4 additions & 2 deletions contract3/OCR3BLSAttestationVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ contract OCR3BLSAttestationVerifier is OCR3AttestationVerifierBase {
// configurations, storage costs are only paid for the used number of keys.
OCR3BLSAttestationVerifierLib.G2PointAffine[32] s_ocr3BlsSignerPublicKeys;

function _setVerificationKeys(uint8 n, bytes calldata ocr3BlsSignerPublicKeys) internal override {
OCR3BLSAttestationVerifierLib.setVerificationKeys(s_ocr3BlsSignerPublicKeys, n, ocr3BlsSignerPublicKeys);
function _setAttestationVerificationKeys(uint8 n, bytes calldata ocr3BlsSignerPublicKeys) internal override {
OCR3BLSAttestationVerifierLib.setAttestationVerificationKeys(
s_ocr3BlsSignerPublicKeys, n, ocr3BlsSignerPublicKeys
);
}

function _verifyAttestation(
Expand Down
12 changes: 6 additions & 6 deletions contract3/OCR3BLSAttestationVerifierLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ library OCR3BLSAttestationVerifierLib {
/// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^... innerHash
/// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^... outerHash
///
function setVerificationKeys(
function setAttestationVerificationKeys(
G2PointAffine[32] storage s_ocr3BlsSignerPublicKeys,
uint8 n,
bytes calldata ocr3BlsSignerPublicKeys
) internal {
// Verify that `n` is consistent with the amount of data being passed in the `ocr3BlsSignerPublicKeys` parameter.
// The maximum of 32 keys is based on the width of the attribution bitmask (currently set to 32 bits).
if (ocr3BlsSignerPublicKeys.length % KEYSIZE_WITH_POP != 0) {
revert KeysOfInvalidSize();
revert AttestationVerificationKeysOfInvalidSize();
}
if (ocr3BlsSignerPublicKeys.length / KEYSIZE_WITH_POP != n) {
revert InvalidNumberOfKeys();
revert InvalidNumberOfAttestationVerificationKeys();
}
if (n > 32) {
revert MaximumNumberOfKeysExceeded();
revert MaximumNumberOfAttestationVerificationKeysExceeded();
}

// Temporary in-memory storage for the keys. This is used to check for duplicate keys at the end of this
Expand Down Expand Up @@ -115,7 +115,7 @@ library OCR3BLSAttestationVerifierLib {
// below the field modulus. This is required to ensure the comparison performed in the duplicate keys check
// is not susceptible to maliciously crafted keys.
if (!_verifySignature(ocr3BlsSignerPublicKey, outerHash, popSignature)) {
revert InvalidKey();
revert InvalidAttestationVerificationKey();
}

// Write the verified key to the application contract's storage and to the temporary in-memory storage
Expand All @@ -138,7 +138,7 @@ library OCR3BLSAttestationVerifierLib {
&& ocr3BlsSignerPublicKeysMemory[i].y_imag == ocr3BlsSignerPublicKeysMemory[j].y_imag
&& ocr3BlsSignerPublicKeysMemory[i].y_real == ocr3BlsSignerPublicKeysMemory[j].y_real
) {
revert DuplicateKey();
revert DuplicateAttestationVerificationKey();
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions contract3/OCR3DynamicallyDispatchedAttestationVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ contract OCR3DynamicallyDispatchedAttestationVerifier is OCR3AttestationVerifier
// Address of the pre-deployed library contract.
address immutable i_verifierLibraryAddress;

// Function selectors for the setVerificationKeys(...) and verifyAttestation(...) functions of the library.
bytes4 immutable i_selectorSetVerificationKeys;
// Function selectors for the setAttestationVerificationKeys(...) and verifyAttestation(...) functions of the
// library.
bytes4 immutable i_selectorSetAttestationVerificationKeys;
bytes4 immutable i_selectorVerifyAttestation;

// Placeholder for reserving storage for up to 32 verification keys. The used library stores an implementation
Expand All @@ -29,7 +30,7 @@ contract OCR3DynamicallyDispatchedAttestationVerifier is OCR3AttestationVerifier
// delegatecall into the library, but is also security critical, it protects against potential misconfiguration,
// where i_verifierLibraryAddress does not point to a contract. Additional details are provided in the comment
// in the _delegatecall(...) helper below.
(i_selectorSetVerificationKeys, i_selectorVerifyAttestation) =
(i_selectorSetAttestationVerificationKeys, i_selectorVerifyAttestation) =
(OCR3DynamicallyDispatchedAttestationVerifierSelectorInterface(verifierLibraryAddress).getSelectors());
}

Expand All @@ -56,12 +57,14 @@ contract OCR3DynamicallyDispatchedAttestationVerifier is OCR3AttestationVerifier
}
}

function _setVerificationKeys(uint8 n, bytes calldata ocr3SignerPublicKeys) internal override {
function _setAttestationVerificationKeys(uint8 n, bytes calldata ocr3SignerPublicKeys) internal override {
uint256 storagePtr;
assembly {
storagePtr := s_ocr3SignerPublicKeys.slot
}
_delegatecall(abi.encodeWithSelector(i_selectorSetVerificationKeys, storagePtr, n, ocr3SignerPublicKeys));
_delegatecall(
abi.encodeWithSelector(i_selectorSetAttestationVerificationKeys, storagePtr, n, ocr3SignerPublicKeys)
);
}

function _verifyAttestation(
Expand All @@ -82,7 +85,7 @@ contract OCR3DynamicallyDispatchedAttestationVerifier is OCR3AttestationVerifier
}

/// @title Internal selector interface for dynamically dispatched OCR3 attestation verifier libraries
/// @dev Exposes the selectors for the `setVerificationKeys(...)`, and `verifyAttestation(...)` functions.
/// @dev Exposes the selectors for the `setAttestationVerificationKeys(...)`, and `verifyAttestation(...)` functions.
/// @dev Required for delegate-calling into a pre-deployed library, implemented in the `DynamicallyDispatched` shims.
interface OCR3DynamicallyDispatchedAttestationVerifierSelectorInterface {
function getSelectors() external pure returns (bytes4, bytes4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import "./OCR3BLSAttestationVerifierLib.sol";
/// @title Shim for the core BLS attestation verifier library, allowing it to be pre-deployed separately.
/// @dev The function modifiers of the main interface functions are updated from internal to external.
library OCR3DynamicallyDispatchedBLSAttestationVerifierLib {
function setVerificationKeys(
function setAttestationVerificationKeys(
OCR3BLSAttestationVerifierLib.G2PointAffine[32] storage s_ocr3BlsSignerPublicKeys,
uint8 n,
bytes calldata ocr3BlsSignerPublicKeys
) external {
OCR3BLSAttestationVerifierLib.setVerificationKeys(s_ocr3BlsSignerPublicKeys, n, ocr3BlsSignerPublicKeys);
OCR3BLSAttestationVerifierLib.setAttestationVerificationKeys(
s_ocr3BlsSignerPublicKeys, n, ocr3BlsSignerPublicKeys
);
}

function verifyAttestation(
Expand All @@ -26,13 +28,15 @@ library OCR3DynamicallyDispatchedBLSAttestationVerifierLib {

// Function to initialize the selectors for delegate-calling into this library.
// Derived using keccak256 from the function signatures (without parameter names):
// - keccak256("setVerificationKeys(OCR3BLSAttestationVerifierLib.G2PointAffine[32] storage,uint8,bytes)")[:4]
// - keccak256(
// "setAttestationVerificationKeys(OCR3BLSAttestationVerifierLib.G2PointAffine[32] storage,uint8,bytes)"
// )[:4]
// - keccak256(
// "verifyAttestation(OCR3BLSAttestationVerifierLib.G2PointAffine[32] storage,uint8,uint8,bytes32,bytes)"
// )[:4]
function getSelectors() external pure returns (bytes4, bytes4) {
return (
OCR3DynamicallyDispatchedBLSAttestationVerifierLib.setVerificationKeys.selector,
OCR3DynamicallyDispatchedBLSAttestationVerifierLib.setAttestationVerificationKeys.selector,
OCR3DynamicallyDispatchedBLSAttestationVerifierLib.verifyAttestation.selector
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import "./OCR3ECDSAAttestationVerifierLib.sol";
/// @title Shim for the core ECDSA attestation verifier library, allowing it to be pre-deployed separately.
/// @dev The function modifiers of the main interface functions are updated from internal to external.
library OCR3DynamicallyDispatchedECDSAAttestationVerifierLib {
function setVerificationKeys(
function setAttestationVerificationKeys(
uint256[32] storage s_ocr3EcdsaSignerPublicKeys,
uint8 n,
bytes calldata ocr3EcdsaSignerPublicKeys
) external {
OCR3ECDSAAttestationVerifierLib.setVerificationKeys(s_ocr3EcdsaSignerPublicKeys, n, ocr3EcdsaSignerPublicKeys);
OCR3ECDSAAttestationVerifierLib.setAttestationVerificationKeys(
s_ocr3EcdsaSignerPublicKeys, n, ocr3EcdsaSignerPublicKeys
);
}

function verifyAttestation(
Expand All @@ -26,11 +28,11 @@ library OCR3DynamicallyDispatchedECDSAAttestationVerifierLib {

// Function to initialize the selectors for delegate-calling into this library.
// Derived using keccak256 from the function signatures (without parameter names):
// - keccak256("setVerificationKeys(uint256[32] storage,uint8,bytes)")[:4]
// - keccak256("setAttestationVerificationKeys(uint256[32] storage,uint8,bytes)")[:4]
// - keccak256("verifyAttestation(uint256[32] storage,uint8,uint8,bytes32,bytes)")[:4]
function getSelectors() external pure returns (bytes4, bytes4) {
return (
OCR3DynamicallyDispatchedECDSAAttestationVerifierLib.setVerificationKeys.selector,
OCR3DynamicallyDispatchedECDSAAttestationVerifierLib.setAttestationVerificationKeys.selector,
OCR3DynamicallyDispatchedECDSAAttestationVerifierLib.verifyAttestation.selector
);
}
Expand Down
15 changes: 13 additions & 2 deletions contract3/OCR3ECDSAAttestationVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@ contract OCR3ECDSAAttestationVerifier is OCR3AttestationVerifierBase {
// entries is fine for smaller configurations, storage costs are only paid for the used number of keys.
uint256[32] s_ocr3EcdsaSignerPublicKeys;

function _setVerificationKeys(uint8 n, bytes calldata ocr3EcdsaSignerPublicKeys) internal override {
OCR3ECDSAAttestationVerifierLib.setVerificationKeys(s_ocr3EcdsaSignerPublicKeys, n, ocr3EcdsaSignerPublicKeys);
function _setAttestationVerificationKeys(uint8 n, bytes calldata ocr3EcdsaSignerPublicKeys) internal override {
OCR3ECDSAAttestationVerifierLib.setAttestationVerificationKeys(
s_ocr3EcdsaSignerPublicKeys, n, ocr3EcdsaSignerPublicKeys
);
}

/// @notice Address-typed convenience overload of `_setAttestationVerificationKeys`. Callers holding an
/// `address[]` (the common case on EVM chains) can use this directly, without ABI-encoding the keys into
/// the `bytes` layout and without supplying a redundant key count.
function _setAttestationVerificationKeys(address[] memory ocr3EcdsaSignerPublicKeys) internal {
OCR3ECDSAAttestationVerifierLib.setAttestationVerificationKeys(
s_ocr3EcdsaSignerPublicKeys, ocr3EcdsaSignerPublicKeys
);
}

function _verifyAttestation(
Expand Down
Loading
Loading