Skip to content

Commit

Permalink
change owner to sender, add crucial revert for hopping not to be hack…
Browse files Browse the repository at this point in the history
…able when frozen
  • Loading branch information
0xCardinalError committed May 17, 2024
1 parent 6c707f2 commit 25e7b18
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,25 @@ contract StakeRegistry is AccessControl, Pausable {
/**
* @notice Create a new stake or update an existing one.
* @dev At least `_initialBalancePerChunk*2^depth` number of tokens need to be preapproved for this contract.
* @param _owner Eth address used for overlay calculation.
* @param _nonce Nonce that was used for overlay calculation.
* @param _amount Deposited amount of ERC20 tokens.
*/
function depositStake(address _owner, bytes32 _nonce, uint256 _amount) external whenNotPaused {
if (_owner != msg.sender) revert Unauthorized();
function depositStake(bytes32 _nonce, uint256 _amount) external whenNotPaused {
bytes32 overlay = keccak256(abi.encodePacked(msg.sender, reverse(NetworkId), _nonce));

bytes32 overlay = keccak256(abi.encodePacked(_owner, reverse(NetworkId), _nonce));

if (stakes[_owner].isValue && !addressNotFrozen(_owner)) revert Frozen();
uint256 updatedAmount = stakes[_owner].isValue ? _amount + stakes[_owner].stakeAmount : _amount;
if (stakes[msg.sender].isValue && !addressNotFrozen(msg.sender)) revert Frozen();
uint256 updatedAmount = stakes[msg.sender].isValue ? _amount + stakes[msg.sender].stakeAmount : _amount;

if (!ERC20(bzzToken).transferFrom(msg.sender, address(this), _amount)) revert TransferFailed();

stakes[_owner] = Stake({
stakes[msg.sender] = Stake({
overlay: overlay,
stakeAmount: updatedAmount,
lastUpdatedBlockNumber: block.number,
isValue: true
});

emit StakeUpdated(_owner, updatedAmount, overlay, block.number);
emit StakeUpdated(msg.sender, updatedAmount, overlay, block.number);
}

/**
Expand Down Expand Up @@ -169,18 +166,16 @@ contract StakeRegistry is AccessControl, Pausable {

/**
* @dev Change overlay of address to new one for neighbourhood hopping
* @param _owner the _owner adress selected
* disable hopping if frozen, as it would reset frozen value of lastUpdatedBlockNumber that is future
* @param _nonce the new nonce that will produce overlay
*/
function changeOverlay(address _owner, bytes32 _nonce) external {
if (_owner != msg.sender) revert Unauthorized();
bytes32 overlay = keccak256(abi.encodePacked(_owner, reverse(NetworkId), _nonce));
function changeOverlay(bytes32 _nonce) external whenNotPaused {
if (stakes[msg.sender].isValue && !addressNotFrozen(msg.sender)) revert Frozen();
bytes32 overlay = keccak256(abi.encodePacked(msg.sender, reverse(NetworkId), _nonce));

if (stakes[_owner].isValue) {
stakes[_owner].overlay = overlay;
stakes[_owner].lastUpdatedBlockNumber = block.number;
emit OverlayChanged(_owner, overlay);
}
stakes[msg.sender].overlay = overlay;
stakes[msg.sender].lastUpdatedBlockNumber = block.number;
emit OverlayChanged(msg.sender, overlay);
}

function changeNetworkId(uint64 _NetworkId) external {
Expand Down

0 comments on commit 25e7b18

Please sign in to comment.