Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dapp-development
Browse files Browse the repository at this point in the history
  • Loading branch information
michalinacienciala committed Nov 7, 2023
2 parents eea1ea8 + 38debeb commit 65f6431
Show file tree
Hide file tree
Showing 25 changed files with 69,348 additions and 302 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/contracts-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Solidity docs

on:
pull_request:
push:
branches:
- releases/mainnet/v**
release:
types:
- "published"
workflow_dispatch:

jobs:
docs-detect-changes:
runs-on: ubuntu-latest
outputs:
path-filter: ${{ steps.filter.outputs.path-filter }}
steps:
- uses: actions/checkout@v3
if: github.event_name == 'pull_request'
- uses: dorny/paths-filter@v2
if: github.event_name == 'pull_request'
id: filter
with:
filters: |
path-filter:
- './contracts/**'
- './.github/workflows/contracts-docs.yml'
# This job will be triggered for PRs which modify contracts. It will generate
# the archive with contracts documentation in Markdown and attatch it to the
# workflow run results. Link to the archive will be posted in a PR comment.
# The job will also be run after manual triggering and after pushes to the
# `releases/mainnet/**` branches.
contracts-docs-publish-preview:
name: Publish preview of contracts documentation
needs: docs-detect-changes
if: |
needs.docs-detect-changes.outputs.path-filter == 'true'
|| github.event_name == 'push'
|| github.event_name == 'workflow_dispatch'
uses: keep-network/ci/.github/workflows/reusable-solidity-docs.yml@main
with:
publish: false
addTOC: false
commentPR: true
exportAsGHArtifacts: true

# This job will be triggered for releases which name starts with
# `refs/tags/v`. It will generate contracts documentation in
# Markdown and sync it with a specific path of
# `threshold-network/threshold` repository. If changes will be detected,
# a PR updating the docs will be created in the destination repository. The
# commit pushing the changes will be verified using GPG key.
contracts-docs-publish:
name: Publish contracts documentation
needs: docs-detect-changes
if: github.event_name == 'release' && startsWith(github.ref, 'refs/tags/v')
uses: keep-network/ci/.github/workflows/reusable-solidity-docs.yml@main
with:
publish: true
addTOC: false
verifyCommits: true
destinationRepo: threshold-network/threshold
destinationFolder: ./docs/app-development/staking-contract-and-dao/staking-contract-and-dao-api
destinationBaseBranch: main
userEmail: [email protected]
userName: Valkyrie
rsyncDelete: true
secrets:
githubToken: ${{ secrets.THRESHOLD_DOCS_GITHUB_TOKEN }}
gpgPrivateKey: ${{ secrets.THRESHOLD_DOCS_GPG_PRIVATE_KEY_BASE64 }}
gpgPassphrase: ${{ secrets.THRESHOLD_DOCS_GPG_PASSPHRASE }}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ on:
workflow_dispatch:
inputs:
environment:
description: "Environment (network) for workflow execution, e.g. `goerli`"
required: false
description: "Environment (network) for workflow execution, e.g. `sepolia`"
required: true
upstream_builds:
description: "Upstream builds"
required: false
Expand Down Expand Up @@ -59,7 +59,10 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: "18.x"
# Using fixed version, because 18.16 was sometimes causing issues with
# artifacts generation during `hardhat compile` - see
# https://github.com/NomicFoundation/hardhat/issues/3877
node-version: "18.15.0"
cache: "yarn"

- name: Install dependencies
Expand All @@ -83,7 +86,10 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: "18.x"
# Using fixed version, because 18.16 was sometimes causing issues with
# artifacts generation during `hardhat compile` - see
# https://github.com/NomicFoundation/hardhat/issues/3877
node-version: "18.15.0"
cache: "yarn"

- name: Install dependencies
Expand All @@ -104,7 +110,10 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: "18.x"
# Using fixed version, because 18.16 was sometimes causing issues with
# artifacts generation during `hardhat compile` - see
# https://github.com/NomicFoundation/hardhat/issues/3877
node-version: "18.15.0"
cache: "yarn"

