Skip to content

Commit

Permalink
Audited eth-contracts (#564)
Browse files Browse the repository at this point in the history
* [Eth-Contracts] Multiple endpoint support (#273)

* First pass of multiple endpoints in SP contracts
* Includes unit test validation

* [eth-contracts] - Dynamic Staking Bounds + SP Type Whitelist (#287)

* Hardcoded list of SP types and associated min/max bounds
* Unit tests to confirm min/max threshold behavior
* Unit test for multiple endpoints / account / type

* Minor fix

* [eth-contracts] Update Service Provider endpoint in staking contracts (#311)

* [eth-contracts] - Automated claim fund + minted tokens (#300)

* [eth-contracts] Stake multiplier model (#330)

* Prerequisite for continued delegation work
* Switch stake tracking model to use a global multiplier that is incremented as funds are added
* All existing tests passing with new code

* Merged master

* [eth-contracts] Delegation v0 + Governance v1 (#340)

* Delegation with rewards split functionality
* Stake for SP direct tracked in ServiceProviderFactory, delegate stakes now tracked in DelegateManager
* Claims forwarded through DelegateManager, slash handled by delegateManager as well
* Revamped reward functionality, with proportional on-demant mint of tokens when claim issued
* Undelegate request and lockup added
* Governance with vote functionality now working, validated with slash

* Convert Staking.sol to new AdminUpgradeabilityProxy + Update all other contracts + migrations + tests (#382)

* [eth-contracts] Permission ClaimFactory / DelegateManager / Staking / ServiceProviderFactory (#376)

* Enforce callers through registry for all staking functions

* Make Governance a RegistryContract (#386)

* Replace vendored @openzepplin/upgrades code with package consumption (#388)

* [eth-contracts] ServiceProviderFactory ServiceType Operations (#389)

* Expose CRUD for known service types to governance or deployer

* Convert VersioningFactory to OZ Proxy pattern + rename to VersionTypeManager, Clean up Initializable pattern (#393)

* [eth-contracts] Undelegate lockup duration CRUD (#392)

* Undelegate lockup duration modification allowed

* ClaimFactory to ClaimsManager proxy (#395)

* Update claimsManager pattern in governance test (#397)

* [eth-contracts] DelegateManager Proxy (#398)

* All tests passing, adding isInitialized next

* Migration passing again

* Test cleanup

* [eth-contracts] Extend ServiceType Manager (#401)

* Move service type information to ServiceTypeManager
* Versioner address renamed to controllerAddress

* [eth-contracts] ServiceProviderFactory -> Proxy (#403)

* pass 1 of moving stuff out

* Tests passing after stg removed everywhere

* Move endpoint to own point

* SP factory to proxy

* Further refactors

* Test fix

* [eth-contracts] Solidity coverage (#406)

* Enable solidity code coverage

* [eth-contracts] ServiceProviderFactory Cleanup (#405)

* Eliminate duplicate functions, serve details as a single tuple
* Update test references

* [eth-contracts] Optimizer, dependency updates, upgradeability updates, refactors (#407)

* [eth-contracts] Increase test coverage (#412)

* Increasing coverage

* [eth-contracts] Vendored contract removal + StakingInterface consumption (#414)

* Removing TimeHelpers
* Removing unnecesary contracts
* Use ERCStakingInterface everywhere
* Remove import
* Adding solcover.js
* interface rename, gitignore, governance interface consumption

* [eth-contracts] DelegateManager added functionality (#413)

* Governance improvements, solc / evmVersion bump, vendored contract removal (#422)

* [eth-contracts] ClaimFactory fundingAmount modifier (#420)

Expose controllerAddress ability to update fundingAmount
Remove references to treasuryAddress where invalid

* [eth-contracts] Mainnet update from master (#423)

* Pull in missing commits from master

* [eth-contracts] Consume Aragon checkpointing  (#424)

* Use updated Checkpointing from https://www.npmjs.com/package/@aragon/court, code has been audited already

* New AudiusAdminUpgradeabilityProxy wrapper + contract upgrade via governance (#425)

* [eth-contracts] Finalize move to AudiusAdminUpgradeabilityProxy (#426)

* [eth-contracts] AudiusAdminUpgradeabilityProxy in Tests (#427)

* Migrations to proxy, Governance guardian veto proposal + execute transaction + test cleanup (#434)

* [eth-contracts] Staking - remove unused bytes field, consume openzeppelin test helpers (#428)

* [eth-contracts] Update with master (#438)

* env var to optionally turn optimizer off (#440)

* The 'cse' flag in the optimizer causes code coverage to break. So added an env var which optionally disables the compiler during coverage tests. Interestingly the README for the code coverage says it doesn't use the optimized builds(https://github.com/sc-forks/solidity-coverage/blob/master/README.md#usage-notes), but for some reason it's still fails when we have our optimizer enabled.

* [eth-contracts] Update heap size for coverage (#445)

* 100% coverage for Registry, RegistryContract, Governance, Initializable, AudiusAdminUpgradeabilityProxy (#451)

* 100% coverage for Registry, RegistryContract, Governance, Initializable, AudiusAdminUpgradeabilityProxy

* [eth-contracts] Staking, Service Coverage + Minor Contract Changes (#453)

* [eth-contracts] Update working branch with master (#460)

* Enforce non-empty signature + test cleanup + require statement format (#457)

* [eth-contracts] Decrease stake request time delay (#463)

* Enforce time difference for decrease stake requests
* CRUD for lockup duration
* SafeMath for ServiceProviderFactory

* [eth-contracts] Remove StakingInterface + Flatten  (#467)

* [eth-contracts] versionIsValid & updateFundingRoundBlockDiff (#442)

* Test validation

* Function re-ordering + re-naming + versionIsValid + updateFundingRoundBlockDiff

Co-authored-by: Sid Sethi <sidsethi93@gmail.com>

* [eth-contracts] Current round logic (#477)

* Separate 'current round' state from configuration variables, enabling fundingAmount modification during ongoing round

* Enable crytic (Slither only) (#480)

* Add safemath everywhere (#473)

* Add SafeMath everywhere we use uints

* run coverage in circleci

* last one didnt work. run coverage in circleci

* try again for run coverage in circleci

* break lint into a top level task in circle

* forgot these files

* lint

* ClaimsManager.sol using SafeMath

* re-enable tests + lint

* Governance.sol

* Few more contracts

* This is causing some problems

* this makes the stack too deep error go away

* Lets see if coveralls works

* comment

* wrong place

* continue on

* specify coverage path

* maybe it's the initial period

* string?

* Stupid period

* Add coverage badge to README

* Remove this before I forget

* This is an actual bug

* BIG bug fix

* Final conversion for DelegateManager

* Remove return declaration

* Remove unused Safemath

* Round 1 of fixes from Crytic (#481)

* Remove shadowed vars

* Acknowledge possible re-entrancy bug

* Fix re-entrancy possibility here

* Move the comment

* [WIP] Crytic - round 2 fixes (#482)

* Remove explicit false check

* Re-entrancy (non-token transfer) in Registry

* Cleanup

* Limit voting to only Yes/No votes

* Stupid

* Remove controllerAddress + remove mockGovernance + update all tests to use new governance override pattern" (#485)

* [eth-contracts] ServiceProviderFactory ClaimPending Restrictions (#484)

* Enforce stake restrictions if a claim is pending for a given service provider

* [eth-contracts] Deprecate internal registry consumption (#491)

Remove all protocol references to the registry
* #494
* #493
* #495
* #490

* Crytic round 3 (#488)

* Unused function calls

* Revert

* Test fix

* Reduce unused returns

* Try to abstract some stuff without changing order

* Remove spFactory double init

* Move some stuff around

* Remove unused variable (#496)

* Remove registry from service type manager, migrations and mock contracts (#497)

* ClaimsManager should be 100% now (#499)

* [eth-contracts] ServiceProviderFactory init fix + Coverage (#498)

* Increased coverage for ServiceTypeManager, ServiceProviderFactory, Staking. DelegateManager

* Fix registry governance pattern + change guardianExecTx to revert on tx failure (#500)

* Add more coverage for Governance and ServiceTypeManager (#501)

* More tests

* bug fix

* this is why you don't copy paste

* [eth-contracts] Imprecise arithmetic operations (#502)

* Restructure spDeployerCut calculation to address crytic

* [eth-contracts] Ganache test to Istanbul (#503)

* Add token & registry governance tests + remove RegistryInterface (#505)

* [eth-contracts] Unused return value + constants (#504)

* Fix unused return value in validateBalance flow, https://crytic.io/AudiusProject/audius-protocol/117/security_checks/mlt8Dl0gQ5Gxt-oxTB3vDA
* Update default values for constants -
        creator node type min stake - 200,000 AUD
        creator node type max stake - 3,000,000 AUD
        discovery provider type min stake - 200,000 AUD
        discovery provider type max stake - 2,000,000 AUD
        fundingRoundBlockDiff - 46523 blocks
        fundingAmount - 1342465.75342 AUD

* Add NATSPEC comments (#486)

* some comments

* More comments

* more comments

* docs for ContractManager.sol

* Two more contracts to go

* ServiceTypeManager.sol

* Staking.sol should be done

* Lint

* Update with most recent mainnet changes

* lint fixes

* AudiusAdminUpgradeability comment fixes

* Lints

* Claims fix

* DelegateManageer comments update

* Minor

* Migration comment

* Commenit

Co-authored-by: Sid Sethi <sidsethi93@gmail.com>
Co-authored-by: Hareesh Nagaraj <hareesh.nagaraj@gmail.com>

* [eth-contracts] Strict equality + local variable shadowing (#506)

* Strict equality
* Local shadowing

* Commenit

* Stale TODO removal

* [C01] A malicious delegator can permanently lock all stake and rewards for a victim service provider and all of its honest delegators (#561)

* Reset locked stake for SP on cancel undelegate stake + test

* [C02] Rewards pay out incorrectly when the service provider has a pending “decrease stake” request (#562)

* [C03] Updating or removing a service type causes critical accounting errors (#555)

* [M01] Complicated state updates (#539)

* Governance submitProposalVote vote update refactors
* DelegateManager stake balance update refactors

* [H01] A malicious delegator can prevent all other delegators from delegating (#552)

* Enforce minimum delegation amount for each SP a delegator delegates to instead of across the delegator account
* Removal of unused delegatorStakeTotal as it is no longer needed
* Additional test case added to verify behavior

* [H08] Unresponsive service provider locks delegator stake (#556)

* Allow claiming of reward to be callable by anyone, preventing delegators from being stuck when an SP is unresponsive

* [H02] Delegators can prevent service providers from deregistering endpoints (#570)

* Enabling service providers to forcibly remove a delegator
* If maximum bounds are violated due to a delegator stake, SP can forcibly remove their stake and return funds, enabling deregistration
* Test case to confirm functionality

* [H06] Endpoint registration can be frontrun (#573)

* Increase decreaseStakeLockupDuration from 10blocks to 1week

* Make decreaseStakeLockupDuration init param so tests can run with lower value than migration

* [H07] A service provider can prevent their delegators from undelegating their stake (#577)

* Enforce minimum account balance for service provider only, excluding delegator balance (per audit suggestion)
* Ensures delegate operations can never force a service provider below the minimum stake value as they are forced to maintain the minimum in direct stake
* Corresponding test fixes

* Add event emission to Governance functions setRegistryAddress() & transferGuardianship() (#563)

* [H05] The quorum requirement can be trivially bypassed with sybil accounts (#574)

* Change votingQuorum to votingQuorumPercent + update evaluateProposalOutcome logic + update migration

* Add mul overflow comment + fix all governance tests + add test for new quorum check

* [H04] No incentive for evaluating proposals with outcome other than Yes (#575)

* Add bounded InProgressProposals array and block new proposal submission if evaluatable proposals exist or if array bounds reached

* Add test for maxInProgressProposals val + fix previous tests

* Make inProgressProposalsAreUpToDate() function publicly accessible + add tests

* Make maxInProgressProposals value uint16 instead of uint8, so we can handle more than 255 concurrent proposals

* Remove comment

* Fix test + comment logs

* Restrict function mutability

* [M05] Only active stakers can evaluate proposals

* Enable any party to evaluate proposal, corresponding test case updated

* [M09] Ties in governance proposals are approved

* Ties are now reject, corresponding test case added

* [M05] Only active stakers can evaluate proposals (follow-up)

* Fix compilation error introduced by https://github.com/AudiusProject/audius-protocol/pull/572/files

* [M08] Service providers and delegators can mistakenly soft-lock their own stake (#567)

* Reject decreaseStake / undelegate requests for amount of zero, eliminating soft-lock conditio
* Corresponding test case

* [M03] Lack of event emission after sensitive changes (#583)

* Events added for key state changes, test verification added for each new event

* [M02] Inconsistently checking initialization (#587)

* Add requireIsInitialized() check to all functions + update mutability as needed

* [M07] Semantic overloading in the No outcome of proposals (#579)

* Add new Veto state to eliminate duplicate 'No' outcome
* Corresponding test updated

* [M06] Voting period and quorum can be set to zero (#568)

* Voting period and quorum values checked prior to setting
* Corresponding test case

* Contracts have artifacts leftover from earlier test versions (#551)

* No-op PR, changes addressed in M03 (event emission PR)

* [L02] Duplicated newProposalId calculation

* [L06] Misleading comments, docstrings, and typographical errors (#546)

Co-authored-by: Hareesh Nagaraj <hareesh.nagaraj@gmail.com>

* [L03] Duplicated staker check (#580)

* Approach detailed here, opted to implement 'isCurrentStaker' only

* [M04] Lack of input validation (#569)

Audit feedback applied here, note that all setGovernanceAddress/initialize functions within protocol now perform the same isGovernanceAddress check (slight deviation from audit feedback in PR). Coverage drop will be addressed independently.

* [N05] Declaring two variables for some addresses #590

* Remove duplicate address tracking

* [M10] Some state variables are not set during initialize (#589)

* Documenting state variables that are not set during initialize + requiring they are set in all relevant functions

* Lint

* Removing unnecessary things

* Require statement abstraction

Co-authored-by: Hareesh Nagaraj <hareesh.nagaraj@gmail.com>

* [M02 - pt2 - please see pt1 PR] Inconsistently checking initialization (#594)

* [N02] Lack of explicit visibility in public state variables (#592)

* [N06] Not declaring uint as uint256 (fix) (#593)

* Explicitly declare all instances of uint as uint256

* [L08] Votes can be overwritten by calling the same function for the first vote (#596)

* Split submitProposalVote into submit and update functions

* Fix require stmt msgs + tests

* [N04] Renaming suggestions (#595)

* ClaimsManager + ServiceProviderFactory rename

* Governance changes

* Additional ClaimsManager naming fix

* Lint

Co-authored-by: Sid Sethi <sidsethi93@gmail.com>

* [N01] Inconsistent style for error messages (#597)

* Consistent format for error messages with "ContractName: errorMessage"
* Any message used >1x within a contract is declared as a private string const to avoid duplication

* [N03] Named return variables (#600)

* All functions with a single return value no longer use a named return variable
* Functions returning a tuple explicitly use named return variables

* [L09] README file missing important information (#601)

* Eth contracts readme update

* Update top-level readme

* Add security section regarding responsible disclosure to top-level readme

* [L01] Governance proposal description only stored in log (#550)

* Governance proposal description only stored in log

* Enforce maxDescriptionLength on proposal descriptions + make value governable

* Standardize require statements + remove .only in test

* WIP

* Remove named return variable

Co-authored-by: Sid Sethi <sidsethi93@gmail.com>

* Update to 0.5.17 (#602)

* Update solc version to 0.5.17

* Remove unnused var from and add natspec to InitializableV2 (#604)

* Remove unnused var from and add natspec to InitializableV2

* Revert test file changes

* [H04 - pt 2 of 2] No incentive for evaluating proposals with outcome other than Yes (#609)

* Fix bug where veto proposal halts all proposal actions by failing to clear vetoed proposal from inProgressProposals array

* Fixes bug where changing target contract address would cause deadlock since any associated proposals would never evaluate

* Fix maxInProgressProposals off-by-one issue

* Remove unreachable line (#611)

* Vulnerability in proposal execution, which allows circumvention of guardian veto (#607)

* Add modifiable execution delay to governance

* [L10] Proposed target code can change (#605)

* Ensure governance enforces consistent contract state between proposal and evaluation
* Test case with selfdestruct functioning

* Enforce consistent block times + Default undelegate lockup duration update (#612)

* Calculate block differences based on 13s, not 15s
* Enforce default undelegateLockupDuration value on deploy to match decreaseStake lockup duration

* More test coverage in mainnet-audit-feedback (#591)

* Incorrect number of args in initialize

* Test getInProgressProposals in Governance

* Check setMaxInProgressProposals for invalid value

* Fail to add version for invalid service

* a non governance address will not be set in ServiceTypeManager

* delegate manager setGovernanceAddress contract check test

* minimum stake test for claimRewards

* Accounts index doesn't work on circle

* setGovernanceAddress check in ClaimsManager

* Fix test

* setGovernanceAddress in Staking contract

* Test addresses in between setup

* Test fixes

* More governance tests

* i don't think this does anything

* SPFactory init vars

* Governance init coverage

* test who can remove a delegator

* Missing await's

* More governance testing

* sp factory should be at 100%

* Test require fail scenarios in Governance

* Partial test working

* removeDelegator test without request undelegate stake pending

* Remove .only

* YATF

* fix gov initialize

* Simply test case

* NIT - logs

* new registry test

* remove dead comments

* Exclude new test contract files (#613)

Co-authored-by: Hareesh Nagaraj <hareesh.nagaraj@gmail.com>

* [L04] Lack of indexed parameters in events (#614)

* Add indexed keyword to event fields in ServiceProviderFactory
* ClaimProcessed addressed in prior PR (#583)

* Add ability for guardianAddress to submit proposals + add test (#616)

* Add ability for guardianAddress to submit proposals + add test

* Test fix

* [mainnet] Consume UpgradeabilityProxy in AudiusAdminUpgradeabilityProxy (#627)

* Eliminate consumption of OZ AdminUpgradeabilityProxy in favor of UpgradeabilityProxy
* Reduces unused API surface in AdminUpgradeabilityProxy (changeAdmin, upgradeToAndCall were unsued) in favor of explicit management of lower level contract
* Eliminates unnecessary storage of admin + governance address in each proxy contract, and makes governance the administrator

* [Audit-Feedback-2] Pull request to aggregate 2nd round of changes (#657)

* [N06] Convert rest of uint to uint256 (#649)

Original PR https://github.com/AudiusProject/audius-protocol/pull/593/files.

* [L05] Contracts have artifacts leftover from earlier test versions (#656)

* Original PR https://github.com/AudiusProject/audius-protocol/pull/583/files#diff-97eaf3b56cab95094247b87ff242d988L35-L36
* Remove test token values

* [N01] Inconsistent style for error messages (#653)

* Standardize any remaining error messages

* [N04] Renaming suggestions (#651)

* Adding indexed to remaining events (#659)

* Original PR https://github.com/AudiusProject/audius-protocol/pull/614/files
* Add indexed to the remaining events

* [H11] A service provider can prevent their delegators from undelegating their stake (#654)

* Remove undelegate bound validation, ensuring a delegator is never stuck
* Test case confirmed behavior and fix

* [H02] Delegators can prevent service providers from deregistering endpoints (#662)

* Old PR - #570
* Adds a time lock mechanism to removeDelegator, ensuring that a service provider cannot maliciously remove delegators to get around slash actions or other protocol enforcement
* Enforce relationship between undelegate lockup duration and voting period + execution delay
* Enforce relationship between removeDelegator lockup duration and voting period + execution delay
* Tests added

* Fix typos (#672)

* [H10] A service provider can deceive its delegators (#666)

* Impose time lock for updating deployer cut
* Enforce relationship between update deployer cut time lock and funding round block diff
* Enforce relationship between decrease stake lockup and votingPeriod + executionDelay
* Additional tests

* Comment nits (#677)

* Surface level comment changes for additional clarity

Co-authored-by: Dheeraj Manjunath <dheerajmanju1@gmail.com>

* Preserve audited eth-contracts state

Co-authored-by: Hareesh Nagaraj <hareesh.nagaraj@gmail.com>
Co-authored-by: Dheeraj Manjunath <dheerajmanju1@gmail.com>
Co-authored-by: Roneil Rumburg <roneil@audius.co>
  • Loading branch information
4 people committed Aug 18, 2020
1 parent f76826b commit c180306
Show file tree
Hide file tree
Showing 124 changed files with 24,141 additions and 7,054 deletions.
16 changes: 12 additions & 4 deletions .circleci/config.yml
Expand Up @@ -7,6 +7,7 @@ orbs:
aws-eks: circleci/aws-eks@0.1.0
helm: circleci/helm@0.1.2
kubernetes: circleci/kubernetes@0.3.0
coveralls: coveralls/coveralls@1.0.6
jobs:
test-mad-dog-e2e:
machine:
Expand Down Expand Up @@ -54,11 +55,11 @@ jobs:
- image: trufflesuite/ganache-cli:latest
# https://discuss.circleci.com/t/docker-using-local-image/11581/9
# https://circleci.com/docs/2.0/configuration-reference/#docker
command: ["-l", "8000000"]
command: ["-l", "8000000", "-a", "50"]
- image: trufflesuite/ganache-cli:latest
# https://discuss.circleci.com/t/docker-using-local-image/11581/9
# https://circleci.com/docs/2.0/configuration-reference/#docker
command: ["-l", "8000000", "-p", "8546"]
command: ["-l", "8000000", "-p", "8546", "-a", "50"]

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
Expand Down Expand Up @@ -171,7 +172,7 @@ jobs:
docker:
- image: circleci/node:10.16.3
- image: trufflesuite/ganache-cli:latest
command: ["--port=8546"]
command: ["--port=8546", "-a", "50", "-l", "8000000"]
parameters:
force:
type: boolean
Expand All @@ -198,13 +199,20 @@ jobs:
paths:
- eth-contracts/node_modules
key: v1-dependencies-{{ checksum "eth-contracts/package.json" }}
# run tests!
- run:
name: run_lint
command: |
cd eth-contracts
npm run lint-circle-ci
cd ../
- run:
name: run_tests
command: |
cd eth-contracts
npm run test-circle-ci
cd ../
- coveralls/upload:
path_to_lcov: ./eth-contracts/coverage/lcov.info

# Disabled - not included in any workflows below
# Not removing code in case of potential re-enabling
Expand Down
63 changes: 55 additions & 8 deletions README.md
Expand Up @@ -3,25 +3,72 @@
---

# audius-protocol
Audius is working to create a fully decentralized community of artists, developers, and listeners collaborating to share and defend the world’s music.

This repository encompasses all of the services, contracts and libs that comprise the Audius protocol.

[![CircleCI](https://circleci.com/gh/AudiusProject/audius-protocol/tree/master.svg?style=svg&circle-token=e272a756b49e50a54dcc096af8fd8b0405f6bf41)](https://circleci.com/gh/AudiusProject/audius-protocol/tree/master)

Audius is a decentralized, community-owned music-sharing protocol and app. It provides a
censorship-resistant alternative to SoundCloud that helps artists distribute anything they
want directly to fans, creating a unique and differentiated catalog. The mission of the
project is to give everyone the freedom to share, monetize, and listen to any audio.

This repository encompasses all of the services, contracts, and client-side libraries that
comprise the Audius protocol.

For a more detailed overview of how Audius works, how these components interact with one
another, how to run an off-chain service, and more, see the [Audius protocol wiki](https://github.com/AudiusProject/audius-protocol/wiki) for more details.


## Install

The Audius protocol has many moving pieces, on-chain and off-chain. Refer to the
installation and usage instructions for any of the sub-components of the Audius protocol:

### Audius Services

These off-chain services are run by community members via the Audius staking system:

| Service | Description
| -------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------
| [`creator-node`](creator-node) | Maintains the availability of users' content on IPFS including user metadata, images, and audio content
| [`discovery-provider`](discovery-provider) | Indexes and stores the contents of the audius contracts on the ethereum blockchain for clients to query via an API
| [`identity-service`](identity-service) | Stores encrypted auth ciphertexts, does Twitter oauth and relays transactions on behalf of users
| [`content-service`](content-service) | Monitors Audius activity and intelligently caches content to increase availability

### Audius Smart Contracts & Libs
### Audius Smart Contracts

The independent sets of smart contracts that underpin the Audius protocol:

| Contracts | Description
| -------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------
| [`contracts`](https://github.com/AudiusProject/audius-protocol/tree/master/contracts) | The POA network smart contracts for the Audius protocol, encompassing user account, content listing, and content interaction functionality
| [`eth-contracts`](https://github.com/AudiusProject/audius-protocol/tree/master/eth-contracts) | The ethereum smart contracts that run the Audius protocol, encompassing the Audius ERC20 token and functionality for staking, off-chain service registration / lookup, and governance


### Audius Client Libraries

Client-side libraries to provide a unified interface for interacting with the entire
Audius protocol:

| Lib | Description
| Library | Description
| -------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------
| [`libs`](https://github.com/AudiusProject/audius-protocol/tree/master/libs) | An easy interface to the distributed web and audius services: Identity Service, Discovery Provider, Creator Node
| [`contracts`](https://github.com/AudiusProject/audius-protocol/tree/master/contracts) | The smart contracts being developed for the audius streaming protocol
| [`eth-contracts`](https://github.com/AudiusProject/audius-protocol/tree/master/eth-contracts) | The ethereum smart contracts being developed for the audius streaming protocol
| [`libs`](https://github.com/AudiusProject/audius-protocol/tree/master/libs) | A complete javascript interface to the Audius smart contracts and Audius services: Identity Service, Discovery Provider, Creator Node

## Usage

Refer to the READMEs of the various Audius components listed above for specific usage
instructions!

## Contributing

We welcome contributions to Audius from anyone who opens a PR. Feel free to reach out to
our team [on Discord](https://discord.com/invite/yNUg2e2) or via other channels for feedback and/or support!

## Security

Please report security issues to `security@audius.co` with a description of the
vulenerability and any steps to reproduce. We have bounties available for issues reported
via responsible disclosure!

## License

Apache 2.0: [LICENSE file](https://github.com/AudiusProject/audius-protocol/blob/master/LICENSE)
8 changes: 4 additions & 4 deletions contracts/contracts/registry/RegistryContract.sol
Expand Up @@ -11,10 +11,10 @@ import "../interface/RegistryInterface.sol";
*/
contract RegistryContract is Ownable {

struct Multihash {
bytes32 digest;
uint8 hashFn;
uint8 size;
struct Multihash {
bytes32 digest;
uint8 hashFn;
uint8 size;
}

address payable internal registryAddress;
Expand Down
3 changes: 3 additions & 0 deletions crytic-config.json
@@ -0,0 +1,3 @@
{
"cwd": "eth-contracts"
}
6 changes: 5 additions & 1 deletion eth-contracts/.gitignore
Expand Up @@ -5,4 +5,8 @@
.npmrc
ganache_log.txt
node_modules/
build/
build/
coverage/
coverage.json
coverage.zip
migrations/migration-output.json
15 changes: 15 additions & 0 deletions eth-contracts/.solcover.js
@@ -0,0 +1,15 @@
module.exports = {
providerOptions: {
// intentionally set to lower than 50 (default) to skip a test that requires 40 accounts
'total_accounts': 20
},
skipFiles: [
'test/TestContract.sol',
'test/MockDelegateManager.sol',
'test/MockGovernance.sol',
'test/MockStakingCaller.sol',
'test/StakingUpgraded.sol',
'test/GovernanceUpgraded.sol',
'test/MockAccount.sol'
]
}
11 changes: 9 additions & 2 deletions eth-contracts/.soliumrc.json
@@ -1,5 +1,5 @@
{
"extends": "solium:all",
"extends": "solium:recommended",
"plugins": ["security"],
"rules": {
"quotes": ["error", "double"],
Expand All @@ -10,7 +10,14 @@
"max-len": ["error", 99],
"no-unused-vars": ["error"],
"pragma-on-top": ["error"],
"function-order": ["error"],
"function-order": [
"error",
{
"ignore": {
"functions": ["initialize"]
}
}
],
"visibility-first": ["error"],
"security/no-inline-assembly": ["warning"]
}
Expand Down
57 changes: 55 additions & 2 deletions eth-contracts/README.md
@@ -1,3 +1,56 @@
# eth-contracts
# Audius Ethereum smart contracts

Contains contracts for ERC-20 token, staking functionality, service provider registration and version management
[![Coverage Status](https://coveralls.io/repos/github/AudiusProject/audius-protocol/badge.svg)](https://coveralls.io/github/AudiusProject/audius-protocol)

Audius has two sets of contracts - the one in this directory, which runs on Ethereum mainnet in
production, and the one
[here](https://github.com/AudiusProject/audius-protocol/tree/master/contracts) which runs on POA
mainnet in production.

The smart contracts in this directory implement the Audius ERC-20 token, staking functionality, service
provider registration, delegator support and off-chain service version management. For a
more in depth look at the contracts and architecture, please see the
[Audius Ethereum Contracts Wiki](https://github.com/AudiusProject/audius-protocol/wiki/Ethereum-Contracts-Overview)
page.

The two sets of smart contracts do not interact with one another, but both sets are used by end-user
clients and the off-chain services that run Audius to make use of their respective
functionality.

## Installation

To install and run the contracts locally, clone the `audius-protocol` repo and go into the
`eth-contracts` folder. Assuming you have node.js, npm, and docker installed, run the
following commands to run Ganache and migrate the contracts.

*Note* - Ganache from the command below is exposed on port 8546, not 8545.

```
npm install
npm run ganache
npm run truffle-migrate
```

## Test

To run tests, run the following command:

```
npm run test
```

To run tests with coverage calculation, run the following command:

```
npm run test-coverage
```

## Security

Please report security issues to `security@audius.co` with a description of the
vulenerability and any steps to reproduce. We have bounties available for issues reported
via responsible disclosure!

## License

Apache 2.0
30 changes: 20 additions & 10 deletions eth-contracts/contract-config.js
Expand Up @@ -2,23 +2,33 @@
// name to other params
module.exports = {
'development': {
versionerAddress: null,
treasuryAddress: null
proxyDeployerAddress: null,
proxyAdminAddress: null,
guardianAddress: null
},
'test_local': {
versionerAddress: null,
treasuryAddress: null
proxyDeployerAddress: null,
proxyAdminAddress: null,
guardianAddress: null
},
'soliditycoverage': {
proxyDeployerAddress: null,
proxyAdminAddress: null,
guardianAddress: null
},
'audius_private': {
versionerAddress: '0xbbbb93A6B3A1D6fDd27909729b95CCB0cc9002C0',
treasuryAddress: null
proxyDeployerAddress: null,
proxyAdminAddress: null,
guardianAddress: null
},
'staging': {
versionerAddress: '0xcccc7428648c4AdC0ae262D3547584dDAE25c465',
treasuryAddress: '0xcccc7428648c4AdC0ae262D3547584dDAE25c465'
proxyDeployerAddress: null,
proxyAdminAddress: null,
guardianAddress: null
},
'production': {
versionerAddress: '0x6054e3dcec782744ec022c2958c3f9641b764b42',
treasuryAddress: '0x0da86ededd278072162a866a30806192f2840cd5'
proxyDeployerAddress: null,
proxyAdminAddress: null,
guardianAddress: null
}
}
73 changes: 73 additions & 0 deletions eth-contracts/contracts/AudiusAdminUpgradeabilityProxy.sol
@@ -0,0 +1,73 @@
pragma solidity ^0.5.0;

import "@openzeppelin/upgrades/contracts/upgradeability/UpgradeabilityProxy.sol";


/**
* @notice Wrapper around OpenZeppelin's UpgradeabilityProxy contract.
* Permissions proxy upgrade logic to Audius Governance contract.
* https://github.com/OpenZeppelin/openzeppelin-sdk/blob/release/2.8/packages/lib/contracts/upgradeability/UpgradeabilityProxy.sol
* @dev Any logic contract that has a signature clash with this proxy contract will be unable to call those functions
* Please ensure logic contract functions do not share a signature with any functions defined in this file
*/
contract AudiusAdminUpgradeabilityProxy is UpgradeabilityProxy {
address private proxyAdmin;
string private constant ERROR_ONLY_ADMIN = (
"AudiusAdminUpgradeabilityProxy: Caller must be current proxy admin"
);

/**
* @notice Sets admin address for future upgrades
* @param _logic - address of underlying logic contract.
* Passed to UpgradeabilityProxy constructor.
* @param _proxyAdmin - address of proxy admin
* Set to governance contract address for all non-governance contracts
* Governance is deployed and upgraded to have own address as admin
* @param _data - data of function to be called on logic contract.
* Passed to UpgradeabilityProxy constructor.
*/
constructor(
address _logic,
address _proxyAdmin,
bytes memory _data
)
UpgradeabilityProxy(_logic, _data) public payable
{
proxyAdmin = _proxyAdmin;
}

/**
* @notice Upgrade the address of the logic contract for this proxy
* @dev Recreation of AdminUpgradeabilityProxy._upgradeTo.
* Adds a check to ensure msg.sender is the Audius Proxy Admin
* @param _newImplementation - new address of logic contract that the proxy will point to
*/
function upgradeTo(address _newImplementation) external {
require(msg.sender == proxyAdmin, ERROR_ONLY_ADMIN);
_upgradeTo(_newImplementation);
}

/**
* @return Current proxy admin address
*/
function getAudiusProxyAdminAddress() external view returns (address) {
return proxyAdmin;
}

/**
* @return The address of the implementation.
*/
function implementation() external view returns (address) {
return _implementation();
}

/**
* @notice Set the Audius Proxy Admin
* @dev Only callable by current proxy admin address
* @param _adminAddress - new admin address
*/
function setAudiusProxyAdminAddress(address _adminAddress) external {
require(msg.sender == proxyAdmin, ERROR_ONLY_ADMIN);
proxyAdmin = _adminAddress;
}
}

0 comments on commit c180306

Please sign in to comment.