Skip to content
Open
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
58 changes: 0 additions & 58 deletions .github/workflows/node.js.yml

This file was deleted.

51 changes: 0 additions & 51 deletions .github/workflows/staticdocs.yml

This file was deleted.

3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

28 changes: 24 additions & 4 deletions contracts/PreConfirmations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ contract PreConfCommitmentStore is Ownable {
bytes32 public constant EIP712_BID_TYPEHASH =
keccak256("PreConfBid(string txnHash,uint64 bid,uint64 blockNumber,uint64 decayStartTimeStamp,uint64 decayEndTimeStamp)");

uint64 public COMMITMENT_DISPATCH_WINDOW;

/// @dev commitment counter
uint256 public commitmentCount;

Expand Down Expand Up @@ -75,7 +77,7 @@ contract PreConfCommitmentStore is Ownable {
bytes32 commitmentHash;
bytes bidSignature;
bytes commitmentSignature;
uint256 blockCommitedAt;
uint64 dispatchTimestamp;
}

/// @dev Event to log successful verifications
Expand Down Expand Up @@ -119,7 +121,8 @@ contract PreConfCommitmentStore is Ownable {
address _providerRegistry,
address _bidderRegistry,
address _oracle,
address _owner
address _owner,
uint64 _commitment_dispatch_window
) {
oracle = _oracle;
providerRegistry = IProviderRegistry(_providerRegistry);
Expand All @@ -142,6 +145,15 @@ contract PreConfCommitmentStore is Ownable {
keccak256("1")
)
);
COMMITMENT_DISPATCH_WINDOW = _commitment_dispatch_window;
}

/**
* @dev Updates the commitment dispatch window to a new value. This function can only be called by the contract owner.
* @param newDispatchWindow The new dispatch window value to be set.
*/
function updateCommitmentDispatchWindow(uint64 newDispatchWindow) external onlyOwner {
COMMITMENT_DISPATCH_WINDOW = newDispatchWindow;
}

