From 653aa85bec4c989c5533781cf39fe0c35201b88c Mon Sep 17 00:00:00 2001 From: zuies Date: Mon, 17 Jun 2024 12:45:29 +0300 Subject: [PATCH 1/4] fix scanner reports --- contracts/Engagement.sol | 18 +++++++++++------- contracts/IEngagement.sol | 3 ++- hardhat.config.ts | 6 ++++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/contracts/Engagement.sol b/contracts/Engagement.sol index f2d4461..72f9986 100644 --- a/contracts/Engagement.sol +++ b/contracts/Engagement.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.24; +pragma solidity 0.8.26; import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; import "@openzeppelin/contracts/access/AccessControl.sol"; @@ -10,8 +10,8 @@ contract Engagement is IEngagement, ERC1155, AccessControl { uint private _counter; bytes32 public constant PROVIDER_ROLE = keccak256("PROVIDER_ROLE"); - mapping(uint => string) private _tokenMetadata; - mapping(uint => string) private _scores; + mapping(uint tokenId => string metadata) private _tokenMetadata; + mapping(uint date => string cid) private _scores; constructor() ERC1155("") { _grantRole(DEFAULT_ADMIN_ROLE, msg.sender); @@ -28,6 +28,13 @@ contract Engagement is IEngagement, ERC1155, AccessControl { _; } + modifier onlyTokenOwner(address account, uint tokenId) { + if (account != msg.sender) { + revert NotAllowed(account, tokenId); + } + _; + } + function counter() external view returns (uint) { return _counter; } @@ -57,10 +64,7 @@ contract Engagement is IEngagement, ERC1155, AccessControl { address account, uint tokenId, uint amount - ) external override validTokenId(tokenId) { - if (account != msg.sender) { - revert NotAllowed(account, tokenId); - } + ) external override validTokenId(tokenId) onlyTokenOwner(account, tokenId) { _burn(account, tokenId, 1); emit Burn(account, tokenId, 1); } diff --git a/contracts/IEngagement.sol b/contracts/IEngagement.sol index c159b21..0aa4a38 100644 --- a/contracts/IEngagement.sol +++ b/contracts/IEngagement.sol @@ -1,4 +1,5 @@ -pragma solidity ^0.8.24; +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.8.26; interface IEngagement { event Issue(address indexed account, uint indexed tokenId); diff --git a/hardhat.config.ts b/hardhat.config.ts index 3e698fe..5015193 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -3,11 +3,13 @@ import "@nomicfoundation/hardhat-toolbox-viem"; import { vars } from "hardhat/config"; const ALCHEMY_SEPOLIA_ENDPOINT = vars.get("ALCHEMY_SEPOLIA_ENDPOINT", ""); -const PRIVATE_KEYS = vars.has("PRIVATE_KEYS") ? vars.get("PRIVATE_KEYS").split(", ") : []; +const PRIVATE_KEYS = vars.has("PRIVATE_KEYS") + ? vars.get("PRIVATE_KEYS").split(", ") + : []; const ETHERSCAN_API_KEY = vars.get("ETHERSCAN_API_KEY", ""); const config: HardhatUserConfig = { - solidity: "0.8.24", + solidity: "0.8.26", networks: { sepolia: { url: ALCHEMY_SEPOLIA_ENDPOINT, From 66f37d8988a20c33d11cb35d11d184d4f04cefa0 Mon Sep 17 00:00:00 2001 From: zuies Date: Mon, 17 Jun 2024 13:00:33 +0300 Subject: [PATCH 2/4] fix supportsInterface --- contracts/Engagement.sol | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contracts/Engagement.sol b/contracts/Engagement.sol index 72f9986..1bddcf1 100644 --- a/contracts/Engagement.sol +++ b/contracts/Engagement.sol @@ -99,7 +99,9 @@ contract Engagement is IEngagement, ERC1155, AccessControl { function supportsInterface( bytes4 interfaceId ) public view override(AccessControl, ERC1155) returns (bool) { - return super.supportsInterface(interfaceId); + return + interfaceId == type(IEngagement).interfaceId || + super.supportsInterface(interfaceId); } function uri( From 8080ecedfb1a2fecb495697cb3e4f46a497bbbe8 Mon Sep 17 00:00:00 2001 From: zuies Date: Mon, 17 Jun 2024 13:02:56 +0300 Subject: [PATCH 3/4] revert supportsInterface changes --- contracts/Engagement.sol | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/contracts/Engagement.sol b/contracts/Engagement.sol index 1bddcf1..72f9986 100644 --- a/contracts/Engagement.sol +++ b/contracts/Engagement.sol @@ -99,9 +99,7 @@ contract Engagement is IEngagement, ERC1155, AccessControl { function supportsInterface( bytes4 interfaceId ) public view override(AccessControl, ERC1155) returns (bool) { - return - interfaceId == type(IEngagement).interfaceId || - super.supportsInterface(interfaceId); + return super.supportsInterface(interfaceId); } function uri( From 023074d5d1ff874701014ec891539cfde48823a5 Mon Sep 17 00:00:00 2001 From: zuies Date: Mon, 17 Jun 2024 14:24:20 +0300 Subject: [PATCH 4/4] add ERC165Checker for supportsInterface --- contracts/Engagement.sol | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/contracts/Engagement.sol b/contracts/Engagement.sol index 72f9986..5b13682 100644 --- a/contracts/Engagement.sol +++ b/contracts/Engagement.sol @@ -4,9 +4,12 @@ pragma solidity 0.8.26; import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; import "@openzeppelin/contracts/access/AccessControl.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; +import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol"; import "./IEngagement.sol"; contract Engagement is IEngagement, ERC1155, AccessControl { + using ERC165Checker for address; + uint private _counter; bytes32 public constant PROVIDER_ROLE = keccak256("PROVIDER_ROLE"); @@ -99,7 +102,10 @@ contract Engagement is IEngagement, ERC1155, AccessControl { function supportsInterface( bytes4 interfaceId ) public view override(AccessControl, ERC1155) returns (bool) { - return super.supportsInterface(interfaceId); + if (address(this).supportsERC165()) { + return super.supportsInterface(interfaceId); + } + return false; } function uri(