- name: Install dependencies
Expand All @@ -124,7 +133,10 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: "18.x"
# Using fixed version, because 18.16 was sometimes causing issues with
# artifacts generation during `hardhat compile` - see
# https://github.com/NomicFoundation/hardhat/issues/3877
node-version: "18.15.0"
cache: "yarn"
registry-url: "https://registry.npmjs.org"

Expand All @@ -141,9 +153,16 @@ jobs:

- name: Deploy contracts
env:
CHAIN_API_URL: ${{ secrets.GOERLI_ETH_HOSTNAME_HTTP }}
CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY: ${{ secrets.GOERLI_ETH_CONTRACT_OWNER_PRIVATE_KEY }}
KEEP_CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY: ${{ secrets.GOERLI_KEEP_ETH_CONTRACT_OWNER_PRIVATE_KEY }}
# Using fake ternary expressions to decide which credentials to use,
# depending on chosen environment. Note: if `GOERLI_ETH_HOSTNAME_HTTP`
# is empty, the expression will be evaluated to
# `SEPOLIA_ETH_HOSTNAME_HTTP`'s value.
CHAIN_API_URL: |
${{ inputs.github.event.inputs.environment == 'goerli'
&& secrets.GOERLI_ETH_HOSTNAME_HTTP
|| secrets.SEPOLIA_ETH_HOSTNAME_HTTP }}
CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ETH_CONTRACT_OWNER_PRIVATE_KEY }}
KEEP_CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ETH_CONTRACT_OWNER_PRIVATE_KEY }}
run: yarn deploy --network ${{ github.event.inputs.environment }}

- name: Bump up package version
Expand Down Expand Up @@ -193,7 +212,10 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: "18.x"
# Using fixed version, because 18.16 was sometimes causing issues with
# artifacts generation during `hardhat compile` - see
# https://github.com/NomicFoundation/hardhat/issues/3877
node-version: "18.15.0"
cache: "yarn"

- name: Install needed dependencies
Expand All @@ -209,7 +231,14 @@ jobs:
- name: Verify contracts on Etherscan
env:
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}
CHAIN_API_URL: ${{ secrets.GOERLI_ETH_HOSTNAME_HTTP }}
# Using fake ternary expressions to decide which credentials to use,
# depending on chosen environment. Note: if `GOERLI_ETH_HOSTNAME_HTTP`
# is empty, the expression will be evaluated to
# `SEPOLIA_ETH_HOSTNAME_HTTP`'s value.
CHAIN_API_URL: |
${{ inputs.github.event.inputs.environment == 'goerli'
&& secrets.GOERLI_ETH_HOSTNAME_HTTP
|| secrets.SEPOLIA_ETH_HOSTNAME_HTTP }}
run: |
yarn run hardhat --network ${{ github.event.inputs.environment }} \
etherscan-verify --license GPL-3.0 --force-license
Expand All @@ -229,7 +258,10 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: "18.x"
# Using fixed version, because 18.16 was sometimes causing issues with
# artifacts generation during `hardhat compile` - see
# https://github.com/NomicFoundation/hardhat/issues/3877
node-version: "18.15.0"
cache: "yarn"
registry-url: "https://registry.npmjs.org"

Expand All @@ -241,9 +273,16 @@ jobs:

- name: Deploy contracts
env:
CHAIN_API_URL: ${{ secrets.GOERLI_ETH_HOSTNAME_HTTP }}
CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY: ${{ secrets.DAPP_DEV_GOERLI_ETH_CONTRACT_OWNER_PRIVATE_KEY }}
KEEP_CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY: ${{ secrets.GOERLI_KEEP_ETH_CONTRACT_OWNER_PRIVATE_KEY }}
# Using fake ternary expressions to decide which credentials to use,
# depending on chosen environment. Note: if `GOERLI_ETH_HOSTNAME_HTTP`
# is empty, the expression will be evaluated to
# `SEPOLIA_ETH_HOSTNAME_HTTP`'s value.
CHAIN_API_URL: |
${{ inputs.github.event.inputs.environment == 'goerli'
&& secrets.GOERLI_ETH_HOSTNAME_HTTP
|| secrets.SEPOLIA_ETH_HOSTNAME_HTTP }}
CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY: ${{ secrets.DAPP_DEV_TESTNET_ETH_CONTRACT_OWNER_PRIVATE_KEY }}
KEEP_CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ETH_CONTRACT_OWNER_PRIVATE_KEY }}
run: yarn deploy --network ${{ github.event.inputs.environment }}

