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
14 changes: 8 additions & 6 deletions contract3/OCR3AttestationVerifierBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ pragma solidity ^0.8.19;
/// @dev Defines the common method used to compute a Keccak-256 digest over a report and its context information.
abstract contract OCR3AttestationVerifierBase {
/// @notice Verifies and stores the list of provided public keys for later use within `verifyAttestation(...)`.
/// Reverts if an invalid number of keys was provided or any key is found invalid.
/// Reverts if an invalid number of keys was provided, any key is found invalid, or a duplicate key is
/// provided.
/// @param n The number of keys expected to be set by this call. Must match the actual number of keys present in
/// the `keys` parameter. The maximum number of keys supported is 32 (based on the width of the
/// attribution bitmask).
/// @param keys A concatenation of `n` public keys. The exact format of the key 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 keys) internal virtual;
/// 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;

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

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

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

// Raised when an attempt to set more than 32 verification keys is made.
Expand All @@ -17,6 +17,10 @@ error MaximumNumberOfKeysExceeded();
// - BLS: a key with an invalid proof-of-possession
error InvalidKey();

// 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();

// Raised when the signature verification failed for the provided attestation.
error InvalidAttestation();

Expand Down
10 changes: 5 additions & 5 deletions contract3/OCR3BLSAttestationVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import "./OCR3BLSAttestationVerifierLib.sol";
contract OCR3BLSAttestationVerifier is OCR3AttestationVerifierBase {
// Reserve storage for up to 32 BLS public keys. The current implementation supports up to 32 keys, limited by the
// width of the attribution bitmask used. Keeping the array size fixed at 32 entries is fine for smaller
// configurations, storage costs are only payed for the used number of keys.
OCR3BLSAttestationVerifierLib.G2PointAffine[32] s_keys;
// configurations, storage costs are only paid for the used number of keys.
OCR3BLSAttestationVerifierLib.G2PointAffine[32] s_ocr3BlsSignerPublicKeys;

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

function _verifyAttestation(
Expand All @@ -27,6 +27,6 @@ contract OCR3BLSAttestationVerifier is OCR3AttestationVerifierBase {
bytes calldata attestation
) internal view override {
bytes32 reportHash = _hashReport(configDigest, seqNr, report);
OCR3BLSAttestationVerifierLib.verifyAttestation(s_keys, n, f, reportHash, attestation);
OCR3BLSAttestationVerifierLib.verifyAttestation(s_ocr3BlsSignerPublicKeys, n, f, reportHash, attestation);
}
}
119 changes: 79 additions & 40 deletions contract3/OCR3BLSAttestationVerifierLib.sol

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions contract3/OCR3DynamicallyDispatchedAttestationVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ pragma solidity ^0.8.19;
import "./OCR3AttestationVerifierBase.sol";

/// @title Base contract for on-deployment linking of a ECDSA or BLS attestation verifier library
/// @dev The constructor takes an library address which must point to a deployed library of the following types:
// - OCR3DynamicallyDispatchedECDSAAttestationVerifierLib, or
// - OCR3DynamicallyDispatchedBLSAttestationVerifierLib.
/// @dev The constructor takes a library address which must point to a deployed library of the following types:
/// - OCR3DynamicallyDispatchedECDSAAttestationVerifierLib, or
/// - OCR3DynamicallyDispatchedBLSAttestationVerifierLib.
contract OCR3DynamicallyDispatchedAttestationVerifier is OCR3AttestationVerifierBase {
// Address of the pre-deployed library contact.
// Address of the pre-deployed library contract.
address immutable i_verifierLibraryAddress;

// Function selectors for the setVerificationKeys(...) and verifyAttestation(...) functions of the library.
Expand All @@ -18,7 +18,7 @@ contract OCR3DynamicallyDispatchedAttestationVerifier is OCR3AttestationVerifier
// Placeholder for reserving storage for up to 32 verification keys. The used library stores an implementation
// specific data structure within these reserved storages slots. 128 words are required for 32 keys, as each key is
// composed of 4 words in the BLS case.
uint256[128] s_keys;
uint256[128] s_ocr3SignerPublicKeys;

// Constructor used to specify the address of the predeployed verifier library to which the calls should be
// forwarded to.
Expand All @@ -30,7 +30,7 @@ contract OCR3DynamicallyDispatchedAttestationVerifier is OCR3AttestationVerifier
// 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) =
(OCR3DynamicallyDispatchedAttestationVerifierSelectorInterface(verifierLibraryAddress).getSelectors());
(OCR3DynamicallyDispatchedAttestationVerifierSelectorInterface(verifierLibraryAddress).getSelectors());
}

// Helper function to perform a delegate call to the underlying verifier library.
Expand All @@ -56,12 +56,12 @@ contract OCR3DynamicallyDispatchedAttestationVerifier is OCR3AttestationVerifier
}
}

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

