Skip to content

Commit

Permalink
Remove Router (#112)
Browse files Browse the repository at this point in the history
* added state machine contract

* state machine same states for all machines

* SlashingController initial commit

* Configurable slash reasons, in review states and proposal editing.

* deploying SlashingController

* fix state machine creation

* - Added stake freezing side effects to SlashingController
- Proposing slash checks for subject existence, unified interface isRegistered in AgentRegistry
- Fixed typos in docs (XXXRegistry reference to ERC1155 should be ERC721)

* WIP: slashing calculations

* test slashing amounts

* evidence handling

* added tests and comments

* fix onlyInState and natspec StateMachines

* SlashController: change frozen stake when reviewing proposal, fix events, tests

* SlashController: modify proposal tests, no need to check for proposal existance there

* SlashController: fix wrong next states size, removed unnecesary checks, reused error message MissingRole, tests

* FortaStaking: comments

* FortaStakingParameters: comments

* SlashingController: implements ISlashingController

* linting

* FortaStaking: make stake to shares converters public

* SlashController: removed MAX_STAKE penalty mode, since it will always be the max possible stake

* fix tests

* Update contracts/components/staking/SlashingController.sol

Co-authored-by: Hadrien Croubois <[email protected]>

* Update contracts/components/staking/SlashingController.sol

reentrancy fix returning deposit

Co-authored-by: Hadrien Croubois <[email protected]>

* Update contracts/components/staking/SlashingController.sol

reentrancy protection on slash deposit

Co-authored-by: Hadrien Croubois <[email protected]>

* SlashingController: msg.sender -> _msgSender(), fix role check for revert proposal

* SlashingController: immutable depositToken

* SlashingController: max string length for evidence

* StateMachines & SlashingController: refactor to more efficient state machines

* StateMachines attribution

* SlashingController and FortaStaking: reverted to accessControl SLASHER_ROLE for slash and freeze

* remove whitelist functionality, limit minting to Forta max supply

* fix escrow test

* flattened AgentRegistry_0_1_4.sol

* flattened ScannerRegistry_0_1_2.sol

* flattened AgentRegistry014, ScannerRegistry012, ScannerNodeVersion011, Dispatch015

* flatten FortaStaking FortaStakingParameters

* flattened FortaStakingParameters011 FortaStakoing011

* flattened dispatch, scanner node version, fortastaking and fortastakingparams

* test upgrade FortaStaking

* remove stray only

* deprecated Router, unified BaseComponentUpgradeables

* removed Router from README, tests

* expand deprecated comment and rename deprecated variable

* Update contracts/components/BaseComponentUpgradeable.sol

Co-authored-by: Francisco <[email protected]>

* Update contracts/components/BaseComponentUpgradeable.sol

Co-authored-by: Francisco <[email protected]>

* Update contracts/components/utils/Routed.sol

Co-authored-by: Francisco <[email protected]>

* expanded on versioned contract generation for test updates

* remove stray console.log in test

* mock router for upgrades testing

* Update README.md

Co-authored-by: Francisco <[email protected]>

* Update test/components/upgrades.test.js

Co-authored-by: Francisco <[email protected]>

* Update test/components/upgrades.test.js

Co-authored-by: Francisco <[email protected]>

* Update test/components/upgrades.test.js

Co-authored-by: Francisco <[email protected]>

* Update test/components/upgrades.test.js

Co-authored-by: Francisco <[email protected]>

* disableRouter is not access control restricted and fails if already 0

* remove unsafeSkipStorageCheck references

* fix tests

Co-authored-by: Hadrien Croubois <[email protected]>
Co-authored-by: Francisco <[email protected]>
  • Loading branch information
3 people authored Sep 28, 2022
1 parent 4137aed commit e7cf26a
Show file tree
Hide file tree
Showing 26 changed files with 9,577 additions and 373 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"editor.experimental.stickyScroll.enabled": true
"editor.stickyScroll.enabled": true
}
25 changes: 10 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ Holds the accepted Scanner Node software image IPFS hash. A change in the versio

