Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Certora][M-06] Deprecate Whitelist in AuctionManager.sol #173

Merged
merged 3 commits into from
Nov 12, 2024
Merged
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
73 changes: 10 additions & 63 deletions src/AuctionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract AuctionManager is
//--------------------------------- STATE-VARIABLES ----------------------------------
//--------------------------------------------------------------------------------------

uint128 public whitelistBidAmount;
uint128 public DEPRECATED_whitelistBidAmount;
uint64 public minBidAmount;
uint64 public maxBidAmount;
uint256 public numberOfBids;
Expand All @@ -35,7 +35,7 @@ contract AuctionManager is
IProtocolRevenueManager public DEPRECATED_protocolRevenueManager;

address public stakingManagerContractAddress;
bool public whitelistEnabled;
bool public DEPRECATED_whitelistEnabled;

mapping(uint256 => Bid) public bids;

Expand Down Expand Up @@ -63,8 +63,6 @@ contract AuctionManager is
event BidCreated(address indexed bidder, uint256 amountPerBid, uint256[] bidIdArray, uint64[] ipfsIndexArray);
event BidCancelled(uint256 indexed bidId);
event BidReEnteredAuction(uint256 indexed bidId);
event WhitelistDisabled(bool whitelistStatus);
event WhitelistEnabled(bool whitelistStatus);

error IncorrectRole();

Expand All @@ -83,11 +81,11 @@ contract AuctionManager is
) external initializer {
require(_nodeOperatorManagerContract != address(0), "No Zero Addresses");

whitelistBidAmount = 0.001 ether;
DEPRECATED_whitelistBidAmount = 0.001 ether;
minBidAmount = 0.01 ether;
maxBidAmount = 5 ether;
numberOfBids = 1;
whitelistEnabled = true;
DEPRECATED_whitelistEnabled = true;

nodeOperatorManager = INodeOperatorManager(_nodeOperatorManagerContract);

Expand Down Expand Up @@ -122,36 +120,13 @@ contract AuctionManager is
uint256 _bidAmountPerBid
) external payable whenNotPaused nonReentrant returns (uint256[] memory) {
require(_bidSize > 0, "Bid size is too small");
if (whitelistEnabled) {
require(
nodeOperatorManager.isWhitelisted(msg.sender),
"Only whitelisted addresses"
);
require(
msg.value == _bidSize * _bidAmountPerBid &&
_bidAmountPerBid >= whitelistBidAmount &&
_bidAmountPerBid <= maxBidAmount,
"Incorrect bid value"
);
} else {
if (
nodeOperatorManager.isWhitelisted(msg.sender)
) {
require(
msg.value == _bidSize * _bidAmountPerBid &&
_bidAmountPerBid >= whitelistBidAmount &&
_bidAmountPerBid <= maxBidAmount,
"Incorrect bid value"
);
} else {
require(
require(
msg.value == _bidSize * _bidAmountPerBid &&
_bidAmountPerBid >= minBidAmount &&
_bidAmountPerBid <= maxBidAmount,
"Incorrect bid value"
);
}
}

uint64 keysRemaining = nodeOperatorManager.getNumKeysRemaining(msg.sender);
require(_bidSize <= keysRemaining, "Insufficient public keys");

Expand Down Expand Up @@ -247,24 +222,6 @@ contract AuctionManager is
require(sent, "Failed to send Ether");
}

/// @notice Disables the whitelisting phase of the bidding
/// @dev Allows both regular users and whitelisted users to bid
function disableWhitelist() public {
if (!roleRegistry.hasRole(AUCTION_ADMIN_ROLE, msg.sender)) revert IncorrectRole();

whitelistEnabled = false;
emit WhitelistDisabled(whitelistEnabled);
}

/// @notice Enables the whitelisting phase of the bidding
/// @dev Only users who are on a whitelist can bid
function enableWhitelist() public {
if (!roleRegistry.hasRole(AUCTION_ADMIN_ROLE, msg.sender)) revert IncorrectRole();

whitelistEnabled = true;
emit WhitelistEnabled(whitelistEnabled);
}

// Pauses the contract
function pauseContract() external {
if (!roleRegistry.hasRole(roleRegistry.PROTOCOL_PAUSER(), msg.sender)) revert IncorrectRole();
Expand Down Expand Up @@ -337,22 +294,21 @@ contract AuctionManager is
stakingManagerContractAddress = _stakingManagerContractAddress;
}

/// @notice Updates the minimum bid price for a non-whitelisted bidder
/// @notice Updates the minimum bid price for bidders
/// @param _newMinBidAmount the new amount to set the minimum bid price as
function setMinBidPrice(uint64 _newMinBidAmount) external {
if (!roleRegistry.hasRole(AUCTION_ADMIN_ROLE, msg.sender)) revert IncorrectRole();

require(_newMinBidAmount < maxBidAmount, "Min bid exceeds max bid");
require(_newMinBidAmount >= whitelistBidAmount, "Min bid less than whitelist bid amount");
require(_newMinBidAmount <= maxBidAmount, "Min bid exceeds max bid");
minBidAmount = _newMinBidAmount;
}

/// @notice Updates the maximum bid price for both whitelisted and non-whitelisted bidders
/// @notice Updates the maximum bid price for bidders
/// @param _newMaxBidAmount the new amount to set the maximum bid price as
function setMaxBidPrice(uint64 _newMaxBidAmount) external {
if (!roleRegistry.hasRole(AUCTION_ADMIN_ROLE, msg.sender)) revert IncorrectRole();

require(_newMaxBidAmount > minBidAmount, "Min bid exceeds max bid");
require(_newMaxBidAmount >= minBidAmount, "Min bid exceeds max bid");
maxBidAmount = _newMaxBidAmount;
}

Expand All @@ -364,15 +320,6 @@ contract AuctionManager is
accumulatedRevenueThreshold = _newThreshold;
}

