-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathEigenLayerBeaconOracle.sol
More file actions
72 lines (61 loc) · 2.75 KB
/
EigenLayerBeaconOracle.sol
File metadata and controls
72 lines (61 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
pragma solidity ^0.8.16;
import {ILightClient} from "src/lightclient/interfaces/ILightClient.sol";
import {SSZ} from "src/libraries/SimpleSerialize.sol";
import {BeaconOracleHelper} from "external/integrations/libraries/BeaconOracleHelper.sol";
import {EigenLayerBeaconOracleStorage} from
"external/integrations/eigenlayer/EigenLayerBeaconOracleStorage.sol";
import {ReentrancyGuardUpgradeable} from
"@openzeppelin-upgradeable/contracts/security/ReentrancyGuardUpgradeable.sol";
contract EigenLayerBeaconOracle is EigenLayerBeaconOracleStorage {
event EigenLayerBeaconOracleUpdate(uint256 slot, uint256 timestamp, bytes32 blockRoot);
error InvalidUpdater(address updater);
error SlotNumberTooLow();
modifier onlyWhitelistedUpdater() {
if (!whitelistedOracleUpdaters[msg.sender]) {
revert InvalidUpdater(msg.sender);
}
_;
}
/// @notice Get beacon block root for the given timestamp
function getBeaconBlockRoot(uint256 _timestamp) external view returns (bytes32) {
return timestampToBlockRoot[_timestamp];
}
/// @notice Fulfill request for a given timestamp (associated with a block)
function fulfillRequest(
BeaconOracleHelper.BeaconStateRootProofInfo calldata _sourceBeaconStateRootProofInfo,
BeaconOracleHelper.TargetBeaconBlockRootProofInfo calldata _targetBeaconBlockRootProofInfo,
bytes32[] calldata _targetTimestampProof,
uint256 _targetTimestamp
) external onlyWhitelistedUpdater {
// Get the source beacon block header root.
bytes32 sourceHeaderRoot = ILightClient(lightclient).headers(
_sourceBeaconStateRootProofInfo.slot
);
// Extract the source beacon state root.
BeaconOracleHelper.verifyBeaconStateRoot(
_sourceBeaconStateRootProofInfo,
sourceHeaderRoot
);
// Verify the target beacon block root.
bytes32 sourceBeaconStateRoot = _sourceBeaconStateRootProofInfo.beaconStateRoot;
BeaconOracleHelper.verifyTargetBeaconBlockRoot(
_targetBeaconBlockRootProofInfo,
sourceBeaconStateRoot
);
// Verify timestamp against target block header root.
bytes32 targetBeaconBlockRoot = _targetBeaconBlockRootProofInfo.targetBeaconBlockRoot;
BeaconOracleHelper.verifyTimestamp(
_targetTimestamp,
_targetTimestampProof,
targetBeaconBlockRoot
);
// Store the target block header root
timestampToBlockRoot[_targetTimestamp] = targetBeaconBlockRoot;
// Emit the event.
emit EigenLayerBeaconOracleUpdate(
_targetBeaconBlockRootProofInfo.targetSlot,
_targetTimestamp,
targetBeaconBlockRoot
);
}
}