Skip to content

Commit

Permalink
Merge pull request #186 from DMDcoin/dev
Browse files Browse the repository at this point in the history
updated master branch with latest contracts form alpha2 network
  • Loading branch information
SurfingNerd authored Oct 4, 2023
2 parents 17257df + e5adc57 commit 8419e75
Show file tree
Hide file tree
Showing 62 changed files with 7,883 additions and 15,504 deletions.
15 changes: 6 additions & 9 deletions .github/workflows/node.js.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
pull_request:
on: [ push, pull_request ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -26,3 +18,8 @@ jobs:
cache: 'npm'
- run: npm ci
- run: npm test
- run: npm run coverage
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
28 changes: 28 additions & 0 deletions .github/workflows/slither.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Slither Analysis

on:
push:
pull_request:

jobs:
analyze:
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Run Slither
uses: crytic/slither-action@v0.2.0
id: slither
with:
node-version: 16
sarif: results.sarif
fail-on: none

- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: ${{ steps.slither.outputs.sarif }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ src
.pk
.mnemonic*
.env*

.vscode/
2 changes: 1 addition & 1 deletion .solcover.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
norpc: true,
skipFiles: ['interfaces', 'libs'],
skipFiles: ['interfaces', 'libs', 'upgradeability', 'mockContracts'],
configureYulOptimizer: true
}
73 changes: 71 additions & 2 deletions contracts/BlockRewardHbbft.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,74 @@
pragma solidity =0.8.17;

import "./base/BlockRewardHbbftCoins.sol";
import "./base/BlockRewardHbbftBase.sol";
import "./interfaces/IBlockRewardHbbftCoins.sol";

contract BlockRewardHbbft is BlockRewardHbbftCoins {}
contract BlockRewardHbbft is BlockRewardHbbftBase, IBlockRewardHbbftCoins {
// =============================================== Setters ========================================================

/// @dev Called by the `StakingHbbft.claimReward` function to transfer native coins
/// from the balance of the `BlockRewardHbbft` contract to the specified address as a reward.
/// @param _nativeCoins The amount of native coins to transfer as a reward.
/// @param _to The target address to transfer the amounts to.
function transferReward(uint256 _nativeCoins, address payable _to)
external
onlyStakingContract
{
_transferNativeReward(_nativeCoins, _to);
}

// =============================================== Getters ========================================================

/// @dev Returns the reward amount in native coins for
/// some delegator with the specified stake amount placed into the specified
/// pool before the specified staking epoch. Used by the `StakingHbbft.claimReward` function.
/// @param _delegatorStake The stake amount placed by some delegator into the `_poolMiningAddress` pool.
/// @param _stakingEpoch The serial number of staking epoch.
/// @param _poolMiningAddress The pool mining address.
/// @return nativeReward `uint256 nativeReward` - the reward amount in native coins.
function getDelegatorReward(
uint256 _delegatorStake,
uint256 _stakingEpoch,
address _poolMiningAddress
) external view returns (uint256 nativeReward) {
uint256 validatorStake = snapshotPoolValidatorStakeAmount[
_stakingEpoch
][_poolMiningAddress];
uint256 totalStake = snapshotPoolTotalStakeAmount[_stakingEpoch][
_poolMiningAddress
];

nativeReward = delegatorShare(
_stakingEpoch,
_delegatorStake,
validatorStake,
totalStake,
epochPoolNativeReward[_stakingEpoch][_poolMiningAddress]
);
}

/// @dev Returns the reward amount in native coins for
/// the specified validator and for the specified staking epoch.
/// Used by the `StakingHbbft.claimReward` function.
/// @param _stakingEpoch The serial number of staking epoch.
/// @param _poolMiningAddress The pool mining address.
/// @return nativeReward `uint256 nativeReward` - the reward amount in native coins.
function getValidatorReward(
uint256 _stakingEpoch,
address _poolMiningAddress
) external view returns (uint256 nativeReward) {
uint256 validatorStake = snapshotPoolValidatorStakeAmount[
_stakingEpoch
][_poolMiningAddress];
uint256 totalStake = snapshotPoolTotalStakeAmount[_stakingEpoch][
_poolMiningAddress
];

nativeReward = validatorShare(
_stakingEpoch,
validatorStake,
totalStake,
epochPoolNativeReward[_stakingEpoch][_poolMiningAddress]
);
}
}
54 changes: 24 additions & 30 deletions contracts/CertifierHbbft.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
pragma solidity =0.8.17;

import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

import "./interfaces/ICertifier.sol";
import "./interfaces/IStakingHbbft.sol";
import "./interfaces/IValidatorSetHbbft.sol";
import "./upgradeability/UpgradeableOwned.sol";

/// @dev Allows validators to use a zero gas price for their service transactions
/// (see https://wiki.parity.io/Permissioning.html#gas-price for more info).
contract CertifierHbbft is UpgradeableOwned, ICertifier {
contract CertifierHbbft is Initializable, OwnableUpgradeable, ICertifier {
// =============================================== Storage ========================================================

// WARNING: since this contract is upgradeable, do not remove
Expand All @@ -31,50 +33,47 @@ contract CertifierHbbft is UpgradeableOwned, ICertifier {
/// @param who Specified address for which zero gas price transactions are denied.
event Revoked(address indexed who);

// ============================================== Modifiers =======================================================

/// @dev Ensures the `initialize` function was called before.
modifier onlyInitialized() {
require(isInitialized(), "Contract requires to be initialized()");
_;
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
// Prevents initialization of implementation contract
_disableInitializers();
}

// =============================================== Setters ========================================================
// =============================================== Setters =======================================================

/// @dev Initializes the contract at network startup.
/// Can only be called by the constructor of the `InitializerHbbft` contract or owner.
/// @param _certifiedAddresses The addresses for which a zero gas price must be allowed.
/// @param _validatorSet The address of the `ValidatorSetHbbft` contract.
function initialize(
address[] calldata _certifiedAddresses,
address _validatorSet
) external {
require(
msg.sender == _admin() ||
tx.origin == _admin() ||
address(0) == _admin() ||
block.number == 0,
"Sender must be admin"
);
require(!isInitialized(), "Contract is already initialized");
address _validatorSet,
address _owner
) external initializer {
require(_owner != address(0), "Owner address must not be 0");
require(_validatorSet != address(0), "Validatorset must not be 0");

__Ownable_init();
_transferOwnership(_owner);

validatorSetContract = IValidatorSetHbbft(_validatorSet);

for (uint256 i = 0; i < _certifiedAddresses.length; i++) {
_certify(_certifiedAddresses[i]);
}
validatorSetContract = IValidatorSetHbbft(_validatorSet);
}

/// @dev Allows the specified address to use a zero gas price for its transactions.
/// Can only be called by the `owner`.
/// @param _who The address for which zero gas price transactions must be allowed.
function certify(address _who) external onlyOwner onlyInitialized {
function certify(address _who) external onlyOwner {
_certify(_who);
}

/// @dev Denies the specified address usage of a zero gas price for its transactions.
/// Can only be called by the `owner`.
/// @param _who The address for which transactions with a zero gas price must be denied.
function revoke(address _who) external onlyOwner onlyInitialized {
function revoke(address _who) external onlyOwner {
_certified[_who] = false;
emit Revoked(_who);
}
Expand Down Expand Up @@ -103,9 +102,9 @@ contract CertifierHbbft is UpgradeableOwned, ICertifier {
// since the node cache the list of certifiers
// and the permission contracts checks anyway,
// if the specific 0 gas transaction is allowed or not.
IStakingHbbft stakingContract = IStakingHbbft(
validatorSetContract.getStakingContract()
);
// IStakingHbbft stakingContract = IStakingHbbft(
// validatorSetContract.getStakingContract()
// );
return stakingAddress != address(0);
}

Expand All @@ -118,11 +117,6 @@ contract CertifierHbbft is UpgradeableOwned, ICertifier {
return _certified[_who];
}

/// @dev Returns a boolean flag indicating if the `initialize` function has been called.
function isInitialized() public view returns (bool) {
return validatorSetContract != IValidatorSetHbbft(address(0));
}

// ============================================== Internal ========================================================

/// @dev An internal function for the `certify` and `initialize` functions.
Expand Down
96 changes: 0 additions & 96 deletions contracts/InitializerHbbft.sol

This file was deleted.

Loading

0 comments on commit 8419e75

Please sign in to comment.