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

Implement batch deposits #93

Merged
merged 8 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
38 changes: 21 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,24 @@ jobs:
sed -i "s|`pwd`/||g" /tmp/workspace/log/test-results/mocha/test-results.xml
fi

# FIXME: https://github.com/sc-forks/solidity-coverage/issues/574
# coverage:
# executor: default
# steps:
# - checkout
# - attach_workspace:
# at: /tmp/workspace
# - run:
# name: Run coverage tests
# command: yarn coverage
# - run:
# name: Upload coverage
# command: |
# bash <(curl -s https://codecov.io/bash)
coverage:
executor: default
resource_class: large
parallelism: 16
steps:
- checkout
- attach_workspace:
at: /tmp/workspace
- run:
name: Run coverage tests
command: |
circleci tests glob 'test/**/*.test.js' |
circleci tests split |
xargs -I {} yarn coverage --testfiles "{}"
- run:
name: Upload coverage
command: |
bash <(curl -s https://codecov.io/bash)

workflows:
version: 2
Expand All @@ -132,6 +136,6 @@ workflows:
- report-gas:
requires:
- test
# - coverage:
# requires:
# - compile
- coverage:
requires:
- compile
4 changes: 2 additions & 2 deletions .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module.exports = {
silent: true,
providerOptions: {
total_accounts: 5000,
default_balance_ether: 10000000000000, // extra zero just in case (coverage consumes more gas)
default_balance_ether: 1000000000000000000000000, // extra zero just in case (coverage consumes more gas)
gasLimit: 0x1fffffffffffff,
},
mocha: {
timeout: 180000,
timeout: 1000000,
},
skipFiles: [
'mocks',
Expand Down
83 changes: 10 additions & 73 deletions abi/Oracles.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "rewardsNonce",
"type": "uint256"
}
],
"name": "Initialized",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down Expand Up @@ -97,23 +84,11 @@
"name": "sender",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "oracle",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "operator",
"type": "address"
},
{
"indexed": false,
"internalType": "bytes",
"name": "publicKey",
"type": "bytes"
"internalType": "address[]",
"name": "oracles",
"type": "address[]"
},
{
"indexed": false,
Expand All @@ -122,7 +97,7 @@
"type": "uint256"
}
],
"name": "RegisterValidatorVoteSubmitted",
"name": "RegisterValidatorsVoteSubmitted",
"type": "event"
},
{
Expand Down Expand Up @@ -458,44 +433,6 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "admin",
"type": "address"
},
{
"internalType": "address",
"name": "oraclesV1",
"type": "address"
},
{
"internalType": "address",
"name": "_rewardEthToken",
"type": "address"
},
{
"internalType": "address",
"name": "_pool",
"type": "address"
},
{
"internalType": "address",
"name": "_poolValidators",
"type": "address"
},
{
"internalType": "address",
"name": "_merkleDistributor",
"type": "address"
}
],
"name": "initialize",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -616,14 +553,14 @@
"type": "bytes"
}
],
"internalType": "struct IPoolValidators.DepositData",
"internalType": "struct IPoolValidators.DepositData[]",
"name": "depositData",
"type": "tuple"
"type": "tuple[]"
},
{
"internalType": "bytes32[]",
"name": "merkleProof",
"type": "bytes32[]"
"internalType": "bytes32[][]",
"name": "merkleProofs",
"type": "bytes32[][]"
},
{
"internalType": "bytes32",
Expand All @@ -636,7 +573,7 @@
"type": "bytes[]"
}
],
"name": "registerValidator",
"name": "registerValidators",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
Expand Down
Binary file added audits/2022-05-06-Quantstamp.pdf
Binary file not shown.
79 changes: 22 additions & 57 deletions contracts/Oracles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import "./interfaces/IPool.sol";
import "./interfaces/IOracles.sol";
import "./interfaces/IMerkleDistributor.sol";
import "./interfaces/IPoolValidators.sol";
import "./interfaces/IOraclesV1.sol";