- name: Bump up package version
Expand Down Expand Up @@ -284,7 +323,10 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: "18"
# Using fixed version, because 18.16 was sometimes causing issues with
# artifacts generation during `hardhat compile` - see
# https://github.com/NomicFoundation/hardhat/issues/3877
node-version: "18.15.0"
cache: "yarn"

- uses: actions/setup-python@v4
Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: "18.x"
# Using fixed version, because 18.16 may cause issues with the
# artifacts generation during `hardhat compile` - see
# https://github.com/NomicFoundation/hardhat/issues/3877.
node-version: "18.15.0"
registry-url: "https://registry.npmjs.org"
cache: "yarn"

Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ artifacts/
build/
cache/
deployments/
docgen-templates/
export/
31 changes: 26 additions & 5 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
# Security Policy

## Reporting a Vulnerability
## Bug Bounty Program

If you identify vulnerabilities with any Threshold Network code, please email `[email protected]` with relevant information to your findings. We will work with researchers to coordinate vulnerability disclosure between our stakers, partners, and users to ensure the successful mitigation of vulnerabilities.
Threshold Network has a [Bug Bounty program with Immunefi](https://immunefi.com/bounty/thresholdnetwork/).

Throughout the reporting process, we expect researchers to honor an embargo period that may vary depending on the severity of the disclosure. This ensures that we have the opportunity to fix any issues, identify further issues (if any), and inform our users.
The details for the Bug Bounty are maintained and updated at the [Immunefi Threshold page](https://immunefi.com/bounty/thresholdnetwork/). There you can explore the assets in scope for the bounty and the different rewards by threat level. As a guide, the initial bounty program launched with the following rewards according to the severity of the threats found:

Sometimes vulnerabilities are more sensitive in nature and require extra precautions. We are happy to work together to use a more secure medium, such as Signal. Email [email protected] and we will coordinate a communication channel that we're both comfortable with.
Smart Contracts

A great place to begin your research is by working on our testnet. Please see our [documentation](https://docs.threshold.network) to get started. We ask that you please respect network machines and their owners. If you find a vulnerability that you suspect has given you access to a machine against the owner's permission, stop what you're doing and immediately email `[email protected]`.
- Critical Level: USD $100,000 to USD $500,000
- High Level: USD $10,000 to USD $50,000
- Medium Level: USD $1,000 to USD $5,000
- Low Level: USD $1,000

Websites and Applications

- Critical Level: USD $10,000 to USD $25,000
- High Level: USD $1,000 to USD $10,000
- Medium Level: USD $1,000

A great place to begin your research is by working on our testnet. Please see our [documentation](https://docs.threshold.network) to get started. We ask that you please respect network machines and their owners. If you find a vulnerability that you suspect has given you access to a machine against the owner's permission, stop what you're doing and create a report using the Immunefi dashboard for researchers.

Rewards are distributed according to the impact of the vulnerability based on the [Immunefi Vulnerability Severity Classification System V2.3](https://immunefi.com/immunefi-vulnerability-severity-classification-system-v2-3/). This is a simplified 4-level scale, with separate scales for websites/apps, smart contracts, and blockchains/DLTs, focusing on the impact of the vulnerability reported.

## Reporting a Vulnerability Not Covered by the Bug Bounty Program

Please verify the list of assets in-scope and out-of-scope available as part of the [Threshold Bug Bounty details](https://immunefi.com/bounty/thresholdnetwork/). Additionally, security researchers are encouraged to submit issues outside of the outlined "Impacts" and "Assets in Scope". If you can demonstrate a critical impact on code in production for an asset not in scope, Threshold DAO encourages you to submit your bug report using the “primacy of impact exception” asset in Immunefi.

Threshold DAO will try to make an initial assessment of a bug's relevance, severity, and exploitability, and communicate this back to the reporter. The Threshold DAO will compensate important findings on a case-by-case basis. We value security researchers and we encourage you to contact us to discuss your findings.

We also ask all researchers to please submit their reports in English.
6 changes: 0 additions & 6 deletions contracts/staking/IStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ interface IStaking {
address authorizer
) external;

/// @notice Refresh Keep stake owner. Can be called only by the old owner
/// or their staking provider.
/// @dev The staking provider in T staking contract is the legacy KEEP
/// staking contract operator.
function refreshKeepStakeOwner(address stakingProvider) external;

/// @notice Allows the Governance to set the minimum required stake amount.
/// This amount is required to protect against griefing the staking
/// contract and individual applications are allowed to require
Expand Down
39 changes: 12 additions & 27 deletions contracts/staking/TokenStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
_;
}

modifier onlyOwnerOf(address stakingProvider) {
// slither-disable-next-line incorrect-equality
require(
stakingProviders[stakingProvider].owner == msg.sender,
"Caller is not owner"
);
_;
}

/// @param _token Address of T token contract
/// @param _keepStakingContract Address of Keep staking contract
/// @param _nucypherStakingContract Address of NuCypher staking contract
Expand Down Expand Up @@ -400,28 +409,6 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
);
}

/// @notice Refresh Keep stake owner. Can be called only by the old owner
/// or their staking provider.
/// @dev The staking provider in T staking contract is the legacy KEEP
/// staking contract operator.
function refreshKeepStakeOwner(address stakingProvider)
external
override
onlyOwnerOrStakingProvider(stakingProvider)
{
StakingProviderInfo storage stakingProviderStruct = stakingProviders[
stakingProvider
];
address newOwner = keepStake.resolveOwner(stakingProvider);

emit OwnerRefreshed(
stakingProvider,
stakingProviderStruct.owner,
newOwner
);
stakingProviderStruct.owner = newOwner;
}

/// @notice Allows the Governance to set the minimum required stake amount.
/// This amount is required to protect against griefing the staking
/// contract and individual applications are allowed to require
Expand Down Expand Up @@ -480,6 +467,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
address application,
uint96 amount
) external override onlyAuthorizerOf(stakingProvider) {
require(amount > 0, "Parameters must be specified");
ApplicationInfo storage applicationStruct = applicationInfo[
application
];
Expand Down Expand Up @@ -763,7 +751,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
function topUpNu(address stakingProvider)
external
override
onlyOwnerOrStakingProvider(stakingProvider)
onlyOwnerOf(stakingProvider)
{
StakingProviderInfo storage stakingProviderStruct = stakingProviders[
stakingProvider
Expand Down Expand Up @@ -1420,14 +1408,11 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
internal
virtual
override
onlyOwnerOf(stakingProvider)
{
StakingProviderInfo storage stakingProviderStruct = stakingProviders[
stakingProvider
];
require(
stakingProviderStruct.owner == msg.sender,
"Caller is not owner"
);
uint96 stakingProviderBalance = stakingProviderStruct.tStake +
stakingProviderStruct.keepInTStake +
stakingProviderStruct.nuInTStake;
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/KeepRegistryStub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract KeepRegistryStub is IKeepRegistry {

event OperatorContractApproved(address operatorContract);

constructor() public {
constructor() {
registryKeeper = msg.sender;
}

Expand Down
2 changes: 1 addition & 1 deletion deploy/00_resolve_nucypher_staking_escrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
} else if (
// TODO: For testnets currently we deploy a stub contract. We should consider
// switching to an actual contract.
hre.network.name !== "ropsten" &&
hre.network.name !== "sepolia" &&
hre.network.name !== "goerli" &&
(!hre.network.tags.allowStubs ||
(hre.network.config as HardhatNetworkConfig)?.forking?.enabled)
Expand Down
2 changes: 1 addition & 1 deletion deploy/00_resolve_nucypher_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
} else if (
// TODO: For testnets currently we deploy a stub contract. We should consider
// switching to an actual contract.
hre.network.name !== "ropsten" &&
hre.network.name !== "sepolia" &&
hre.network.name !== "goerli" &&
(!hre.network.tags.allowStubs ||
(hre.network.config as HardhatNetworkConfig)?.forking?.enabled)
Expand Down
Loading

0 comments on commit 65f6431

Please sign in to comment.