generated from ScopeLift/foundry-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ERC5564Announcer contract and tests (#2)
See [ERC-5564](https://eips.ethereum.org/EIPS/eip-5564) for the spec. The contract is super simple so we really only have one test, if you have ideas for more tests let me know. This PR also turns off the metadata hash, that way the resulting bytecode is independent of the machine it's compiled on.
- Loading branch information
Showing
8 changed files
with
117 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
[profile.default] | ||
bytecode_hash = "none" | ||
evm_version = "paris" | ||
optimizer = true | ||
optimizer_runs = 10_000_000 | ||
|
Submodule forge-std
updated
27 files
+48 −6 | .github/workflows/ci.yml | |
+29 −0 | .github/workflows/sync.yml | |
+1 −1 | foundry.toml | |
+1 −1 | lib/ds-test | |
+2 −2 | package.json | |
+7 −3 | src/Base.sol | |
+3 −2 | src/Script.sol | |
+191 −24 | src/StdAssertions.sol | |
+89 −49 | src/StdChains.sol | |
+274 −34 | src/StdCheats.sol | |
+92 −0 | src/StdInvariant.sol | |
+28 −28 | src/StdJson.sol | |
+5 −1 | src/StdStorage.sol | |
+333 −0 | src/StdStyle.sol | |
+83 −8 | src/StdUtils.sol | |
+8 −2 | src/Test.sol | |
+140 −11 | src/Vm.sol | |
+394 −382 | src/console2.sol | |
+73 −0 | src/interfaces/IMulticall3.sol | |
+13,248 −0 | src/safeconsole.sol | |
+412 −0 | test/StdAssertions.t.sol | |
+131 −39 | test/StdChains.t.sol | |
+302 −5 | test/StdCheats.t.sol | |
+17 −2 | test/StdMath.t.sol | |
+10 −0 | test/StdStorage.t.sol | |
+110 −0 | test/StdStyle.t.sol | |
+168 −17 | test/StdUtils.t.sol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.20; | ||
|
||
import {IERC5564Announcer} from "./interfaces/IERC5564Announcer.sol"; | ||
|
||
/// @dev `ERC5564Announcer` contract to emit an `Announcement` event to broadcast information about | ||
/// a transaction involving a stealth address. See | ||
/// [ERC-5564](https://eips.ethereum.org/EIPS/eip-5564) to learn more. | ||
contract ERC5564Announcer is IERC5564Announcer { | ||
/// @inheritdoc IERC5564Announcer | ||
function announce( | ||
uint256 schemeId, | ||
address stealthAddress, | ||
bytes memory ephemeralPubKey, | ||
bytes memory metadata | ||
) external { | ||
emit Announcement(schemeId, stealthAddress, msg.sender, ephemeralPubKey, metadata); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
/// @dev Interface for calling the `ERC5564Announcer` contract, which emits an `Announcement` event | ||
/// to broadcast information about a transaction involving a stealth address. See | ||
/// [ERC-5564](https://eips.ethereum.org/EIPS/eip-5564) to learn more. | ||
interface IERC5564Announcer { | ||
/// @dev Emitted when something is sent to a stealth address. | ||
/// @param schemeId Identifier corresponding to the applied stealth address scheme, e.g. 0 for | ||
/// secp256k1, as specified in ERC-5564. | ||
/// @param stealthAddress The computed stealth address for the recipient. | ||
/// @param caller The caller of the `announce` function that emitted this event. | ||
/// @param ephemeralPubKey Ephemeral public key used by the sender to derive the `stealthAddress`. | ||
/// @param metadata Arbitrary data to emit with the event. The first byte MUST be the view tag. | ||
/// The remaining metadata can be used by the senders however they like. See | ||
/// [ERC-5564](https://eips.ethereum.org/EIPS/eip-5564) for recommendations on how to structure | ||
/// this metadata. | ||
event Announcement( | ||
uint256 indexed schemeId, | ||
address indexed stealthAddress, | ||
address indexed caller, | ||
bytes ephemeralPubKey, | ||
bytes metadata | ||
); | ||
|
||
/// @dev Called by integrators to emit an `Announcement` event. | ||
/// @param schemeId The applied stealth address scheme (such as secp25k1). | ||
/// @param stealthAddress The computed stealth address for the recipient. | ||
/// @param ephemeralPubKey Ephemeral public key used by the sender. | ||
/// @param metadata Arbitrary data to emit with the event. The first byte MUST be the view tag. | ||
/// The remaining metadata can be used by the senders however they like. See | ||
/// [ERC-5564](https://eips.ethereum.org/EIPS/eip-5564) for recommendations on how to structure | ||
/// this metadata. | ||
function announce( | ||
uint256 schemeId, | ||
address stealthAddress, | ||
bytes memory ephemeralPubKey, | ||
bytes memory metadata | ||
) external; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.20; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
import {Deploy} from "script/Deploy.s.sol"; | ||
|
||
contract ERC5564AnnouncerTest is Test, Deploy { | ||
event Announcement( | ||
uint256 indexed schemeId, | ||
address indexed stealthAddress, | ||
address indexed caller, | ||
bytes ephemeralPubKey, | ||
bytes metadata | ||
); | ||
|
||
function setUp() public { | ||
Deploy.run(); | ||
} | ||
} | ||
|
||
contract Announce is ERC5564AnnouncerTest { | ||
function testFuzz_EmitsAnnouncementEvent( | ||
uint256 schemeId, | ||
address stealthAddress, | ||
address caller, | ||
bytes memory ephemeralPubKey, | ||
bytes memory metadata | ||
) external { | ||
vm.prank(caller); | ||
vm.expectEmit(); | ||
emit Announcement(schemeId, stealthAddress, caller, ephemeralPubKey, metadata); | ||
announcer.announce(schemeId, stealthAddress, ephemeralPubKey, metadata); | ||
} | ||
|
||
// This test is a subset of `testFuzz_EmitsAnnouncementEvent`, and is mainly present to make | ||
// the `announce` method's specification more explicit. For this reason, we set the number of runs | ||
// to 1 for all profiles. | ||
/// forge-config: default.fuzz.runs = 1 | ||
/// forge-config: ci.fuzz.runs = 1 | ||
/// forge-config: lite.fuzz.runs = 1 | ||
function testFuzz_NeverReverts( | ||
uint256 schemeId, | ||
address stealthAddress, | ||
address caller, | ||
bytes memory ephemeralPubKey, | ||
bytes memory metadata | ||
) external { | ||
vm.prank(caller); | ||
announcer.announce(schemeId, stealthAddress, ephemeralPubKey, metadata); | ||
} | ||
} |