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

263 go over smart contracts functions and review things #77

Merged
Merged
Show file tree
Hide file tree
Changes from 7 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
16 changes: 8 additions & 8 deletions contracts/APRCalculator/IAPRCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface IAPRCalculator is IMacroFactor, IRSIndex, IPrice {
error InvalidRSI();

/**
* @notice sets new base APR
* @notice Sets new base APR
* @dev only owner can call this function
* @param newBase new base APR
*/
Expand All @@ -18,42 +18,42 @@ interface IAPRCalculator is IMacroFactor, IRSIndex, IPrice {
// _______________ Public functions _______________

/**
* @notice returns base APR
* @notice Returns base APR
*/
function getBaseAPR() external view returns (uint256);

/**
* @notice returns the denominator for the APR calculation
* @notice Returns the denominator for the APR calculation
*/
function getDENOMINATOR() external pure returns (uint256);

/**
* @notice applies the base APR for the given amount
* @notice Applies the base APR for the given amount
* @param amount the amount to apply the APR to
*/
function applyBaseAPR(uint256 amount) external view returns (uint256);

/**
* @notice applies macro factor for the given total staked amount
* @notice Applies macro factor for the given total staked amount
* @param totalStaked the total staked amount to apply the macro factor to
*/
function applyMacro(uint256 totalStaked) external view returns (uint256 reward);

/**
* @notice returns the vesting bonus for the given weeks count
* @notice Returns the vesting bonus for the given weeks count
* @param weeksCount the amount of weeks to calculate the bonus for
*/
function getVestingBonus(uint256 weeksCount) external view returns (uint256 nominator);

/**
* @notice returns the max APR for 52 weeks
* @notice Returns the max APR for 52 weeks
* @return nominator the nominator for the max APR
* @return denominator the denominator for the max APR
*/
function getMaxAPR() external view returns (uint256 nominator, uint256 denominator);

/**
* @notice returns the max yearly reward for the given total staked amount
* @notice Returns the max yearly reward for the given total staked amount
* @param totalStaked the total staked amount to apply the max APR params to
*/
function getMaxYearlyReward(uint256 totalStaked) external view returns (uint256 reward);
Expand Down
4 changes: 2 additions & 2 deletions contracts/BLS/BLS.sol
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ contract BLS is IBLS {
}

/**
* @notice returns square root of a uint256 value
* @notice Returns square root of a uint256 value
* @param xx the value to take the square root of
* @return x the uint256 value of the root
* @return hasRoot a bool indicating if there is a square root
Expand All @@ -346,7 +346,7 @@ contract BLS is IBLS {
}

/**
* @notice inverts a uint256 value
* @notice Inverts a uint256 value
* @param a uint256 value to invert
* @return uint256 of the value of the inverse
*/
Expand Down
20 changes: 10 additions & 10 deletions contracts/BLS/IBLS.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.17;

interface IBLS {
/**
* @notice verifies a single signature
* @notice Verifies a single signature
* @param signature 64-byte G1 group element (small sig)
* @param pubkey 128-byte G2 group element (big pubkey)
* @param message message signed to produce signature
Expand All @@ -17,7 +17,7 @@ interface IBLS {
) external view returns (bool, bool);

/**
* @notice verifies multiple non-aggregated signatures where each message is unique
* @notice Verifies multiple non-aggregated signatures where each message is unique
* @param signature 64-byte G1 group element (small sig)
* @param pubkeys array of 128-byte G2 group element (big pubkey)
* @param messages array of messages signed to produce signature
Expand All @@ -31,7 +31,7 @@ interface IBLS {
) external view returns (bool checkResult, bool callSuccess);

/**
* @notice verifies an aggregated signature where the same message is signed
* @notice Verifies an aggregated signature where the same message is signed
* @param signature 64-byte G1 group element (small sig)
* @param pubkeys array of 128-byte G2 group element (big pubkey)
* @param message message signed by all to produce signature
Expand All @@ -45,36 +45,36 @@ interface IBLS {
) external view returns (bool checkResult, bool callSuccess);

/**
* @notice maps a field element to the curve
* @notice Maps a field element to the curve
* @param _x a valid field element
* @return p the point on the curve the point is mapped to
*/
function mapToPoint(uint256 _x) external pure returns (uint256[2] memory p);

/**
* @notice checks if a signature is formatted correctly and valid
* @notice Checks if a signature is formatted correctly and valid
* @dev will revert if improperly formatted, will return false if invalid
* @param signature the BLS signature
* @return bool indicating if the signature is valid or not
*/
function isValidSignature(uint256[2] memory signature) external view returns (bool);

/**
* @notice checks if point in the finite field Fq (x,y) is on the G1 curve
* @notice Checks if point in the finite field Fq (x,y) is on the G1 curve
* @param point array with x and y values of the point
* @return _isOnCurve bool indicating if the point is on the curve or not
*/
function isOnCurveG1(uint256[2] memory point) external pure returns (bool _isOnCurve);

/**
* @notice checks if point in the finite field Fq (x,y) is on the G2 curve
* @notice Checks if point in the finite field Fq (x,y) is on the G2 curve
* @param point array with x and y values of the point
* @return _isOnCurve bool indicating if the point is on the curve or not
*/
function isOnCurveG2(uint256[4] memory point) external pure returns (bool _isOnCurve);

/**
* @notice hashes an arbitrary message to a point on the curve
* @notice Hashes an arbitrary message to a point on the curve
* @dev Fouque-Tibouchi Hash to Curve
* @param domain domain separator for the hash
* @param message the message to map
Expand All @@ -83,15 +83,15 @@ interface IBLS {
function hashToPoint(bytes32 domain, bytes memory message) external view returns (uint256[2] memory);

/**
* @notice hashes an arbitrary message to a field element
* @notice Hashes an arbitrary message to a field element
* @param domain domain separator for the hash
* @param messages the messages to map
* @return uint256[2] (x,y) point of the field element that the message maps to
*/
function hashToField(bytes32 domain, bytes memory messages) external view returns (uint256[2] memory);

/**
* @notice pads messages less than 96 bytes to 96 bytes for hashing
* @notice Pads messages less than 96 bytes to 96 bytes for hashing
* @param domain domain separator for the hash
* @param message the message to pad
* @return bytes the padded message
Expand Down
4 changes: 2 additions & 2 deletions contracts/GenesisProxy/GenesisProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transpa
/**
@title GenesisProxy
@author Polygon Technology
@notice wrapper for OpenZeppelin's Transparent Upgreadable Proxy, intended for use during genesis for genesis contracts
@notice one GenesisProxy should be deployed for each genesis contract
@notice Wrapper for OpenZeppelin's Transparent Upgreadable Proxy, intended for use during genesis for genesis contracts
@notice One GenesisProxy should be deployed for each genesis contract
*/
contract GenesisProxy is TransparentUpgradeableProxy {
// keccak256("GenesisProxy INITIATOR_SLOT")
Expand Down
56 changes: 28 additions & 28 deletions contracts/HydraChain/HydraChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ contract HydraChain is
using ArraysUpgradeable for uint256[];

uint256 public currentEpochId;
/// @notice Epoch data linked with the epoch id
mapping(uint256 => Epoch) public epochs;
/// @notice Array with epoch ending blocks
uint256[] public epochEndBlocks;
/// @notice Epoch data linked with the epoch id
mapping(uint256 => Epoch) public epochs;

mapping(uint256 => uint256) internal _commitBlockNumbers;

Expand Down Expand Up @@ -65,29 +65,6 @@ contract HydraChain is

// _______________ External functions _______________

/**
* @inheritdoc IHydraChain
*/
function getCurrentEpochId() external view returns (uint256) {
return currentEpochId;
}

/**
* @inheritdoc IHydraChain
*/
function totalBlocks(uint256 epochId) external view returns (uint256 length) {
uint256 endBlock = epochs[epochId].endBlock;
length = endBlock == 0 ? 0 : endBlock - epochs[epochId].startBlock + 1;
}

/**
* @inheritdoc IHydraChain
*/
function getEpochByBlock(uint256 blockNumber) external view returns (Epoch memory) {
uint256 epochIndex = epochEndBlocks.findUpperBound(blockNumber);
return epochs[epochIndex];
}

/**
* @inheritdoc IHydraChain
*/
Expand All @@ -112,8 +89,8 @@ contract HydraChain is
}

epochs[newEpochId] = epoch;
_commitBlockNumbers[newEpochId] = block.number;
epochEndBlocks.push(epoch.endBlock);
_commitBlockNumbers[newEpochId] = block.number;

// Update participations
uint256 uptimesCount = uptime.length;
Expand All @@ -140,12 +117,35 @@ contract HydraChain is
uint256 withdrawableRewards,
uint256 votingPower,
ValidatorStatus status,
bool isbanInitiated
bool isBanInitiated
)
{
(blsKey, stake, totalStake, commission, withdrawableRewards, status) = _getValidator(validatorAddress);
votingPower = validatorPower[validatorAddress];
isbanInitiated = bansInitiated[validatorAddress] != 0;
isBanInitiated = bansInitiated[validatorAddress] != 0;
}

/**
* @inheritdoc IHydraChain
*/
function getCurrentEpochId() external view returns (uint256) {
return currentEpochId;
}

/**
* @inheritdoc IHydraChain
*/
function totalBlocks(uint256 epochId) external view returns (uint256 length) {
uint256 endBlock = epochs[epochId].endBlock;
length = endBlock == 0 ? 0 : endBlock - epochs[epochId].startBlock + 1;
}

/**
* @inheritdoc IHydraChain
*/
function getEpochByBlock(uint256 blockNumber) external view returns (Epoch memory) {
uint256 epochIndex = epochEndBlocks.findUpperBound(blockNumber);
return epochs[epochIndex];
}

// _______________ Public functions _______________
Expand Down
41 changes: 21 additions & 20 deletions contracts/HydraChain/IHydraChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,6 @@ interface IHydraChain is IInspector, IValidatorManager, IDaoIncentive, IValidato

error CommitEpochFailed(string reason);

/**
* @notice Get current epoch ID
*/
function getCurrentEpochId() external view returns (uint256);

/**
* @notice Total amount of blocks in a given epoch
* @param epochId The number of the epoch
* @return length Total blocks for an epoch
*/
function totalBlocks(uint256 epochId) external view returns (uint256 length);

/**
* @notice Look up an epoch by block number. Searches in O(log n) time.
* @param blockNumber ID of epoch to be committed
* @return Epoch Returns epoch if found, or else, the last epoch
*/
function getEpochByBlock(uint256 blockNumber) external view returns (Epoch memory);

/**
* @notice Commits an epoch
* @dev Only callable by the system
Expand All @@ -57,6 +38,7 @@ interface IHydraChain is IInspector, IValidatorManager, IDaoIncentive, IValidato
* @return withdrawableRewards withdrawable rewards
* @return votingPower voting power of the validator
* @return status status of the validator
* @return isBanInitiated is ban initiated for validator
*/
function getValidator(
address validator
Expand All @@ -71,6 +53,25 @@ interface IHydraChain is IInspector, IValidatorManager, IDaoIncentive, IValidato
uint256 withdrawableRewards,
uint256 votingPower,
ValidatorStatus status,
bool isbanInitiated
bool isBanInitiated
);

/**
* @notice Get current epoch ID
*/
function getCurrentEpochId() external view returns (uint256);

/**
* @notice Total amount of blocks in a given epoch
* @param epochId The number of the epoch
* @return length Total blocks for an epoch
*/
function totalBlocks(uint256 epochId) external view returns (uint256 length);

/**
* @notice Look up an epoch by block number. Searches in O(log n) time.
* @param blockNumber ID of epoch to be committed
* @return Epoch Returns epoch if found, or else, the last epoch
*/
function getEpochByBlock(uint256 blockNumber) external view returns (Epoch memory);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ abstract contract AccessControl is IAccessControl, Ownable2StepUpgradeable {

// _______________ Initializer _______________

// TODO: We must be able to enable/disable this feature
// solhint-disable-next-line func-name-mixedcase
function __AccessControl_init(address _governance) internal onlyInitializing {
__AccessControl_init_unchained(_governance);
Expand Down
5 changes: 3 additions & 2 deletions contracts/HydraChain/modules/DaoIncentive/DaoIncentive.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ abstract contract DaoIncentive is
RewardWalletConnector,
HydraStakingConnector
{
address public daoIncentiveVaultAddr;
/// @notice last rewards distribution timestamp
uint256 public lastDistribution;
Vitomir2 marked this conversation as resolved.
Show resolved Hide resolved
SamBorisov marked this conversation as resolved.
Show resolved Hide resolved
uint256 public vaultDistribution;
uint256 public lastDistribution; // timestamp of the last distribution
address public daoIncentiveVaultAddr;

// _______________ Initializer _______________

Expand Down
4 changes: 2 additions & 2 deletions contracts/HydraChain/modules/Inspector/Inspector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ abstract contract Inspector is IInspector, ValidatorManager {

// solhint-disable-next-line func-name-mixedcase
function __Inspector_init_unchained() internal onlyInitializing {
initiateBanThreshold = 18000; // in blocks => 1 hour minimum
validatorPenalty = 700 ether;
reporterReward = 300 ether;
banThreshold = 24 hours;
initiateBanThreshold = 18000; // in blocks => 1 hour minimum
}

// _______________ Modifiers _______________
Expand Down Expand Up @@ -68,8 +68,8 @@ abstract contract Inspector is IInspector, ValidatorManager {
}

bansInitiated[msg.sender] = 0;
hydraStakingContract.recoverEjectedValidator(msg.sender);
_updateParticipation(msg.sender);
hydraStakingContract.recoverEjectedValidator(msg.sender);
}

/**
Expand Down
Loading
Loading