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);
}
}
}