/// @notice Updates the minimum bid price for a whitelisted address
/// @param _newAmount the new amount to set the minimum bid price as
function updateWhitelistMinBidAmount(
uint128 _newAmount
) external onlyOwner {
require(_newAmount < minBidAmount && _newAmount > 0, "Invalid Amount");
whitelistBidAmount = _newAmount;
}

function updateNodeOperatorManager(address _address) external onlyOwner {
nodeOperatorManager = INodeOperatorManager(
_address
Expand Down
127 changes: 19 additions & 108 deletions test/AuctionManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ contract AuctionManagerTest is TestSetup {
auctionInstance.stakingManagerContractAddress(),
address(stakingManagerInstance)
);
assertEq(auctionInstance.whitelistBidAmount(), 0.001 ether);
assertEq(auctionInstance.minBidAmount(), 0.01 ether);
assertEq(auctionInstance.whitelistBidAmount(), 0.001 ether);
assertEq(auctionInstance.maxBidAmount(), 5 ether);
assertEq(auctionInstance.numberOfActiveBids(), 0);
assertTrue(auctionInstance.whitelistEnabled());
}

function test_ReEnterAuctionManagerFailsIfBidAlreadyActive() public {
Expand All @@ -56,37 +53,6 @@ contract AuctionManagerTest is TestSetup {
auctionInstance.reEnterAuction(bidId1[0]);
}

function test_DisableWhitelist() public {
assertTrue(auctionInstance.whitelistEnabled());

vm.expectRevert(AuctionManager.IncorrectRole.selector);
vm.prank(owner);
auctionInstance.disableWhitelist();

vm.prank(alice);
auctionInstance.disableWhitelist();

assertFalse(auctionInstance.whitelistEnabled());
}

function test_EnableWhitelist() public {
assertTrue(auctionInstance.whitelistEnabled());

vm.prank(alice);
auctionInstance.disableWhitelist();

assertFalse(auctionInstance.whitelistEnabled());

vm.expectRevert(AuctionManager.IncorrectRole.selector);
vm.prank(owner);
auctionInstance.enableWhitelist();

vm.prank(alice);
auctionInstance.enableWhitelist();

assertTrue(auctionInstance.whitelistEnabled());
}

function test_createBidWorks() public {
vm.prank(alice);
nodeOperatorManagerInstance.registerNodeOperator(
Expand All @@ -106,75 +72,61 @@ contract AuctionManagerTest is TestSetup {
5
);

assertFalse(nodeOperatorManagerInstance.isWhitelisted(jess));
assertTrue(nodeOperatorManagerInstance.isWhitelisted(alice));

hoax(alice);
uint256[] memory bid1Id = auctionInstance.createBid{value: 0.001 ether}(
vm.expectRevert("Incorrect bid value");
auctionInstance.createBid{value: 0.001 ether}(
1,
0.001 ether
);

assertEq(auctionInstance.numberOfActiveBids(), 1);
assertEq(auctionInstance.numberOfActiveBids(), 0);

(
startHoax(alice);
uint256[] memory bid1Id = auctionInstance.createBid{value: 0.04 ether}(4, 0.01 ether);

(
uint256 amount,
uint64 ipfsIndex,
address bidderAddress,
bool isActive
) = auctionInstance.bids(bid1Id[0]);

assertEq(amount, 0.001 ether);
assertEq(amount, 0.01 ether);
assertEq(ipfsIndex, 0);
assertEq(bidderAddress, alice);
assertTrue(isActive);

startHoax(alice);
auctionInstance.createBid{value: 0.004 ether}(4, 0.001 ether);

vm.expectRevert("Bid size is too small");
auctionInstance.createBid{value: 0.004 ether}(0, 0.001 ether);
auctionInstance.createBid{value: 0.04 ether}(0, 0.01 ether);
vm.stopPrank();

vm.expectRevert("Insufficient public keys");
startHoax(alice);
auctionInstance.createBid{value: 1 ether}(1, 1 ether);
vm.stopPrank();

assertTrue(auctionInstance.whitelistEnabled());

vm.expectRevert("Only whitelisted addresses");
hoax(jess);
auctionInstance.createBid{value: 0.01 ether}(1, 0.01 ether);
vm.expectRevert("Insufficient public keys");
startHoax(alice);
auctionInstance.createBid{value: 1 ether}(1, 1 ether);
vm.stopPrank();

assertEq(auctionInstance.numberOfActiveBids(), 5);

// Owner disables whitelist
vm.prank(alice);
auctionInstance.disableWhitelist();

// Bob can still bid below min bid amount because he was whitelisted
hoax(bob);
uint256[] memory bobBidIds = auctionInstance.createBid{
value: 0.001 ether
}(1, 0.001 ether);
uint256[] memory bobBidIds = auctionInstance.createBid{value: 0.01 ether}(1, 0.01 ether);

(amount, ipfsIndex, bidderAddress, isActive) = auctionInstance.bids(
bobBidIds[0]
);
assertEq(amount, 0.001 ether);
assertEq(amount, 0.01 ether);
assertEq(ipfsIndex, 0);
assertEq(bidderAddress, bob);
assertTrue(isActive);

assertEq(auctionInstance.numberOfActiveBids(), 6);

// jess cannot bid below the min bid amount because he was not whitelisted
vm.expectRevert("Incorrect bid value");
hoax(jess);
uint256[] memory henryBidIds = auctionInstance.createBid{
value: 0.001 ether
}(1, 0.001 ether);
uint256[] memory henryBidIds = auctionInstance.createBid{value: 0.001 ether}(1, 0.001 ether);

hoax(henry);
henryBidIds = auctionInstance.createBid{value: 0.01 ether}(
Expand All @@ -188,28 +140,6 @@ contract AuctionManagerTest is TestSetup {
assertEq(ipfsIndex, 0);
assertEq(bidderAddress, henry);
assertTrue(isActive);

// Owner enables whitelist
vm.prank(alice);
auctionInstance.enableWhitelist();

vm.expectRevert("Only whitelisted addresses");
hoax(jess);
auctionInstance.createBid{value: 0.01 ether}(1, 0.01 ether);

hoax(bob);
bobBidIds = auctionInstance.createBid{value: 0.001 ether}(
1,
0.001 ether
);

(amount, ipfsIndex, bidderAddress, isActive) = auctionInstance.bids(
bobBidIds[0]
);
assertEq(amount, 0.001 ether);
assertEq(ipfsIndex, 1);
assertEq(bidderAddress, bob);
assertTrue(isActive);
}

function test_CreateBidMinMaxAmounts() public {
Expand All @@ -233,8 +163,8 @@ contract AuctionManagerTest is TestSetup {
hoax(alice);
auctionInstance.createBid{value: 5.1 ether}(1, 5.1 ether);

vm.prank(alice);
auctionInstance.disableWhitelist();
// vm.prank(alice);
// auctionInstance.disableWhitelist();

vm.expectRevert("Incorrect bid value");
hoax(alice);
Expand Down Expand Up @@ -634,7 +564,7 @@ contract AuctionManagerTest is TestSetup {
function test_SetMinBidAmount() public {
vm.prank(alice);
vm.expectRevert("Min bid exceeds max bid");
auctionInstance.setMinBidPrice(5 ether);
auctionInstance.setMinBidPrice(5.001 ether);

vm.prank(owner);
vm.expectRevert(AuctionManager.IncorrectRole.selector);
Expand All @@ -646,25 +576,6 @@ contract AuctionManagerTest is TestSetup {
assertEq(auctionInstance.minBidAmount(), 1 ether);
}

function test_SetWhitelistBidAmount() public {
vm.prank(alice);
vm.expectRevert("Ownable: caller is not the owner");
auctionInstance.updateWhitelistMinBidAmount(0.005 ether);

vm.prank(owner);
vm.expectRevert("Invalid Amount");
auctionInstance.updateWhitelistMinBidAmount(0);

vm.prank(owner);
vm.expectRevert("Invalid Amount");
auctionInstance.updateWhitelistMinBidAmount(0.2 ether);

assertEq(auctionInstance.whitelistBidAmount(), 0.001 ether);
vm.prank(owner);
auctionInstance.updateWhitelistMinBidAmount(0.002 ether);
assertEq(auctionInstance.whitelistBidAmount(), 0.002 ether);
}

function test_EventBidPlaced() public {

vm.prank(alice);
Expand Down
3 changes: 0 additions & 3 deletions test/TestSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1151,9 +1151,6 @@ contract TestSetup is Test {
liquidityPoolInstance.updateBnftMode(_isLpBnftHolder);
vm.stopPrank();

vm.prank(admin);
auctionInstance.disableWhitelist();

vm.startPrank(_nodeOperator);
if (!nodeOperatorManagerInstance.registered(_nodeOperator)) {
nodeOperatorManagerInstance.registerNodeOperator(
Expand Down
Loading