Skip to content

Commit

Permalink
fix: preconf + block tracker contracts now use their interfaces (#264)
Browse files Browse the repository at this point in the history
* fix: preconf contract now uses its interface

* fix: nit newline

* feat: bindings + abis + also add interface to block tracker

* fix: linter

* fix: revert "fix: linter"

This reverts commit e88c7d4.

* fix: restore original public functions
  • Loading branch information
shaspitz authored Jul 22, 2024
1 parent a0d9367 commit 985b84f
Show file tree
Hide file tree
Showing 7 changed files with 303 additions and 166 deletions.
10 changes: 5 additions & 5 deletions contracts-abi/abi/PreConfCommitmentStore.abi
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@
{
"name": "",
"type": "tuple",
"internalType": "struct PreConfCommitmentStore.PreConfCommitment",
"internalType": "struct IPreConfCommitmentStore.PreConfCommitment",
"components": [
{
"name": "bidder",
Expand Down Expand Up @@ -443,7 +443,7 @@
{
"name": "commitment",
"type": "tuple",
"internalType": "struct PreConfCommitmentStore.PreConfCommitment",
"internalType": "struct IPreConfCommitmentStore.PreConfCommitment",
"components": [
{
"name": "bidder",
Expand Down Expand Up @@ -546,7 +546,7 @@
{
"name": "",
"type": "tuple",
"internalType": "struct PreConfCommitmentStore.EncrPreConfCommitment",
"internalType": "struct IPreConfCommitmentStore.EncrPreConfCommitment",
"components": [
{
"name": "isUsed",
Expand Down Expand Up @@ -585,7 +585,7 @@
{
"name": "commitment",
"type": "tuple",
"internalType": "struct PreConfCommitmentStore.EncrPreConfCommitment",
"internalType": "struct IPreConfCommitmentStore.EncrPreConfCommitment",
"components": [
{
"name": "isUsed",
Expand Down Expand Up @@ -1090,7 +1090,7 @@
{
"name": "params",
"type": "tuple",
"internalType": "struct PreConfCommitmentStore.CommitmentParams",
"internalType": "struct IPreConfCommitmentStore.CommitmentParams",
"components": [
{
"name": "txnHash",
Expand Down

Large diffs are not rendered by default.

16 changes: 2 additions & 14 deletions contracts/contracts/BlockTracker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ pragma solidity 0.8.20;

import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {IBlockTracker} from "./interfaces/IBlockTracker.sol";

/**
* @title BlockTracker
* @dev A contract that tracks Ethereum blocks and their winners.
*/
contract BlockTracker is Ownable2StepUpgradeable, UUPSUpgradeable {
contract BlockTracker is IBlockTracker, Ownable2StepUpgradeable, UUPSUpgradeable {

/// @dev Permissioned address of the oracle account.
address public oracleAccount;
Expand All @@ -22,19 +23,6 @@ contract BlockTracker is Ownable2StepUpgradeable, UUPSUpgradeable {
/// @dev Maps builder names to their respective Ethereum addresses.
mapping(string => address) public blockBuilderNameToAddress;

/// @dev Event emitted when a new L1 block is tracked.
event NewL1Block(
uint256 indexed blockNumber,
address indexed winner,
uint256 indexed window
);

/// @dev Event emitted when a new window is created.
event NewWindow(uint256 indexed window);

/// @dev Event emitted when the oracle account is set.
event OracleAccountSet(address indexed oldOracleAccount, address indexed newOracleAccount);

/// @dev Modifier to ensure that the sender is the oracle account.
modifier onlyOracle() {
require(msg.sender == oracleAccount, "sender isn't oracle account");
Expand Down
84 changes: 3 additions & 81 deletions contracts/contracts/PreConfCommitmentStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,17 @@ import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/U
import {IProviderRegistry} from "./interfaces/IProviderRegistry.sol";
import {IBidderRegistry} from "./interfaces/IBidderRegistry.sol";
import {IBlockTracker} from "./interfaces/IBlockTracker.sol";
import {IPreConfCommitmentStore} from "./interfaces/IPreConfCommitmentStore.sol";
import {WindowFromBlockNumber} from "./utils/WindowFromBlockNumber.sol";

/**
* @title PreConfCommitmentStore - A contract for managing preconfirmation commitments and bids.
* @notice This contract allows bidders to make precommitments and bids and provides a mechanism for the oracle to verify and process them.
*/
contract PreConfCommitmentStore is Ownable2StepUpgradeable, UUPSUpgradeable {
contract PreConfCommitmentStore is IPreConfCommitmentStore, Ownable2StepUpgradeable, UUPSUpgradeable {

using ECDSA for bytes32;

/// @dev Struct for all the information around preconfirmations commitment
struct PreConfCommitment {
address bidder;
bool isUsed;
uint64 blockNumber;
uint64 decayStartTimeStamp;
uint64 decayEndTimeStamp;
uint64 dispatchTimestamp;
address commiter;
uint256 bid;
bytes32 bidHash;
bytes32 commitmentHash;
bytes bidSignature;
bytes commitmentSignature;
bytes sharedSecretKey;
string txnHash;
string revertingTxHashes;
}

/// @dev Struct for all the commitment params to avoid too deep in the stack error
struct CommitmentParams {
string txnHash;
string revertingTxHashes;
uint256 bid;
uint64 blockNumber;
uint64 decayStartTimeStamp;
uint64 decayEndTimeStamp;
bytes32 bidHash;
bytes bidSignature;
bytes commitmentSignature;
bytes sharedSecretKey;
}

/// @dev Struct for all the information around encrypted preconfirmations commitment
struct EncrPreConfCommitment {
bool isUsed;
address commiter;
uint64 dispatchTimestamp;
bytes32 commitmentDigest;
bytes commitmentSignature;
}

/// @dev EIP-712 Type Hash for preconfirmation commitment
bytes32 public constant EIP712_COMMITMENT_TYPEHASH =
keccak256(
Expand Down Expand Up @@ -124,43 +83,6 @@ contract PreConfCommitmentStore is Ownable2StepUpgradeable, UUPSUpgradeable {
/// @dev Only stores valid encrypted commitments
mapping(bytes32 => EncrPreConfCommitment) public encryptedCommitments;

/// @dev Event to log successful commitment storage
event CommitmentStored(
bytes32 indexed commitmentIndex,
address bidder,
address commiter,
uint256 bid,
uint64 blockNumber,
bytes32 bidHash,
uint64 decayStartTimeStamp,
uint64 decayEndTimeStamp,
string txnHash,
string revertingTxHashes,
bytes32 commitmentHash,
bytes bidSignature,
bytes commitmentSignature,
uint64 dispatchTimestamp,
bytes sharedSecretKey
);

/// @dev Event to log successful encrypted commitment storage
event EncryptedCommitmentStored(
bytes32 indexed commitmentIndex,
address commiter,
bytes32 commitmentDigest,
bytes commitmentSignature,
uint64 dispatchTimestamp
);

/// @dev Event to log successful verifications
event SignatureVerified(
address indexed signer,
string txnHash,
string revertingTxHashes,
uint256 indexed bid,
uint64 blockNumber
);

/**
* @dev Makes sure transaction sender is oracle
*/
Expand Down Expand Up @@ -377,9 +299,9 @@ contract PreConfCommitmentStore is Ownable2StepUpgradeable, UUPSUpgradeable {
encryptedCommitment.dispatchTimestamp,
sharedSecretKey
);

return commitmentIndex;
}

/**
* @dev Store an encrypted commitment.
* @param commitmentDigest The digest of the commitment.
Expand Down
14 changes: 10 additions & 4 deletions contracts/contracts/interfaces/IBlockTracker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ pragma solidity 0.8.20;

/// @title IBlockTracker interface for BlockTracker contract
interface IBlockTracker {
/// @notice Emitted when a new L1 block is recorded.
/// @param blockNumber The block number of the new L1 block.
/// @param winner The address of the winner of the new L1 block.
event NewL1Block(uint256 indexed blockNumber, address indexed winner);

/// @dev Event emitted when a new L1 block is tracked.
event NewL1Block(
uint256 indexed blockNumber,
address indexed winner,
uint256 indexed window
);

/// @notice Emitted when entering a new window.
/// @param window The new window number.
event NewWindow(uint256 indexed window);

/// @dev Event emitted when the oracle account is set.
event OracleAccountSet(address indexed oldOracleAccount, address indexed newOracleAccount);

/// @notice Records a new L1 block with its winner.
/// @param _blockNumber The block number of the new L1 block.
/// @param _winnerGrafitti The graffiti of the winner of the new L1 block.
Expand Down
Loading

0 comments on commit 985b84f

Please sign in to comment.