Skip to content

Commit

Permalink
Improve test and update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
rya-sge committed May 2, 2024
1 parent 4774b7e commit 4316ce8
Show file tree
Hide file tree
Showing 159 changed files with 3,047 additions and 1,510 deletions.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,16 @@ The report is available in [ABDK_CMTA_CMTATRuleEngine_v_1_0.pdf](doc/audits/ABDK

You will find the report produced by [Slither](https://github.com/crytic/slither) in

| Version | File |
| ------- | ------------------------------------------------------------ |
| v2.3.0 | [v2.3.0-slither-report.md](doc/audits/tools/v2.3.0-slither-report.md) |
| v2.3.1 | [v2.3.1-slither-report.md](doc/audits/tools/v2.3.1-slither-report.md) |
| Version | File |
| ------------ | ------------------------------------------------------------ |
| Last version | [slither-report.md](doc/audits/tools/slither-report.md) |
| v2.3.0 | [v2.3.0-slither-report.md](doc/audits/tools/v2.3.0-slither-report.md) |
| v2.3.1 | [v2.3.1-slither-report.md](doc/audits/tools/v2.3.1-slither-report.md) |


### Test

- A summary of automatic tests is available in [test.pdf](doc/general/test/test.pdf).
- A code coverage is available in [index.html](doc/general/test/coverage/index.html).

> Note that we do not perform tests on the internal functions `init` of the different modules.
A code coverage is available in [index.html](doc/general/test/coverage/index.html).


### Remarks
Expand Down
12 changes: 11 additions & 1 deletion contracts/deployment/CMTAT_BEACON_FACTORY.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// SPDX-License-Identifier: UNLICENSED
//SPDX-License-Identifier: MPL-2.0
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol";

import '@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol';
import "../CMTAT_PROXY.sol";
import "../modules/CMTAT_BASE.sol";
import "../libraries/FactoryErrors.sol";
import '@openzeppelin/contracts/access/AccessControl.sol';

/**
Expand All @@ -29,6 +30,15 @@ contract CMTAT_BEACON_FACTORY is AccessControl {
* @param beaconOwner owner
*/
constructor(address implementation_, address factoryAdmin, address beaconOwner) {
if(factoryAdmin == address(0)){
revert FactoryErrors.CMTAT_Factory_AddressZeroNotAllowedForFactoryAdmin();
}
if(beaconOwner == address(0)){
revert FactoryErrors.CMTAT_Factory_AddressZeroNotAllowedForBeaconOwner();
}
if(implementation_ == address(0)){
revert FactoryErrors.CMTAT_Factory_AddressZeroNotAllowedForLogicContract();
}
beacon = new UpgradeableBeacon(implementation_, beaconOwner);
_grantRole(DEFAULT_ADMIN_ROLE, factoryAdmin);
_grantRole(CMTAT_DEPLOYER_ROLE, factoryAdmin);
Expand Down
12 changes: 10 additions & 2 deletions contracts/deployment/CMTAT_TP_FACTORY.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
//SPDX-License-Identifier: MPL-2.0
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import "../CMTAT_PROXY.sol";
import "../libraries/FactoryErrors.sol";
import '@openzeppelin/contracts/access/AccessControl.sol';
/**
* @notice Factory to deploy transparent proxy
Expand All @@ -20,11 +20,19 @@ contract CMTAT_TP_FACTORY is AccessControl {
address public immutable logic;
address[] public cmtatsList;



/**
* @param logic_ contract implementation
* @param factoryAdmin admin
*/
constructor(address logic_, address factoryAdmin) {
if(logic_ == address(0)){
revert FactoryErrors.CMTAT_Factory_AddressZeroNotAllowedForLogicContract();
}
if(factoryAdmin == address(0)){
revert FactoryErrors.CMTAT_Factory_AddressZeroNotAllowedForFactoryAdmin();
}
logic = logic_;
_grantRole(DEFAULT_ADMIN_ROLE, factoryAdmin);
_grantRole(CMTAT_DEPLOYER_ROLE, factoryAdmin);
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ICCIPToken.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//SPDX-License-Identifier: MPL-2.0

pragma solidity ^0.8.0;
pragma solidity ^0.8.20;

/**
* @notice CCIP Pool with mint
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ICMTATSnapshot.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//SPDX-License-Identifier: MPL-2.0

pragma solidity ^0.8.0;
pragma solidity ^0.8.20;

/**
* @notice interface to represent a CMTAT with snapshot
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IDebtGlobal.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//SPDX-License-Identifier: MPL-2.0

pragma solidity ^0.8.0;
pragma solidity ^0.8.20;

/**
* @notice interface to represent debt tokens
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/draft-IERC1404/draft-IERC1404.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//SPDX-License-Identifier: MPL-2.0

pragma solidity ^0.8.0;
pragma solidity ^0.8.20;

/*
* @dev Contrary to the ERC-1404, this interface does not inherit from the ERC20 interface
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//SPDX-License-Identifier: MPL-2.0

pragma solidity ^0.8.0;
pragma solidity ^0.8.20;

interface IERC1404EnumCode {
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//SPDX-License-Identifier: MPL-2.0

pragma solidity ^0.8.0;
pragma solidity ^0.8.20;

import "./draft-IERC1404.sol";
import "./draft-IERC1404EnumCode.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/engine/IAuthorizationEngine.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MPL-2.0

pragma solidity ^0.8.0;
pragma solidity ^0.8.20;

interface IAuthorizationEngine {
/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/engine/IRuleEngine.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MPL-2.0

pragma solidity ^0.8.0;
pragma solidity ^0.8.20;

import "../draft-IERC1404/draft-IERC1404Wrapper.sol";

Expand Down
9 changes: 9 additions & 0 deletions contracts/libraries/FactoryErrors.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//SPDX-License-Identifier: MPL-2.0

pragma solidity ^0.8.20;

library FactoryErrors {
error CMTAT_Factory_AddressZeroNotAllowedForFactoryAdmin();
error CMTAT_Factory_AddressZeroNotAllowedForBeaconOwner();
error CMTAT_Factory_AddressZeroNotAllowedForLogicContract();
}
1 change: 0 additions & 1 deletion contracts/mocks/RuleEngine/RuleEngineMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pragma solidity ^0.8.20;
import "./interfaces/IRule.sol";
import "./interfaces/IRuleEngineMock.sol";
import "./RuleMock.sol";
import "./CodeList.sol";

/*
* @title a mock for testing, not suitable for production
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/RuleEngine/interfaces/IRule.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//SPDX-License-Identifier: MPL-2.0

pragma solidity ^0.8.0;
pragma solidity ^0.8.20;

import "../../../interfaces/draft-IERC1404/draft-IERC1404Wrapper.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/RuleEngine/interfaces/IRuleEngineMock.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//SPDX-License-Identifier: MPL-2.0

pragma solidity ^0.8.0;
pragma solidity ^0.8.20;

import "./IRule.sol";
import "../../../interfaces/engine/IRuleEngine.sol";
Expand Down
8 changes: 2 additions & 6 deletions contracts/modules/internal/ERC20SnapshotModuleInternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

pragma solidity ^0.8.20;

import "../../../openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol";
import "../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import "../../../openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol";
import {Arrays} from '@openzeppelin/contracts/utils/Arrays.sol';

import "../../libraries/Errors.sol";
import "../../interfaces/ICMTATSnapshot.sol";
import "./base/SnapshotModuleBase.sol";
import "../../interfaces/ICMTATSnapshot.sol";
/**
* @dev Snapshot module internal.
*
Expand All @@ -19,7 +15,7 @@ import "./base/SnapshotModuleBase.sol";
because overriding this function can break the contract.
*/

abstract contract ERC20SnapshotModuleInternal is SnapshotModuleBase, ERC20Upgradeable {
abstract contract ERC20SnapshotModuleInternal is ICMTATSnapshot, SnapshotModuleBase, ERC20Upgradeable {
using Arrays for uint256[];

/**
Expand Down
1 change: 0 additions & 1 deletion contracts/modules/internal/ValidationModuleInternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.20;

import "../../../openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol";
import "../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import "../../interfaces/draft-IERC1404/draft-IERC1404Wrapper.sol";
import "../../interfaces/engine/IRuleEngine.sol";
/**
* @dev Validation module.
Expand Down
20 changes: 1 addition & 19 deletions contracts/modules/security/AuthorizationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,15 @@
pragma solidity ^0.8.20;

import "../../../openzeppelin-contracts-upgradeable/contracts/access/AccessControlUpgradeable.sol";
import "../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";

import "../../libraries/Errors.sol";
import "../../interfaces/engine/IAuthorizationEngine.sol";

abstract contract AuthorizationModule is AccessControlUpgradeable {
IAuthorizationEngine private authorizationEngine;
/**
* @dev Emitted when a rule engine is set.
*/
event AuthorizationEngine(IAuthorizationEngine indexed newAuthorizationEngine);
// BurnModule
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");
bytes32 public constant BURNER_FROM_ROLE = keccak256("BURNER_FROM_ROLE");
// CreditEvents
bytes32 public constant DEBT_CREDIT_EVENT_ROLE =
keccak256("DEBT_CREDIT_EVENT_ROLE");
// DebtModule
bytes32 public constant DEBT_ROLE = keccak256("DEBT_ROLE");
// EnforcementModule
bytes32 public constant ENFORCER_ROLE = keccak256("ENFORCER_ROLE");
// MintModule
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
// PauseModule
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
// SnapshotModule
bytes32 public constant SNAPSHOOTER_ROLE = keccak256("SNAPSHOOTER_ROLE");

/**
* @dev
*
Expand Down
1 change: 0 additions & 1 deletion contracts/modules/wrapper/controllers/ValidationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

pragma solidity ^0.8.20;

import "../../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import "../../security/AuthorizationModule.sol";
import "../../internal/ValidationModuleInternal.sol";
import "../core/PauseModule.sol";
Expand Down
1 change: 0 additions & 1 deletion contracts/modules/wrapper/core/BaseModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
pragma solidity ^0.8.20;

// required OZ imports here
import "../../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import "../../security/AuthorizationModule.sol";
import "../../../libraries/Errors.sol";

Expand Down
1 change: 0 additions & 1 deletion contracts/modules/wrapper/core/ERC20BaseModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
pragma solidity ^0.8.20;

// required OZ imports here
import "../../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import "../../../../openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol";
import "../../../libraries/Errors.sol";

Expand Down
3 changes: 2 additions & 1 deletion contracts/modules/wrapper/core/ERC20BurnModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
pragma solidity ^0.8.20;

import "../../../../openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol";
import "../../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import "../../security/AuthorizationModule.sol";
import "../../../interfaces/ICCIPToken.sol";
abstract contract ERC20BurnModule is ERC20Upgradeable, ICCIPBurnFromERC20, AuthorizationModule {
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");
bytes32 public constant BURNER_FROM_ROLE = keccak256("BURNER_FROM_ROLE");
/**
* @notice Emitted when the specified `value` amount of tokens owned by `owner`are destroyed with the given `reason`
*/
Expand Down
3 changes: 2 additions & 1 deletion contracts/modules/wrapper/core/ERC20MintModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
pragma solidity ^0.8.20;

import "../../../../openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol";
import "../../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import "../../security/AuthorizationModule.sol";
import "../../../interfaces/ICCIPToken.sol";
abstract contract ERC20MintModule is ERC20Upgradeable, ICCIPMintERC20, AuthorizationModule {
// MintModule
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
/**
* @notice Emitted when the specified `value` amount of new tokens are created and
* allocated to the specified `account`.
Expand Down
2 changes: 2 additions & 0 deletions contracts/modules/wrapper/core/EnforcementModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ abstract contract EnforcementModule is
EnforcementModuleInternal,
AuthorizationModule
{
// EnforcementModule
bytes32 public constant ENFORCER_ROLE = keccak256("ENFORCER_ROLE");
string internal constant TEXT_TRANSFER_REJECTED_FROM_FROZEN =
"Address FROM is frozen";

Expand Down
3 changes: 2 additions & 1 deletion contracts/modules/wrapper/core/PauseModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
pragma solidity ^0.8.20;

import "../../../../openzeppelin-contracts-upgradeable/contracts/utils/PausableUpgradeable.sol";
import "../../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import "../../security/AuthorizationModule.sol";

/**
Expand All @@ -17,6 +16,8 @@ import "../../security/AuthorizationModule.sol";
* event of a large bug.
*/
abstract contract PauseModule is PausableUpgradeable, AuthorizationModule {
// PauseModule
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
string internal constant TEXT_TRANSFER_REJECTED_PAUSED =
"All transfers paused";
bool private isDeactivated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ abstract contract CreditEventsModule is
ContextUpgradeable,
AuthorizationModule
{
// CreditEvents
bytes32 public constant DEBT_CREDIT_EVENT_ROLE =
keccak256("DEBT_CREDIT_EVENT_ROLE");
CreditEvents public creditEvents;

/* Events */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ abstract contract DebtBaseModule is
ContextUpgradeable,
AuthorizationModule
{
// DebtModule
bytes32 public constant DEBT_ROLE = keccak256("DEBT_ROLE");
DebtBase public debt;

/* Events */
Expand Down
3 changes: 2 additions & 1 deletion contracts/modules/wrapper/extensions/ERC20SnapshotModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

pragma solidity ^0.8.20;

import "../../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import "../../security/AuthorizationModule.sol";
import "../../internal/ERC20SnapshotModuleInternal.sol";

Expand All @@ -16,6 +15,8 @@ abstract contract ERC20SnapshotModule is
ERC20SnapshotModuleInternal,
AuthorizationModule
{
// SnapshotModule
bytes32 public constant SNAPSHOOTER_ROLE = keccak256("SNAPSHOOTER_ROLE");
function __ERC20SnasphotModule_init_unchained() internal onlyInitializing {
// no variable to initialize
}
Expand Down
1 change: 0 additions & 1 deletion contracts/modules/wrapper/extensions/MetaTxModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
pragma solidity ^0.8.20;

import "../../../../openzeppelin-contracts-upgradeable/contracts/metatx/ERC2771ContextUpgradeable.sol";
import "../../../../openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";

/**
* @dev Meta transaction (gasless) module.
Expand Down
2 changes: 1 addition & 1 deletion doc/TOOLCHAIN.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,6 @@ npm run-script coverage
Slither is a Solidity static analysis framework written in Python3

```bash
slither . --checklist --filter-paths "openzeppelin-contracts-upgradeable|test" > slither-report.md
slither . --checklist --filter-paths "openzeppelin-contracts-upgradeable|openzeppelin-contracts|@openzeppelin|test" > slither-report.md
```

Loading

0 comments on commit 4316ce8

Please sign in to comment.