Contract ownership changes unintentionally in Staking contract

I have the following staking contract, whenever I stake tokens, it changes the owner of the contract, I think I know what causes this, but I don’t know why.

_updateCheckpointValueAtNow() this method is called when staking, and it messes the storage I think, but I don’t know what I am doing wrong here

I would appreciate it if someone can guide me here, thanks!

This is the contract.

This is the function which is wrong

function _updateCheckpointValueAtNow(
    Checkpoint[] storage checkpoints,
    uint _oldValue,
    uint _value
  ) internal {
    require(_value <= uint128(-1));
    require(_oldValue <= uint128(-1));

    if (checkpoints.length == 0) {
      Checkpoint storage genesis;
      genesis.fromBlock = uint128(block.number - 1);
      genesis.value = uint128(_oldValue);
      checkpoints.push(genesis);
    }

    if (checkpoints[checkpoints.length - 1].fromBlock < block.number) {
      Checkpoint storage newCheckPoint;
      newCheckPoint.fromBlock = uint128(block.number);
      newCheckPoint.value = uint128(_value);
      checkpoints.push(newCheckPoint);
    } else {
      Checkpoint storage oldCheckPoint = checkpoints[checkpoints.length - 1];
      oldCheckPoint.value = uint128(_value);
    }
  }
  
}
1 Like

HI @Abdul_Rafay,

Welcome to the community :wave:

I am not familiar with staking or with this code so unfortunately can’t help here.

If you are looking for a developer to help with this, you could post in the forum, stating what you are looking for and what you are offering in exchange (e.g. payment) and the best way to contact you. See the following examples: https://forum.openzeppelin.com/tag/developer-wanted