diff --git a/doc/slither-report.md b/doc/slither-report.md index 48d34fb..cc8c1dd 100644 --- a/doc/slither-report.md +++ b/doc/slither-report.md @@ -1,18 +1,35 @@ **THIS CHECKLIST IS NOT COMPLETE**. Use `--show-ignored-findings` to show all the results. Summary + - [dead-code](#dead-code) (1 results) (Informational) - [solc-version](#solc-version) (1 results) (Informational) +## dead-code + +> Acknowledge + +Impact: Informational +Confidence: Medium + + - [ ] ID-0 +[DocumentEngine._msgData()](src/DocumentEngine.sol#L265-L272) is never used and should be removed + +src/DocumentEngine.sol#L265-L272 + ## solc-version + +> Acknowledge + Impact: Informational Confidence: High - - [ ] ID-0 -Version constraint ^0.8.20 contains known severe issues (https://solidity.readthedocs.io/en/latest/bugs.html) + - [ ] ID-1 + Version constraint ^0.8.20 contains known severe issues (https://solidity.readthedocs.io/en/latest/bugs.html) - VerbatimInvalidDeduplication - FullInlinerNonExpressionSplitArgumentEvaluationOrder - MissingSideEffectsOnSelectorAccess. - It is used by: + It is used by: - lib/CMTAT/contracts/interfaces/engine/draft-IERC1643.sol#3 - lib/openzeppelin-contracts/contracts/access/AccessControl.sol#4 - lib/openzeppelin-contracts/contracts/access/IAccessControl.sol#4 + - lib/openzeppelin-contracts/contracts/metatx/ERC2771Context.sol#4 - lib/openzeppelin-contracts/contracts/utils/Context.sol#4 - lib/openzeppelin-contracts/contracts/utils/introspection/ERC165.sol#4 - lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol#4 diff --git a/doc/surya/surya_graph/surya_graph_DocumentEngine.sol.png b/doc/surya/surya_graph/surya_graph_DocumentEngine.sol.png index ebdee5d..ed1905f 100644 Binary files a/doc/surya/surya_graph/surya_graph_DocumentEngine.sol.png and b/doc/surya/surya_graph/surya_graph_DocumentEngine.sol.png differ diff --git a/doc/surya/surya_inheritance/surya_inheritance_DocumentEngine.sol.png b/doc/surya/surya_inheritance/surya_inheritance_DocumentEngine.sol.png index 66f6055..add3eb2 100644 Binary files a/doc/surya/surya_inheritance/surya_inheritance_DocumentEngine.sol.png and b/doc/surya/surya_inheritance/surya_inheritance_DocumentEngine.sol.png differ diff --git a/doc/surya/surya_report/surya_report_DocumentEngine.sol.md b/doc/surya/surya_report/surya_report_DocumentEngine.sol.md index 8d3efd1..69a3c95 100644 --- a/doc/surya/surya_report/surya_report_DocumentEngine.sol.md +++ b/doc/surya/surya_report/surya_report_DocumentEngine.sol.md @@ -15,8 +15,8 @@ |:----------:|:-------------------:|:----------------:|:----------------:|:---------------:| | └ | **Function Name** | **Visibility** | **Mutability** | **Modifiers** | |||||| -| **DocumentEngine** | Implementation | IERC1643, DocumentEngineInvariant, AccessControl ||| -| └ | | Public ❗️ | 🛑 |NO❗️ | +| **DocumentEngine** | Implementation | IERC1643, DocumentEngineInvariant, AccessControl, ERC2771Context ||| +| └ | | Public ❗️ | 🛑 | ERC2771Context | | └ | setDocument | Public ❗️ | 🛑 | onlyRole | | └ | removeDocument | External ❗️ | 🛑 | onlyRole | | └ | batchSetDocuments | External ❗️ | 🛑 | onlyRole | @@ -32,6 +32,9 @@ | └ | _removeDocumentName | Internal 🔒 | 🛑 | | | └ | _removeDocument | Internal 🔒 | 🛑 | | | └ | _setDocument | Internal 🔒 | 🛑 | | +| └ | _msgSender | Internal 🔒 | | | +| └ | _msgData | Internal 🔒 | | | +| └ | _contextSuffixLength | Internal 🔒 | | | ### Legend diff --git a/src/DocumentEngine.sol b/src/DocumentEngine.sol index 422493d..924994a 100644 --- a/src/DocumentEngine.sol +++ b/src/DocumentEngine.sol @@ -2,6 +2,7 @@ pragma solidity ^0.8.20; import "OZ/access/AccessControl.sol"; +import "OZ/metatx/ERC2771Context.sol"; import "CMTAT/interfaces/engine/draft-IERC1643.sol"; import "./DocumentEngineInvariant.sol"; @@ -9,18 +10,21 @@ import "./DocumentEngineInvariant.sol"; * @title DocumentEngine * @notice contract to manage documents on-chain through ERC-1643 */ -contract DocumentEngine is IERC1643, DocumentEngineInvariant, AccessControl { +contract DocumentEngine is IERC1643, DocumentEngineInvariant, AccessControl, ERC2771Context { /** * @notice * Get the current version of the smart contract */ - string public constant VERSION = "0.2.0"; + string public constant VERSION = "0.3.0"; // Mapping from contract addresses to document names to their corresponding Document structs mapping(address => mapping(bytes32 => Document)) private _documents; mapping(address => bytes32[]) private _documentNames; // Constructor to initialize the admin role - constructor(address admin) { + constructor(address admin, address forwarderIrrevocable) ERC2771Context(forwarderIrrevocable){ + if (admin == address(0)) { + revert AdminWithAddressZeroNotAllowed(); + } _grantRole(DEFAULT_ADMIN_ROLE, admin); } @@ -241,4 +245,41 @@ contract DocumentEngine is IERC1643, DocumentEngineInvariant, AccessControl { doc.lastModified = block.timestamp; emit DocumentUpdated(smartContract, name_, uri_, documentHash_); } + + + /** + * @dev This surcharge is not necessary if you do not use the MetaTxModule + */ + function _msgSender() + internal + view + override(ERC2771Context, Context) + returns (address sender) + { + return ERC2771Context._msgSender(); + } + + /** + * @dev This surcharge is not necessary if you do not use the MetaTxModule + */ + function _msgData() + internal + view + override(ERC2771Context, Context) + returns (bytes calldata) + { + return ERC2771Context._msgData(); + } + + /** + * @dev This surcharge is not necessary if you do not use the MetaTxModule + */ + function _contextSuffixLength() + internal + view + override(ERC2771Context, Context) + returns (uint256) + { + return ERC2771Context._contextSuffixLength(); + } } diff --git a/src/DocumentEngineInvariant.sol b/src/DocumentEngineInvariant.sol index 1b2d100..b3836d8 100644 --- a/src/DocumentEngineInvariant.sol +++ b/src/DocumentEngineInvariant.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.20; contract DocumentEngineInvariant { error DocumentNotFound(address smartContract, bytes32 name); error InvalidInputLength(); + error AdminWithAddressZeroNotAllowed(); event DocumentUpdated( address smartContract, diff --git a/test/DocumentEngine.t.sol b/test/DocumentEngine.t.sol index d8c9d6c..99f8b76 100644 --- a/test/DocumentEngine.t.sol +++ b/test/DocumentEngine.t.sol @@ -20,7 +20,7 @@ contract DocumentEngineTest is Test, DocumentEngineInvariant, AccessControl { address AddressZero = address(0); CMTAT_STANDALONE cmtat; function setUp() public { - documentEngine = new DocumentEngine(admin); + documentEngine = new DocumentEngine(admin, AddressZero); vm.prank(admin); documentEngine.setDocument( testContract, @@ -58,6 +58,25 @@ contract DocumentEngineTest is Test, DocumentEngineInvariant, AccessControl { ); } + /*////////////////////////////////////////////////////////////// + DEPLOYMENT + ///////////////////////////////////////*/ + + function testDeploy() public { + address forwarder = address(0x1); + documentEngine = new DocumentEngine(admin, forwarder); + + // Forwarder + assertEq(documentEngine.isTrustedForwarder(forwarder), true); + // admin + vm.expectRevert( + abi.encodeWithSelector( + AdminWithAddressZeroNotAllowed.selector + ) + ); + documentEngine = new DocumentEngine(AddressZero, forwarder); + } + /*////////////////////////////////////////////////////////////// Access control ///////////////////////////////////////*/