[Access Control](https://docs.openzeppelin.com/contracts/4.x/api/access#AccessControl) Singleton for all contracts except Token and VestingWallets

### Router

- [File](https://github.com/forta-network/forta-contracts/blob/master/contracts/components/router/Router.sol)

Observer pattern allowing actions in contracts to have side effects. Currently unused.

### Forwarder

- [File](https://github.com/forta-network/forta-contracts/blob/master/contracts/components/metatx/Forwarder.sol)
Expand Down Expand Up @@ -138,15 +132,16 @@ The process to develop, test and deploy new implementations are as follow:
2. Bump the version accordingly. Contract versioning should follow semver and increment with each upgrade or deployment.
3. Develop according to good practices, modify __gap length to accommodate new state, add comments with storage accounting in contract variables and __gap values.
4. Write an upgradeability test in `test/components/upgrades.test.js`.
4.1 Deploy an upgradeable proxy with the base implementation, found in `components/_old/<component_folder>/<ComponentName>_X_Y_Z`.
If not there, either:
- Use `hardhat flattener` to generate one.
- If the contracts is deployed and the repo is not tagged and you are not sure if the exact files are in the current commit, generate a flattened version obtained from verified contracts in relevant block explorer (Etherscan, Polyscan...) and add it.
- Rename main component in flattened file to `<ComponentName>_X_Y_Z`.
4.2 Initialize all the state of the contract, assert the values are there.
4.3 Upgrade to the new implementation
4.4 Check the output from `upgrades-plugin`. If gap sizes changed, you may need to activate the flag `unsafeSkipStorageCheck` to deploy.
4.5 Assert the values of the state have not changed.
1. Deploy an upgradeable proxy with the base implementation, found in `components/_old/<component_folder>/<ComponentName>_X_Y_Z`.
If not there, either:
- Use `hardhat flatten` to generate a file with all the inheriting contracts.
- Remove duplicate licenses and pragma statements.
- Rename main component in flattened file to `<ComponentName>_X_Y_Z`.
- If the contracts is deployed and the repo is not tagged and you are not sure if the exact files are in the current commit, generate a flattened version obtained from verified contracts in relevant block explorer (Etherscan, Polyscan...) and add it.
2. Initialize all the state of the contract, assert the values are there.
3. Upgrade to the new implementation
4. Check the output from `upgrades-plugin`, if there is any problems fix them. Check the plugin [docs and faqs](https://docs.openzeppelin.com/upgrades-plugins/1.x/faq) if needed.
5. Assert the values of the state have not changed.
5. Execute the script `scripts/storageToTable` to print a markdown table of the before and after implementations
- You may need to execute `test/components/upgrades.test.js` with `it.only(<relevant_test>)` so both old and new implementations are present in `.openzeppelin/unknown-31337.json`. Delete delete `.openzeppelin/unknown-31337.json` before executing the test so `storageToTable` finds the correct implementations.
6. Visualize and assert that the sum of the storage reserved is the same before and after, and that the new gaps are adjusted correctly. If the test in 4.5 passes this is probably correct, if that test fails, something will not add up.
Expand Down
10 changes: 7 additions & 3 deletions contracts/components/BaseComponentUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ import "../tools/ENSReverseRegistration.sol";
* @dev The Forta platform is composed of "component" smart contracts that are upgradeable, share a common access
* control scheme and can send use routed hooks to signal one another. They also support the multicall pattern.
*
* This contract contains the base of Forta components. Contract inheriting this will have to call
* - __AccessManaged_init(address manager)
* - __Routed_init(address router)
* This contract contains the base of Forta components. Contracts that inherit this component must call
* - __BaseComponentUpgradeable_init(address manager)
* in their initialization process.
*/
abstract contract BaseComponentUpgradeable is
Expand All @@ -29,6 +28,11 @@ abstract contract BaseComponentUpgradeable is
UUPSUpgradeable,
IVersioned
{

function __BaseComponentUpgradeable_init(address __manager) internal initializer {
__AccessManaged_init(__manager);
__UUPSUpgradeable_init();
}

// Access control for the upgrade process
function _authorizeUpgrade(address newImplementation) internal virtual override onlyRole(UPGRADER_ROLE) {
Expand Down
Loading

0 comments on commit e7cf26a

Please sign in to comment.