From 2eb4aafffa18183e96ffd2d25794c892388570d0 Mon Sep 17 00:00:00 2001 From: VP Date: Thu, 21 Mar 2024 15:38:06 +0100 Subject: [PATCH] feat: aggregate getReport() implementation --- contracts/0.8.9/oracle/Multiprover.sol | 56 ++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/contracts/0.8.9/oracle/Multiprover.sol b/contracts/0.8.9/oracle/Multiprover.sol index 5d43ff6d3..a13757d0d 100644 --- a/contracts/0.8.9/oracle/Multiprover.sol +++ b/contracts/0.8.9/oracle/Multiprover.sol @@ -45,6 +45,13 @@ contract Multiprover is ILidoZKOracle, AccessControlEnumerable { /// @dev Oracle committee members quorum value, must be larger than totalMembers // 2 uint256 internal _quorum; + struct Report { + bool success; + uint256 clBalanceGwei; + uint256 numValidators; + uint256 exitedValidators; + } + constructor( address admin ) { @@ -146,17 +153,60 @@ contract Multiprover is ILidoZKOracle, AccessControlEnumerable { /// Implementation: LidoZKOracle /// + // Helper function to check if two reports are identical + function _areReportsIdentical(Report memory a, Report memory b) internal pure returns (bool) { + return a.success == b.success && + a.clBalanceGwei == b.clBalanceGwei && + a.numValidators == b.numValidators && + a.exitedValidators == b.exitedValidators; + } + + // Helper function to request a report from an oracle + function _requestReportFromOracle(ILidoZKOracle oracle, uint256 refSlot) internal view + returns (Report memory) { + (bool success, uint256 clBalanceGwei, uint256 numValidators, uint256 exitedValidators) = oracle.getReport(refSlot); + return Report(success, clBalanceGwei, numValidators, exitedValidators); + } + function getReport(uint256 refSlot) external view override returns ( bool success, uint256 clBalanceGwei, uint256 numValidators, uint256 exitedValidators ) { - refSlot; - return (true, 100, 100, 100); - } + Report[] memory reportsData = new Report[](_memberAddresses.length); + uint256[] memory reportCounts = new uint256[](_memberAddresses.length); + uint256 reports = 0; + + for (uint256 i = 0; i < _memberAddresses.length; i++) { + ILidoZKOracle oracle = ILidoZKOracle(_memberAddresses[i]); + Report memory report = _requestReportFromOracle(oracle, refSlot); + if (report.success) { + uint256 currentReportCount = 0; + for (uint256 j = 0; j < reports; j++) { + if (_areReportsIdentical(reportsData[j], report)) { + reportCounts[j]++; + currentReportCount = reportCounts[j]; + break; + } + } + if (currentReportCount == 0) { + reportsData[reports] = report; + reportCounts[reports] = 1; + currentReportCount = 1; + reports++; + } + if (currentReportCount >= _quorum) { + return (report.success, report.clBalanceGwei, report.numValidators, report.exitedValidators); + } + } + } + return (false, 0, 0, 0); + } /// /// Implementation: Auto-resettable fuse /// + + // TODO: implement the fuse } \ No newline at end of file