From cdd922433ff509d1108ec2541946e5b230697fff Mon Sep 17 00:00:00 2001 From: Vincent Geddes Date: Fri, 22 Dec 2023 15:13:45 +0200 Subject: [PATCH] Ensure commitPrevRandao called after submitInitial --- contracts/src/BeefyClient.sol | 4 ++++ contracts/test/BeefyClient.t.sol | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/contracts/src/BeefyClient.sol b/contracts/src/BeefyClient.sol index 72cd3f0fd2..bf40943a1a 100644 --- a/contracts/src/BeefyClient.sol +++ b/contracts/src/BeefyClient.sol @@ -299,6 +299,10 @@ contract BeefyClient { bytes32 ticketID = createTicketID(msg.sender, commitmentHash); Ticket storage ticket = tickets[ticketID]; + if (ticket.blockNumber == 0) { + revert InvalidTicket(); + } + if (ticket.prevRandao != 0) { revert PrevRandaoAlreadyCaptured(); } diff --git a/contracts/test/BeefyClient.t.sol b/contracts/test/BeefyClient.t.sol index eeb039ee28..8f74d10607 100644 --- a/contracts/test/BeefyClient.t.sol +++ b/contracts/test/BeefyClient.t.sol @@ -437,6 +437,11 @@ contract BeefyClientTest is Test { assertEq(beefyClient.getValidatorCounter(true, finalValidatorProofs[1].index), 0); } + function testCommitPrevRandaoCalledInSequence() public { + vm.expectRevert(BeefyClient.InvalidTicket.selector); + commitPrevRandao(); + } + function testSubmitWithHandoverAnd3SignatureCount() public { //initialize with previous set BeefyClient.Commitment memory commitment = initialize(setId - 1);