Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Zilliqa/zq2 into dependabot…
Browse files Browse the repository at this point in the history
…/cargo/rusqlite-0.33.0
  • Loading branch information
saeed-zil committed Jan 27, 2025
2 parents eb8a3f9 + afa7e93 commit 3e3179b
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions zilliqa/src/contracts/deposit_v4.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.20;
pragma solidity 0.8.28;

import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {Deque, Withdrawal} from "./utils/deque.sol";
Expand Down Expand Up @@ -84,7 +84,7 @@ contract Deposit is UUPSUpgradeable {
uint256 atFutureBlock
);

uint64 public constant VERSION = 3;
uint64 public constant VERSION = 4;

/// @custom:storage-location erc7201:zilliqa.storage.DepositStorage
struct DepositStorage {
Expand Down Expand Up @@ -192,7 +192,6 @@ contract Deposit is UUPSUpgradeable {
uint256 position = randomness % currentCommittee.totalStake;
uint256 cummulativeStake = 0;

// TODO: Consider binary search for performance. Or consider an alias method for O(1) performance.
for (uint256 i = 0; i < currentCommittee.stakerKeys.length; i++) {
bytes memory stakerKey = currentCommittee.stakerKeys[i];
uint256 stakedBalance = currentCommittee.stakers[stakerKey].balance;
Expand Down Expand Up @@ -243,11 +242,11 @@ contract Deposit is UUPSUpgradeable {
Staker[] memory stakers
)
{
// TODO clean up doule call to _getDepositStorage() here
DepositStorage storage $ = _getDepositStorage();
Committee storage currentCommittee = committee();

stakerKeys = currentCommittee.stakerKeys;
indices = new uint256[](stakerKeys.length);
balances = new uint256[](stakerKeys.length);
stakers = new Staker[](stakerKeys.length);
for (uint256 i = 0; i < stakerKeys.length; i++) {
Expand Down Expand Up @@ -584,12 +583,13 @@ contract Deposit is UUPSUpgradeable {
revert KeyNotStaked();
}

uint256 currentBalance = futureCommittee.stakers[blsPubKey].balance;
require(
futureCommittee.stakers[blsPubKey].balance >= amount,
currentBalance >= amount,
"amount is greater than staked balance"
);

if (futureCommittee.stakers[blsPubKey].balance - amount == 0) {
if (currentBalance - amount == 0) {
require(futureCommittee.stakerKeys.length > 1, "too few stakers");

// Remove the staker from the future committee, because their staked amount has gone to zero.
Expand Down Expand Up @@ -620,8 +620,7 @@ contract Deposit is UUPSUpgradeable {
emit StakerRemoved(blsPubKey, nextUpdate());
} else {
require(
futureCommittee.stakers[blsPubKey].balance - amount >=
$.minimumStake,
currentBalance - amount >= $.minimumStake,
"unstaking this amount would take the validator below the minimum stake"
);

Expand Down

0 comments on commit 3e3179b

Please sign in to comment.