Skip to content

Commit

Permalink
Tests + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Fletch153 committed Nov 19, 2024
1 parent bfaff3e commit e27c382
Show file tree
Hide file tree
Showing 15 changed files with 262 additions and 396 deletions.
17 changes: 9 additions & 8 deletions contracts/src/v0.8/llo-feeds/v0.5.0/Verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ contract Verifier is IVerifier, ConfirmedOwner, TypeAndVersionInterface {
// The block number of the block the last time the configuration was updated.
uint32 latestConfigBlockNumber;
// Whether the config is deactivated
bool isDeactivated;
bool isActive;
// Fault tolerance
uint8 f;
// Map of signer addresses to oracles
Expand Down Expand Up @@ -182,14 +182,14 @@ contract Verifier is IVerifier, ConfirmedOwner, TypeAndVersionInterface {
bytes32 rawVs
) = abi.decode(signedReport, (bytes32[3], bytes, bytes32[], bytes32[], bytes32));

VerifierState storage verifierState = s_verifierStates[reportContext[0]];

// reportContext consists of:
// reportContext[0]: ConfigDigest
// reportContext[1]: 27 byte padding, 4-byte epoch and 1-byte round
// reportContext[2]: ExtraHash
bytes32 configDigest = reportContext[0];

VerifierState storage verifierState = s_verifierStates[configDigest];

_validateReport(configDigest, rs, ss, verifierState);

bytes32 hashedReport = keccak256(reportData);
Expand All @@ -213,7 +213,7 @@ contract Verifier is IVerifier, ConfirmedOwner, TypeAndVersionInterface {
) private view {
uint8 expectedNumSignatures = config.f + 1;

if (!config.isDeactivated) revert DigestInactive(configDigest);
if (!config.isActive) revert DigestInactive(configDigest);
if (rs.length != expectedNumSignatures) revert IncorrectSignatureCount(rs.length, expectedNumSignatures);
if (rs.length != ss.length) revert MismatchedSignatures(rs.length, ss.length);
}
Expand Down Expand Up @@ -326,6 +326,7 @@ contract Verifier is IVerifier, ConfirmedOwner, TypeAndVersionInterface {
verifierState.latestConfigBlockNumber = uint32(block.number);
verifierState.configCount = configCount;
verifierState.f = f;
verifierState.isActive = true;

for (uint8 i; i < signers.length; ++i) {
address signerAddr = signers[i];
Expand Down Expand Up @@ -405,8 +406,8 @@ contract Verifier is IVerifier, ConfirmedOwner, TypeAndVersionInterface {
)
);
uint256 prefixMask = type(uint256).max << (256 - 16); // 0xFFFF00..00
// 0x0006 corresponds to ConfigDigestPrefixMercuryV02 in libocr
uint256 prefix = 0x0009 << (256 - 16); // 0x000600..00
// 0x0009 corresponds to ConfigDigestPrefixMercuryV02 in libocr
uint256 prefix = 0x0009 << (256 - 16); // 0x000900..00
return bytes32((prefix & prefixMask) | (h & ~prefixMask));
}

Expand All @@ -416,7 +417,7 @@ contract Verifier is IVerifier, ConfirmedOwner, TypeAndVersionInterface {

if (configDigest == bytes32("")) revert DigestEmpty();
if (verifierState.f == 0) revert DigestNotSet(configDigest);
verifierState.isDeactivated = false;
verifierState.isActive = true;
emit ConfigActivated(configDigest);
}

Expand All @@ -426,7 +427,7 @@ contract Verifier is IVerifier, ConfirmedOwner, TypeAndVersionInterface {

if (configDigest == bytes32("")) revert DigestEmpty();
if (verifierState.f == 0) revert DigestNotSet(configDigest);
verifierState.isDeactivated = true;
verifierState.isActive = false;
emit ConfigDeactivated(configDigest);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ contract Verifier_setConfig is BaseTest {
function testSetConfigSuccess_gas() public {
s_verifier.setConfig(
FEED_ID,
SOURCE_CHAIN_ID,
SOURCE_ADDRESS,
1,
s_signerAddrs,
s_offchaintransmitters,
FAULT_TOLERANCE,
bytes(""),
VERIFIER_VERSION,
1,
bytes(""),
new Common.AddressAndWeight[](0)
);
Expand All @@ -44,7 +47,7 @@ contract Verifier_verifyWithFee is BaseTestWithConfiguredVerifierAndFeeManager {
//warm the rewardManager
link.mint(address(this), DEFAULT_NATIVE_MINT_QUANTITY);
_approveLink(address(rewardManager), DEFAULT_REPORT_LINK_FEE, address(this));
(, , bytes32 latestConfigDigest) = s_verifier.latestConfigDetails(FEED_ID);
bytes32 latestConfigDigest = v1ConfigDigest;

//mint some tokens to the user
link.mint(USER, DEFAULT_LINK_MINT_QUANTITY);
Expand Down Expand Up @@ -103,7 +106,7 @@ contract Verifier_bulkVerifyWithFee is BaseTestWithConfiguredVerifierAndFeeManag
//warm the rewardManager
link.mint(address(this), DEFAULT_NATIVE_MINT_QUANTITY);
_approveLink(address(rewardManager), DEFAULT_REPORT_LINK_FEE, address(this));
(, , bytes32 latestConfigDigest) = s_verifier.latestConfigDetails(FEED_ID);
bytes32 latestConfigDigest = v1ConfigDigest;

//mint some tokens to the user
link.mint(USER, DEFAULT_LINK_MINT_QUANTITY);
Expand Down Expand Up @@ -174,7 +177,7 @@ contract Verifier_verify is BaseTestWithConfiguredVerifierAndFeeManager {
BLOCKNUMBER_LOWER_BOUND,
uint32(block.timestamp)
);
(, , s_configDigest) = s_verifier.latestConfigDetails(FEED_ID);
s_configDigest = v1ConfigDigest;
bytes32[3] memory reportContext;
reportContext[0] = s_configDigest;
reportContext[1] = bytes32(abi.encode(uint32(5), uint8(1)));
Expand Down Expand Up @@ -213,7 +216,7 @@ contract Verifier_accessControlledVerify is BaseTestWithConfiguredVerifierAndFee
BLOCKNUMBER_LOWER_BOUND,
uint32(block.timestamp)
);
(, , s_configDigest) = s_verifier.latestConfigDetails(FEED_ID);
s_configDigest = v1ConfigDigest;
bytes32[3] memory reportContext;
reportContext[0] = s_configDigest;
reportContext[1] = bytes32(abi.encode(uint32(5), uint8(1)));
Expand Down
32 changes: 4 additions & 28 deletions contracts/src/v0.8/llo-feeds/v0.5.0/test/mocks/ErroredVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,8 @@ contract ErroredVerifier is IVerifier {
revert FailedToVerify();
}

function setConfig(
bytes32,
address[] memory,
bytes32[] memory,
uint8,
bytes memory,
uint64,
bytes memory,
Common.AddressAndWeight[] memory
) external pure override {
revert FailedToSetConfig();
}

function setConfigFromSource(
function setConfig(
bytes32,
uint256,
address,
Expand All @@ -69,27 +57,15 @@ contract ErroredVerifier is IVerifier {
revert FailedToSetConfig();
}

function activateConfig(bytes32, bytes32) external pure {
function activateConfig(bytes32) external pure {
revert FailedToActivateConfig();
}

function deactivateConfig(bytes32, bytes32) external pure {
function deactivateConfig(bytes32) external pure {
revert FailedToDeactivateConfig();
}

function activateFeed(bytes32) external pure {
revert FailedToActivateFeed();
}

function deactivateFeed(bytes32) external pure {
revert FailedToDeactivateFeed();
}

function latestConfigDigestAndEpoch(bytes32) external pure override returns (bool, bytes32, uint32) {
revert FailedToGetLatestConfigDigestAndEpoch();
}

function latestConfigDetails(bytes32) external pure override returns (uint32, uint32, bytes32) {
function latestConfigDetails(bytes32) external pure override returns (uint32, uint32) {
revert FailedToGetLatestConfigDetails();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ contract BaseTest is Test {
bytes32 internal constant V2_BITMASK = 0x0002000000000000000000000000000000000000000000000000000000000000;
bytes32 internal constant V3_BITMASK = 0x0003000000000000000000000000000000000000000000000000000000000000;

uint256 internal constant SOURCE_CHAIN_ID = 0x1234;
address internal constant SOURCE_ADDRESS = address(0x1234);

//version 0 feeds
bytes32 internal constant FEED_ID = (keccak256("ETH-USD") & V_MASK) | V1_BITMASK;
bytes32 internal constant FEED_ID_2 = (keccak256("LINK-USD") & V_MASK) | V1_BITMASK;
Expand Down Expand Up @@ -205,7 +208,7 @@ contract BaseTest is Test {
)
);
uint256 prefixMask = type(uint256).max << (256 - 16); // 0xFFFF00..00
uint256 prefix = 0x0006 << (256 - 16); // 0x000600..00
uint256 prefix = 0x0009 << (256 - 16); // 0x000900..00
return bytes32((prefix & prefixMask) | (h & ~prefixMask));
}

Expand Down Expand Up @@ -288,6 +291,9 @@ contract BaseTestWithConfiguredVerifierAndFeeManager is BaseTest {
s_verifierProxy.initializeVerifier(address(s_verifier));
s_verifier.setConfig(
FEED_ID,
SOURCE_CHAIN_ID,
SOURCE_ADDRESS,
1,
_getSignerAddresses(signers),
s_offchaintransmitters,
FAULT_TOLERANCE,
Expand All @@ -296,10 +302,25 @@ contract BaseTestWithConfiguredVerifierAndFeeManager is BaseTest {
bytes(""),
new Common.AddressAndWeight[](0)
);
(, , v1ConfigDigest) = s_verifier.latestConfigDetails(FEED_ID);

v1ConfigDigest = _configDigestFromConfigData(
FEED_ID,
SOURCE_CHAIN_ID,
SOURCE_ADDRESS,
1,
_getSignerAddresses(signers),
s_offchaintransmitters,
FAULT_TOLERANCE,
bytes(""),
VERIFIER_VERSION,
bytes("")
);

s_verifier.setConfig(
FEED_ID_V3,
SOURCE_CHAIN_ID,
SOURCE_ADDRESS,
1,
_getSignerAddresses(signers),
s_offchaintransmitters,
FAULT_TOLERANCE,
Expand All @@ -308,7 +329,19 @@ contract BaseTestWithConfiguredVerifierAndFeeManager is BaseTest {
bytes(""),
new Common.AddressAndWeight[](0)
);
(, , v3ConfigDigest) = s_verifier.latestConfigDetails(FEED_ID_V3);

v3ConfigDigest = _configDigestFromConfigData(
FEED_ID_V3,
SOURCE_CHAIN_ID,
SOURCE_ADDRESS,
1,
_getSignerAddresses(signers),
s_offchaintransmitters,
FAULT_TOLERANCE,
bytes(""),
VERIFIER_VERSION,
bytes("")
);

link = new ERC20Mock("LINK", "LINK", ADMIN, 0);
native = new WERC20Mock();
Expand Down Expand Up @@ -442,12 +475,15 @@ contract BaseTestWithMultipleConfiguredDigests is BaseTestWithConfiguredVerifier
BaseTestWithConfiguredVerifierAndFeeManager.setUp();
Signer[] memory signers = _getSigners(MAX_ORACLES);

(, , s_configDigestOne) = s_verifier.latestConfigDetails(FEED_ID);
s_configDigestOne = v1ConfigDigest;

// Verifier 1, Feed 1, Config 2
Signer[] memory secondSetOfSigners = _getSigners(8);
s_verifier.setConfig(
FEED_ID,
SOURCE_CHAIN_ID,
SOURCE_ADDRESS,
2,
_getSignerAddresses(secondSetOfSigners),
s_offchaintransmitters,
FAULT_TOLERANCE_TWO,
Expand All @@ -456,12 +492,27 @@ contract BaseTestWithMultipleConfiguredDigests is BaseTestWithConfiguredVerifier
bytes(""),
new Common.AddressAndWeight[](0)
);
(, , s_configDigestTwo) = s_verifier.latestConfigDetails(FEED_ID);

s_configDigestTwo = _configDigestFromConfigData(
FEED_ID,
SOURCE_CHAIN_ID,
SOURCE_ADDRESS,
2,
_getSignerAddresses(secondSetOfSigners),
s_offchaintransmitters,
FAULT_TOLERANCE_TWO,
bytes(""),
2,
bytes("")
);

// Verifier 1, Feed 1, Config 3
Signer[] memory thirdSetOfSigners = _getSigners(5);
s_verifier.setConfig(
FEED_ID,
SOURCE_CHAIN_ID,
SOURCE_ADDRESS,
3,
_getSignerAddresses(thirdSetOfSigners),
s_offchaintransmitters,
FAULT_TOLERANCE_THREE,
Expand All @@ -470,11 +521,25 @@ contract BaseTestWithMultipleConfiguredDigests is BaseTestWithConfiguredVerifier
bytes(""),
new Common.AddressAndWeight[](0)
);
(s_numConfigsSet, , s_configDigestThree) = s_verifier.latestConfigDetails(FEED_ID);
s_configDigestThree = _configDigestFromConfigData(
FEED_ID,
SOURCE_CHAIN_ID,
SOURCE_ADDRESS,
3,
_getSignerAddresses(thirdSetOfSigners),
s_offchaintransmitters,
FAULT_TOLERANCE_THREE,
bytes(""),
3,
bytes("")
);

// Verifier 1, Feed 2, Config 1
s_verifier.setConfig(
FEED_ID_2,
SOURCE_CHAIN_ID,
SOURCE_ADDRESS,
1,
_getSignerAddresses(signers),
s_offchaintransmitters,
FAULT_TOLERANCE,
Expand All @@ -483,20 +548,45 @@ contract BaseTestWithMultipleConfiguredDigests is BaseTestWithConfiguredVerifier
bytes(""),
new Common.AddressAndWeight[](0)
);
(, , s_configDigestFour) = s_verifier.latestConfigDetails(FEED_ID_2);
s_configDigestFour = _configDigestFromConfigData(
FEED_ID_2,
SOURCE_CHAIN_ID,
SOURCE_ADDRESS,
1,
_getSignerAddresses(signers),
s_offchaintransmitters,
FAULT_TOLERANCE,
bytes(""),
4,
bytes("")
);

// Verifier 2, Feed 3, Config 1
s_verifierProxy.initializeVerifier(address(s_verifier_2));
s_verifier_2.setConfig(
FEED_ID_3,
SOURCE_CHAIN_ID,
SOURCE_ADDRESS,
1,
_getSignerAddresses(signers),
s_offchaintransmitters,
FAULT_TOLERANCE,
bytes(""),
VERIFIER_VERSION,
5,
bytes(""),
new Common.AddressAndWeight[](0)
);
(, , s_configDigestFive) = s_verifier_2.latestConfigDetails(FEED_ID_3);
s_configDigestFive = _configDigestFromConfigData(
FEED_ID_3,
SOURCE_CHAIN_ID,
SOURCE_ADDRESS,
1,
_getSignerAddresses(signers),
s_offchaintransmitters,
FAULT_TOLERANCE,
bytes(""),
5,
bytes("")
);
}
}
Loading

0 comments on commit e27c382

Please sign in to comment.