From a4ba28ec19a2c2f7082347717d4196a384397468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wei=C3=9Fer=20Hase?= Date: Fri, 5 Jul 2024 14:35:06 +0200 Subject: [PATCH] test: halmos stress test --- .gitignore | 1 + package.json | 2 +- src/contracts/Greeter.sol | 11 +++++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 9209344d..af411073 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ yarn-error.log node_modules .DS_STORE .vscode +.python-version # Foundry files cache diff --git a/package.json b/package.json index 246c5dd1..0ae14e9c 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "lint:sol-tests": "solhint -c .solhint.tests.json 'test/**/*.sol'", "prepare": "husky install", "test": "forge test -vvv", - "test:fuzz": "echidna test/invariants/fuzz/Greeter.t.sol --contract GreeterInvariant --corpus-dir test/invariants/fuzz/echidna_coverage/ --test-mode assertion", + "test:fuzz": "echidna test/invariants/fuzz/Greeter.t.sol --contract InvariantGreeter --corpus-dir test/invariants/fuzz/echidna_coverage/ --test-mode assertion", "test:integration": "forge test --match-contract Integration -vvv", "test:symbolic": "halmos", "test:unit": "forge test --match-contract Unit -vvv", diff --git a/src/contracts/Greeter.sol b/src/contracts/Greeter.sol index 7167b5c7..56910e01 100644 --- a/src/contracts/Greeter.sol +++ b/src/contracts/Greeter.sol @@ -6,11 +6,17 @@ import {IGreeter} from 'interfaces/IGreeter.sol'; contract Greeter is IGreeter { /** - * @notice Empty string for revert checks + * @notice Empty string signature for revert checks * @dev result of doing keccak256(bytes('')) */ bytes32 internal constant _EMPTY_STRING = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; + /** + * @notice Forbidden string signature for revert checks + * @dev result of doing keccak256(bytes('SECRET_STRING')) + */ + bytes32 internal constant _FORBIDDEN_STRING = 0x8c917c6c6ed13e2a7bc9a85e333804f00ef06bf49d17d1140551e128758a022c; + /// @inheritdoc IGreeter address public immutable OWNER; @@ -49,7 +55,8 @@ contract Greeter is IGreeter { /// @inheritdoc IGreeter function setGreeting(string memory _greeting) public onlyOwner { - if (keccak256(bytes(_greeting)) == _EMPTY_STRING) { + bytes32 _greetingHash = keccak256(bytes(_greeting)); + if (_greetingHash == _EMPTY_STRING || _greetingHash == _FORBIDDEN_STRING) { revert Greeter_InvalidGreeting(); }