Skip to content

Commit

Permalink
wip: test stacked multiple commitments
Browse files Browse the repository at this point in the history
  • Loading branch information
merklefruit committed Sep 26, 2024
1 parent d689f13 commit f1f361c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions bolt-contracts/src/contracts/BoltChallenger.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {console} from "forge-std/Test.sol";

import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {Time} from "@openzeppelin/contracts/utils/types/Time.sol";
Expand Down Expand Up @@ -126,6 +128,11 @@ contract BoltChallenger is IBoltChallenger {
(address txSender, address commitmentSigner, TransactionData memory firstTransactionData) =
_recoverCommitmentData(commitments[0]);

console.log("first");
console.log(txSender);
console.log(commitmentSigner);
console.logBytes32(firstTransactionData.txHash);

transactionsData[0] = firstTransactionData;

for (uint256 i = 1; i < commitments.length; i++) {
Expand All @@ -134,6 +141,11 @@ contract BoltChallenger is IBoltChallenger {

transactionsData[i] = otherTransactionData;

console.log("other");
console.log(otherTxSender);
console.log(otherCommitmentSigner);
console.logBytes32(otherTransactionData.txHash);

// check that all commitments are for the same slot
if (commitments[i].slot != targetSlot) {
revert UnexpectedMixedSlots();
Expand Down
19 changes: 19 additions & 0 deletions bolt-contracts/test/BoltChallenger.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,29 @@ contract BoltChallengerTest is Test {
// Prove the full defense of a challenge: the block headers, account proof, and tx proofs
// are all valid and the proposer has included the transaction in their slot.
// This time, the proposer has committed to multiple transactions in their slot.
//
// The test data for this test was generated by querying for an Ethereum block with a
// sender that has sent multiple transactions in the same block.
// Check out https://etherscan.io/block/20817618

uint256 inclusionBlockNumber = 20_817_618;
IBoltChallenger.SignedCommitment[] memory commitments = new IBoltChallenger.SignedCommitment[](3);
commitments[0] = _createRecentBoltCommitment(inclusionBlockNumber, 1);
commitments[1] = _createRecentBoltCommitment(inclusionBlockNumber, 2);
commitments[2] = _createRecentBoltCommitment(inclusionBlockNumber, 3);

// Sanity check senders of the transactions: they should all be the same
for (uint256 i = 0; i < commitments.length; i++) {
address recovered = commitments[i].signedTx.decodeEnveloped().recoverSender();
assertEq(recovered, 0xc21fb45Eeb45D883B838E30ABBd2896aE5AC888c);
}

// Sanity check signers of the commitments: they should all be the same
for (uint256 i = 0; i < commitments.length; i++) {
address signer = ECDSA.recover(_computeCommitmentID(commitments[i].signedTx, commitments[i].slot), commitments[i].signature);
assertEq(signer, target);
}

// Open a challenge
vm.prank(challenger);
boltChallenger.openChallenge{value: 1 ether}(commitments);
Expand Down Expand Up @@ -436,6 +452,9 @@ contract BoltChallengerTest is Test {
(uint8 v, bytes32 r, bytes32 s) = vm.sign(targetPK, commitmentID);
commitment.signature = abi.encodePacked(r, s, v);

// Sanity check
assertEq(ECDSA.recover(commitmentID, commitment.signature), target);

return commitment;
}

Expand Down

0 comments on commit f1f361c

Please sign in to comment.