Skip to content

Commit

Permalink
Add support meta tx transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
rya-sge committed Sep 9, 2024
1 parent 28f31a4 commit 65105e6
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 9 deletions.
23 changes: 20 additions & 3 deletions doc/slither-report.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Binary file modified doc/surya/surya_graph/surya_graph_DocumentEngine.sol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions doc/surya/surya_report/surya_report_DocumentEngine.sol.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
|:----------:|:-------------------:|:----------------:|:----------------:|:---------------:|
|| **Function Name** | **Visibility** | **Mutability** | **Modifiers** |
||||||
| **DocumentEngine** | Implementation | IERC1643, DocumentEngineInvariant, AccessControl |||
|| <Constructor> | Public ❗️ | 🛑 |NO❗️ |
| **DocumentEngine** | Implementation | IERC1643, DocumentEngineInvariant, AccessControl, ERC2771Context |||
|| <Constructor> | Public ❗️ | 🛑 | ERC2771Context |
|| setDocument | Public ❗️ | 🛑 | onlyRole |
|| removeDocument | External ❗️ | 🛑 | onlyRole |
|| batchSetDocuments | External ❗️ | 🛑 | onlyRole |
Expand All @@ -32,6 +32,9 @@
|| _removeDocumentName | Internal 🔒 | 🛑 | |
|| _removeDocument | Internal 🔒 | 🛑 | |
|| _setDocument | Internal 🔒 | 🛑 | |
|| _msgSender | Internal 🔒 | | |
|| _msgData | Internal 🔒 | | |
|| _contextSuffixLength | Internal 🔒 | | |


### Legend
Expand Down
47 changes: 44 additions & 3 deletions src/DocumentEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@
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";

/**
* @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);
}

Expand Down Expand Up @@ -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();
}
}
1 change: 1 addition & 0 deletions src/DocumentEngineInvariant.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 20 additions & 1 deletion test/DocumentEngine.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
///////////////////////////////////////*/
Expand Down

0 comments on commit 65105e6

Please sign in to comment.