function _verifyAttestation(
Expand All @@ -75,7 +75,7 @@ contract OCR3DynamicallyDispatchedAttestationVerifier is OCR3AttestationVerifier
bytes32 reportHash = _hashReport(configDigest, seqNr, report);
uint256 storagePtr;
assembly {
storagePtr := s_keys.slot
storagePtr := s_ocr3SignerPublicKeys.slot
}
_delegatecall(abi.encodeWithSelector(i_selectorVerifyAttestation, storagePtr, n, f, reportHash, attestation));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import "./OCR3BLSAttestationVerifierLib.sol";
/// @dev The function modifiers of the main interface functions are updated from internal to external.
library OCR3DynamicallyDispatchedBLSAttestationVerifierLib {
function setVerificationKeys(
OCR3BLSAttestationVerifierLib.G2PointAffine[32] storage s_verificationKeys,
OCR3BLSAttestationVerifierLib.G2PointAffine[32] storage s_ocr3BlsSignerPublicKeys,
uint8 n,
bytes calldata keys
bytes calldata ocr3BlsSignerPublicKeys
) external {
OCR3BLSAttestationVerifierLib.setVerificationKeys(s_verificationKeys, n, keys);
OCR3BLSAttestationVerifierLib.setVerificationKeys(s_ocr3BlsSignerPublicKeys, n, ocr3BlsSignerPublicKeys);
}

function verifyAttestation(
OCR3BLSAttestationVerifierLib.G2PointAffine[32] storage s_verificationKeys,
OCR3BLSAttestationVerifierLib.G2PointAffine[32] storage s_ocr3BlsSignerPublicKeys,
uint8 n,
uint8 f,
bytes32 reportHash,
bytes calldata attestation
) external view {
OCR3BLSAttestationVerifierLib.verifyAttestation(s_verificationKeys, n, f, reportHash, attestation);
OCR3BLSAttestationVerifierLib.verifyAttestation(s_ocr3BlsSignerPublicKeys, n, f, reportHash, attestation);
}

// Function to initialize the selectors for delegate-calling into this library.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ 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(uint256[32] storage s_keys, uint8 n, bytes calldata keys) external {
OCR3ECDSAAttestationVerifierLib.setVerificationKeys(s_keys, n, keys);
function setVerificationKeys(
uint256[32] storage s_ocr3EcdsaSignerPublicKeys,
uint8 n,
bytes calldata ocr3EcdsaSignerPublicKeys
) external {
OCR3ECDSAAttestationVerifierLib.setVerificationKeys(s_ocr3EcdsaSignerPublicKeys, n, ocr3EcdsaSignerPublicKeys);
}

function verifyAttestation(
uint256[32] storage s_keys,
uint256[32] storage s_ocr3EcdsaSignerPublicKeys,
uint8 n,
uint8 f,
bytes32 reportHash,
bytes calldata attestation
) external view {
OCR3ECDSAAttestationVerifierLib.verifyAttestation(s_keys, n, f, reportHash, attestation);
OCR3ECDSAAttestationVerifierLib.verifyAttestation(s_ocr3EcdsaSignerPublicKeys, n, f, reportHash, attestation);
}

// Function to initialize the selectors for delegate-calling into this library.
Expand Down
10 changes: 5 additions & 5 deletions contract3/OCR3ECDSAAttestationVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import "./OCR3ECDSAAttestationVerifierLib.sol";
contract OCR3ECDSAAttestationVerifier is OCR3AttestationVerifierBase {
// Reserve storage for up to 32 ECDSA public keys (i.e., the oracle's addresses). The current implementation
// supports up to 32 keys, limited by the width of the attribution bitmask used. Keeping the array size fixed at 32
// entries is fine for smaller configurations, storage costs are only payed for the used number of keys.
uint256[32] s_keys;
// 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 keys) internal override {
OCR3ECDSAAttestationVerifierLib.setVerificationKeys(s_keys, n, keys);
function _setVerificationKeys(uint8 n, bytes calldata ocr3EcdsaSignerPublicKeys) internal override {
OCR3ECDSAAttestationVerifierLib.setVerificationKeys(s_ocr3EcdsaSignerPublicKeys, n, ocr3EcdsaSignerPublicKeys);
}

function _verifyAttestation(
Expand All @@ -28,6 +28,6 @@ contract OCR3ECDSAAttestationVerifier is OCR3AttestationVerifierBase {
bytes calldata attestation
) internal view override {
bytes32 reportHash = _hashReport(configDigest, seqNr, report);
OCR3ECDSAAttestationVerifierLib.verifyAttestation(s_keys, n, f, reportHash, attestation);
OCR3ECDSAAttestationVerifierLib.verifyAttestation(s_ocr3EcdsaSignerPublicKeys, n, f, reportHash, attestation);
}
}
Loading
Loading