/**
* @title Oracles
Expand Down Expand Up @@ -53,43 +52,6 @@ contract Oracles is IOracles, OwnablePausableUpgradeable {
_;
}

/**
* @dev See {IOracles-initialize}.
*/
function initialize(
address admin,
address oraclesV1,
address _rewardEthToken,
address _pool,
address _poolValidators,
address _merkleDistributor
)
external override initializer
{
require(admin != address(0), "Pool: invalid admin address");
require(_rewardEthToken != address(0), "Pool: invalid RewardEthToken address");
require(_pool != address(0), "Pool: invalid Pool address");
require(_poolValidators != address(0), "Pool: invalid PoolValidators address");
require(_merkleDistributor != address(0), "Pool: invalid MerkleDistributor address");

__OwnablePausableUpgradeable_init(admin);

// migrate data from previous Oracles contract
rewardsNonce._value = IOraclesV1(oraclesV1).currentNonce().add(1000);
uint256 oraclesCount = AccessControlUpgradeable(oraclesV1).getRoleMemberCount(ORACLE_ROLE);
for (uint256 i = 0; i < oraclesCount; i++) {
address oracle = AccessControlUpgradeable(oraclesV1).getRoleMember(ORACLE_ROLE, i);
_setupRole(ORACLE_ROLE, oracle);
emit OracleAdded(oracle);
}

rewardEthToken = IRewardEthToken(_rewardEthToken);
pool = IPool(_pool);
poolValidators = IPoolValidators(_poolValidators);
merkleDistributor = IMerkleDistributor(_merkleDistributor);
emit Initialized(rewardsNonce.current());
}

/**
* @dev See {IOracles-currentRewardsNonce}.
*/
Expand All @@ -115,6 +77,7 @@ contract Oracles is IOracles, OwnablePausableUpgradeable {
* @dev See {IOracles-addOracle}.
*/
function addOracle(address account) external override {
require(account != address(0), "Oracles: invalid oracle address");
grantRole(ORACLE_ROLE, account);
emit OracleAdded(account);
}
Expand All @@ -140,7 +103,8 @@ contract Oracles is IOracles, OwnablePausableUpgradeable {
* @param signaturesCount - number of signatures.
*/
function isEnoughSignatures(uint256 signaturesCount) internal view returns (bool) {
return signaturesCount.mul(3) > getRoleMemberCount(ORACLE_ROLE).mul(2);
uint256 totalOracles = getRoleMemberCount(ORACLE_ROLE);
return totalOracles >= signaturesCount && signaturesCount.mul(3) > totalOracles.mul(2);
}

/**
Expand Down Expand Up @@ -228,11 +192,11 @@ contract Oracles is IOracles, OwnablePausableUpgradeable {
}

/**
* @dev See {IOracles-registerValidator}.
*/
function registerValidator(
IPoolValidators.DepositData calldata depositData,
bytes32[] calldata merkleProof,
* @dev See {IOracles-registerValidators}.
*/
function registerValidators(
IPoolValidators.DepositData[] calldata depositData,
bytes32[][] calldata merkleProofs,
bytes32 validatorsDepositRoot,
bytes[] calldata signatures
)
Expand All @@ -247,10 +211,10 @@ contract Oracles is IOracles, OwnablePausableUpgradeable {
// calculate candidate ID hash
uint256 nonce = validatorsNonce.current();
bytes32 candidateId = ECDSAUpgradeable.toEthSignedMessageHash(
keccak256(abi.encode(nonce, depositData.publicKey, depositData.operator, validatorsDepositRoot))
keccak256(abi.encode(nonce, depositData, validatorsDepositRoot))
);

// check signatures and calculate number of submitted oracle votes
// check signatures are correct
address[] memory signedOracles = new address[](signatures.length);
for (uint256 i = 0; i < signatures.length; i++) {
bytes memory signature = signatures[i];
Expand All @@ -261,19 +225,20 @@ contract Oracles is IOracles, OwnablePausableUpgradeable {
require(signedOracles[j] != signer, "Oracles: repeated signature");
}
signedOracles[i] = signer;
emit RegisterValidatorVoteSubmitted(
msg.sender,
signer,
depositData.operator,
depositData.publicKey,
nonce
);
}

// increment nonce for future signatures
validatorsNonce.increment();
uint256 depositDataLength = depositData.length;
require(merkleProofs.length == depositDataLength, "Oracles: invalid merkle proofs length");

// register validator
poolValidators.registerValidator(depositData, merkleProof);
// submit deposit data
for (uint256 i = 0; i < depositDataLength; i++) {
// register validator
poolValidators.registerValidator(depositData[i], merkleProofs[i]);
}

emit RegisterValidatorsVoteSubmitted(msg.sender, signedOracles, nonce);

// increment nonce for future registrations
validatorsNonce.increment();
}
}
Loading