/**
Expand Down Expand Up @@ -289,13 +301,16 @@ contract PreConfCommitmentStore is Ownable {
);
}



/**
* @dev Store a commitment.
* @param bid The bid amount.
* @param blockNumber The block number.
* @param txnHash The transaction hash.
* @param bidSignature The signature of the bid.
* @param commitmentSignature The signature of the commitment.
* @param dispatchTimestamp The timestamp at which the commitment is dispatched
* @return commitmentIndex The index of the stored commitment
*/
function storeCommitment(
Expand All @@ -305,7 +320,8 @@ contract PreConfCommitmentStore is Ownable {
uint64 decayStartTimeStamp,
uint64 decayEndTimeStamp,
bytes calldata bidSignature,
bytes memory commitmentSignature
bytes memory commitmentSignature,
uint64 dispatchTimestamp
) public returns (bytes32 commitmentIndex) {
(bytes32 bHash, address bidderAddress, uint256 stake) = verifyBid(
bid,
Expand All @@ -315,6 +331,10 @@ contract PreConfCommitmentStore is Ownable {
txnHash,
bidSignature
);

require(block.timestamp >= dispatchTimestamp, "Invalid dispatch timestamp, block.timestamp < dispatchTimestamp");
require(block.timestamp - dispatchTimestamp < COMMITMENT_DISPATCH_WINDOW, "Invalid dispatch timestamp, block.timestamp - dispatchTimestamp < COMMITMENT_DISPATCH_WINDOW");

// This helps in avoiding stack too deep
{
bytes32 commitmentDigest = getPreConfHash(
Expand Down Expand Up @@ -345,7 +365,7 @@ contract PreConfCommitmentStore is Ownable {
commitmentDigest,
bidSignature,
commitmentSignature,
block.number
dispatchTimestamp
);

commitmentIndex = getCommitmentIndex(newCommitment);
Expand Down
11 changes: 7 additions & 4 deletions contracts/interfaces/IPreConfirmations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface IPreConfCommitmentStore {
bytes32 commitmentHash;
bytes bidSignature;
bytes commitmentSignature;
uint256 blockCommitedAt;
uint64 dispatchTimestamp;
}


Expand Down Expand Up @@ -65,13 +65,16 @@ interface IPreConfCommitmentStore {
uint64 bid,
uint64 blockNumber,
string memory txnHash,
string memory commitmentHash,
uint64 decayStartTimeStamp,
uint64 decayEndTimeStamp,
bytes calldata bidSignature,
bytes memory commitmentSignature
) external returns (uint256);
bytes memory commitmentSignature,
uint64 dispatchTimestamp
) external returns (bytes32 commitmentIndex);

function getCommitmentsByBlockNumber(uint256 blockNumber) external view returns (bytes32[] memory);

function updateCommitmentDispatchWindow(uint64 newDispatchWindow) external;

function getCommitment(bytes32 commitmentIndex) external view returns (PreConfCommitment memory);

Expand Down
3 changes: 2 additions & 1 deletion scripts/DeployScripts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ contract DeployScript is Script, Create2Deployer {
address feeRecipient = address(0x68bC10674b265f266b4b1F079Fa06eF4045c3ab9);
uint16 feePercent = 2;
uint256 nextRequestedBlockNumber = 4958905;
uint64 commitmentDispatchWindow = 250;

// Forge deploy with salt uses create2 proxy from https://github.com/primevprotocol/deterministic-deployment-proxy
bytes32 salt = 0x8989000000000000000000000000000000000000000000000000000000000000;
Expand All @@ -54,7 +55,7 @@ contract DeployScript is Script, Create2Deployer {
ProviderRegistry providerRegistry = new ProviderRegistry{salt: salt}(minStake, feeRecipient, feePercent, msg.sender);
console.log("ProviderRegistry deployed to:", address(providerRegistry));

PreConfCommitmentStore preConfCommitmentStore = new PreConfCommitmentStore{salt: salt}(address(providerRegistry), address(bidderRegistry), feeRecipient, msg.sender);
PreConfCommitmentStore preConfCommitmentStore = new PreConfCommitmentStore{salt: salt}(address(providerRegistry), address(bidderRegistry), feeRecipient, msg.sender, commitmentDispatchWindow);
console.log("PreConfCommitmentStore deployed to:", address(preConfCommitmentStore));

providerRegistry.setPreconfirmationsContract(address(preConfCommitmentStore));
Expand Down
43 changes: 25 additions & 18 deletions test/OracleTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ contract OracleTest is Test {
bytes32 commitmentDigest;
bytes bidSignature;
bytes commitmentSignature;
uint64 dispatchTimestamp;
}

// Events to match against
Expand All @@ -53,7 +54,8 @@ contract OracleTest is Test {
0xa0327970258c49b922969af74d60299a648c50f69a2d98d6ab43f32f64ac2100,
0x54c118e537dd7cf63b5388a5fc8322f0286a978265d0338b108a8ca9d155dccc,
hex"876c1216c232828be9fabb14981c8788cebdf6ed66e563c4a2ccc82a577d052543207aeeb158a32d8977736797ae250c63ef69a82cd85b727da21e20d030fb311b",
hex"ec0f11f77a9e96bb9c2345f031a5d12dca8d01de8a2e957cf635be14802f9ad01c6183688f0c2672639e90cc2dce0662d9bea3337306ca7d4b56dd80326aaa231b"
hex"ec0f11f77a9e96bb9c2345f031a5d12dca8d01de8a2e957cf635be14802f9ad01c6183688f0c2672639e90cc2dce0662d9bea3337306ca7d4b56dd80326aaa231b",
1000
);

feePercent = 10;
Expand All @@ -71,7 +73,8 @@ contract OracleTest is Test {
address(providerRegistry), // Provider Registry
address(bidderRegistry), // User Registry
feeRecipient, // Oracle
address(this) // Owner
address(this),
500
);

address ownerInstance = 0x6d503Fd50142C7C469C7c6B64794B55bfa6883f3;
Expand All @@ -86,6 +89,7 @@ contract OracleTest is Test {
preConfCommitmentStore.updateOracle(address(oracle));
bidderRegistry.setPreconfirmationsContract(address(preConfCommitmentStore));
providerRegistry.setPreconfirmationsContract(address(preConfCommitmentStore));
vm.warp(1010);

}

Expand Down Expand Up @@ -142,7 +146,8 @@ contract OracleTest is Test {
_testCommitmentAliceBob.decayStartTimestamp,
_testCommitmentAliceBob.decayEndTimestamp,
bidderPk,
providerPk
providerPk,
_testCommitmentAliceBob.dispatchTimestamp
);

string[] memory txnList = new string[](1);
Expand Down Expand Up @@ -172,7 +177,7 @@ contract OracleTest is Test {
providerRegistry.registerAndStake{value: 250 ether}();
vm.stopPrank();

bytes32 index = constructAndStoreCommitment(bid, blockNumber, txn, 10, 20, bidderPk, providerPk);
bytes32 index = constructAndStoreCommitment(bid, blockNumber, txn, 10, 20, bidderPk, providerPk, 1000);

vm.startPrank(address(0x6d503Fd50142C7C469C7c6B64794B55bfa6883f3));
oracle.addBuilderAddress(blockBuilderName, provider);
Expand Down Expand Up @@ -202,7 +207,7 @@ contract OracleTest is Test {
providerRegistry.registerAndStake{value: 250 ether}();
vm.stopPrank();

bytes32 index = constructAndStoreCommitment(bid, blockNumber, txn, 10, 20, bidderPk, providerPk);
bytes32 index = constructAndStoreCommitment(bid, blockNumber, txn, 10, 20, bidderPk, providerPk, 1000);

vm.startPrank(address(0x6d503Fd50142C7C469C7c6B64794B55bfa6883f3));
oracle.addBuilderAddress(blockBuilderName, provider);
Expand Down Expand Up @@ -236,8 +241,8 @@ contract OracleTest is Test {
providerRegistry.registerAndStake{value: 250 ether}();
vm.stopPrank();

bytes32 index1 = constructAndStoreCommitment(bid, blockNumber, txn1, 10, 20, bidderPk, providerPk);
bytes32 index2 = constructAndStoreCommitment(bid, blockNumber, txn2, 10, 20, bidderPk, providerPk);
bytes32 index1 = constructAndStoreCommitment(bid, blockNumber, txn1, 10, 20, bidderPk, providerPk,1000);
bytes32 index2 = constructAndStoreCommitment(bid, blockNumber, txn2, 10, 20, bidderPk, providerPk,1000);

vm.startPrank(address(0x6d503Fd50142C7C469C7c6B64794B55bfa6883f3));
oracle.addBuilderAddress(blockBuilderName, provider);
Expand Down Expand Up @@ -276,10 +281,10 @@ contract OracleTest is Test {
providerRegistry.registerAndStake{value: 250 ether}();
vm.stopPrank();

bytes32 index1 = constructAndStoreCommitment(bid, blockNumber, txn1, 10, 20, bidderPk, providerPk);
bytes32 index2 = constructAndStoreCommitment(bid, blockNumber, txn2, 10, 20, bidderPk, providerPk);
bytes32 index3 = constructAndStoreCommitment(bid, blockNumber, txn3, 10, 20, bidderPk, providerPk);
bytes32 index4 = constructAndStoreCommitment(bid, blockNumber, txn4, 10, 20, bidderPk, providerPk);
bytes32 index1 = constructAndStoreCommitment(bid, blockNumber, txn1, 10, 20, bidderPk, providerPk,1000);
bytes32 index2 = constructAndStoreCommitment(bid, blockNumber, txn2, 10, 20, bidderPk, providerPk,1000);
bytes32 index3 = constructAndStoreCommitment(bid, blockNumber, txn3, 10, 20, bidderPk, providerPk,1000);
bytes32 index4 = constructAndStoreCommitment(bid, blockNumber, txn4, 10, 20, bidderPk, providerPk,1000);


vm.startPrank(address(0x6d503Fd50142C7C469C7c6B64794B55bfa6883f3));
Expand Down Expand Up @@ -323,13 +328,13 @@ contract OracleTest is Test {
providerRegistry.registerAndStake{value: 250 ether}();
vm.stopPrank();

bytes32 index1 = constructAndStoreCommitment(bid, blockNumber, txn1, 10, 20, bidderPk, providerPk);
bytes32 index1 = constructAndStoreCommitment(bid, blockNumber, txn1, 10, 20, bidderPk, providerPk ,1000);
assertEq(bidderRegistry.bidderPrepaidBalances(bidder), 250 ether - bid);
bytes32 index2 = constructAndStoreCommitment(bid, blockNumber, txn2, 10, 20, bidderPk, providerPk);
bytes32 index2 = constructAndStoreCommitment(bid, blockNumber, txn2, 10, 20, bidderPk, providerPk ,1000);
assertEq(bidderRegistry.bidderPrepaidBalances(bidder), 250 ether - 2*bid);
bytes32 index3 = constructAndStoreCommitment(bid, blockNumber, txn3, 10, 20, bidderPk, providerPk);
bytes32 index3 = constructAndStoreCommitment(bid, blockNumber, txn3, 10, 20, bidderPk, providerPk, 1000);
assertEq(bidderRegistry.bidderPrepaidBalances(bidder), 250 ether - 3*bid);
bytes32 index4 = constructAndStoreCommitment(bid, blockNumber, txn4, 10, 20, bidderPk, providerPk);
bytes32 index4 = constructAndStoreCommitment(bid, blockNumber, txn4, 10, 20, bidderPk, providerPk, 1000);
assertEq(bidderRegistry.bidderPrepaidBalances(bidder), 250 ether - 4*bid);

vm.startPrank(address(0x6d503Fd50142C7C469C7c6B64794B55bfa6883f3));
Expand Down Expand Up @@ -370,7 +375,7 @@ contract OracleTest is Test {
providerRegistry.registerAndStake{value: 250 ether}();
vm.stopPrank();

bytes32 index = constructAndStoreCommitment(bid, blockNumber, txn, 10, 20, bidderPk, providerPk);
bytes32 index = constructAndStoreCommitment(bid, blockNumber, txn, 10, 20, bidderPk, providerPk, 1000);
PreConfCommitmentStore.PreConfCommitment memory commitment = preConfCommitmentStore.getCommitment(index);

vm.startPrank(address(0x6d503Fd50142C7C469C7c6B64794B55bfa6883f3));
Expand All @@ -397,7 +402,8 @@ contract OracleTest is Test {
uint64 decayStartTimestamp,
uint64 decayEndTimestamp,
uint256 bidderPk,
uint256 signerPk
uint256 signerPk,
uint64 dispatchTimestamp
) public returns (bytes32 commitmentIndex) {
bytes32 bidHash = preConfCommitmentStore.getBidHash(
txnHash,
Expand Down Expand Up @@ -431,7 +437,8 @@ contract OracleTest is Test {
decayStartTimestamp,
decayEndTimestamp,
bidSignature,
commitmentSignature
commitmentSignature,
dispatchTimestamp
);

return commitmentIndex;
Expand Down
Loading