From 3dad39e1eadd5a205196f4143595335bd05cac7b Mon Sep 17 00:00:00 2001 From: Mark Bliss Date: Mon, 9 Sep 2024 15:33:20 +0200 Subject: [PATCH] fix: add check on isParticipatingInUpcomingRound (#270) --- src/Redistribution.sol | 8 +++++++- test/Redistribution.test.ts | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Redistribution.sol b/src/Redistribution.sol index 0e17cb71..3efdef56 100644 --- a/src/Redistribution.sol +++ b/src/Redistribution.sol @@ -801,11 +801,17 @@ contract Redistribution is AccessControl, Pausable { * @param _depth The storage depth the applicant intends to report. */ function isParticipatingInUpcomingRound(address _owner, uint8 _depth) public view returns (bool) { + uint256 _lastUpdate = Stakes.lastUpdatedBlockNumberOfAddress(_owner); + if (currentPhaseReveal()) { revert WrongPhase(); } - if (Stakes.lastUpdatedBlockNumberOfAddress(_owner) >= block.number - 2 * ROUND_LENGTH) { + if (_lastUpdate == 0) { + revert NotStaked(); + } + + if (_lastUpdate >= block.number - 2 * ROUND_LENGTH) { revert MustStake2Rounds(); } diff --git a/test/Redistribution.test.ts b/test/Redistribution.test.ts index 5f21c47a..0916695f 100644 --- a/test/Redistribution.test.ts +++ b/test/Redistribution.test.ts @@ -223,6 +223,16 @@ describe('Redistribution', function () { await expect(r_node_0.commit(obfuscatedHash_0, currentRound)).to.be.revertedWith(errors.commit.notStaked); }); + it('should not participation with unstaked node', async function () { + expect(await redistribution.currentPhaseCommit()).to.be.true; + + const r_node_0 = await ethers.getContract('Redistribution', node_0); + const currentRound = await r_node_0.currentRound(); + await expect(r_node_0['isParticipatingInUpcomingRound(address,uint8)'](node_0, depth_0)).to.be.revertedWith( + errors.commit.notStaked + ); + }); + it('should not create a commit with recently staked node', async function () { const sr_node_0 = await ethers.getContract('StakeRegistry', node_0); await mintAndApprove(deployer, node_0, sr_node_0.address, stakeAmount_0);