@bananapus/721-hook-v6 0.0.35 → 0.0.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/ADMINISTRATION.md +49 -163
  2. package/ARCHITECTURE.md +71 -49
  3. package/AUDIT_INSTRUCTIONS.md +47 -84
  4. package/README.md +40 -28
  5. package/RISKS.md +85 -86
  6. package/SKILLS.md +17 -16
  7. package/USER_JOURNEYS.md +85 -62
  8. package/foundry.toml +2 -0
  9. package/package.json +1 -1
  10. package/references/operations.md +7 -3
  11. package/references/runtime.md +5 -4
  12. package/src/JB721CheckpointsDeployer.sol +2 -0
  13. package/src/JB721TiersHook.sol +0 -2
  14. package/src/JB721TiersHookProjectDeployer.sol +0 -1
  15. package/src/JB721TiersHookStore.sol +1 -2
  16. package/src/abstract/JB721Hook.sol +0 -1
  17. package/src/interfaces/IJB721CheckpointsDeployer.sol +3 -0
  18. package/src/interfaces/IJB721TiersHook.sol +0 -2
  19. package/src/interfaces/IJB721TiersHookStore.sol +1 -1
  20. package/src/libraries/JB721Constants.sol +0 -1
  21. package/src/structs/JB721InitTiersConfig.sol +0 -1
  22. package/src/structs/JB721Tier.sol +0 -2
  23. package/src/structs/JB721TierConfig.sol +0 -2
  24. package/src/structs/JB721TierConfigFlags.sol +0 -1
  25. package/src/structs/JB721TierFlags.sol +0 -1
  26. package/src/structs/JB721TiersHookFlags.sol +0 -1
  27. package/src/structs/JB721TiersMintReservesConfig.sol +0 -1
  28. package/src/structs/JB721TiersRulesetMetadata.sol +0 -1
  29. package/src/structs/JB721TiersSetDiscountPercentConfig.sol +0 -1
  30. package/src/structs/JBBitmapWord.sol +0 -1
  31. package/src/structs/JBDeploy721TiersHookConfig.sol +0 -1
  32. package/src/structs/JBLaunchProjectConfig.sol +0 -1
  33. package/src/structs/JBLaunchRulesetsConfig.sol +0 -1
  34. package/src/structs/JBPayDataHookRulesetConfig.sol +0 -1
  35. package/src/structs/JBPayDataHookRulesetMetadata.sol +0 -1
  36. package/src/structs/JBQueueRulesetsConfig.sol +0 -1
  37. package/src/structs/JBStored721Tier.sol +0 -1
  38. package/test/unit/JB721CheckpointsDeployer_AccessControl.t.sol +116 -0
@@ -0,0 +1,116 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity 0.8.28;
3
+
4
+ import {Test} from "forge-std/Test.sol";
5
+ import {JB721CheckpointsDeployer} from "../../src/JB721CheckpointsDeployer.sol";
6
+ import {IJB721CheckpointsDeployer} from "../../src/interfaces/IJB721CheckpointsDeployer.sol";
7
+ import {IJB721Checkpoints} from "../../src/interfaces/IJB721Checkpoints.sol";
8
+ import {IJB721TiersHookStore} from "../../src/interfaces/IJB721TiersHookStore.sol";
9
+
10
+ /// @notice H-1 audit fix: access control tests for JB721CheckpointsDeployer.deploy().
11
+ /// @dev The deployer must only allow the hook address itself (msg.sender == hook) to call deploy().
12
+ contract Test_JB721CheckpointsDeployer_AccessControl is Test {
13
+ JB721CheckpointsDeployer deployer;
14
+ address mockStore;
15
+
16
+ function setUp() public {
17
+ deployer = new JB721CheckpointsDeployer();
18
+ mockStore = makeAddr("mockStore");
19
+ vm.etch(mockStore, new bytes(0x69));
20
+ }
21
+
22
+ // ═══════════════════════════════════════════════════════════
23
+ // Test 1: Calling deploy() from the hook address succeeds
24
+ // ═══════════════════════════════════════════════════════════
25
+
26
+ /// @notice deploy() succeeds when msg.sender == hook parameter.
27
+ function test_deploy_succeedsWhenCallerIsHook() public {
28
+ address hookAddr = makeAddr("hook");
29
+
30
+ // Call deploy from the hook address, passing itself as the hook parameter.
31
+ vm.prank(hookAddr);
32
+ IJB721Checkpoints module = deployer.deploy(hookAddr, IJB721TiersHookStore(mockStore));
33
+
34
+ // Verify the module was deployed (non-zero address).
35
+ assertTrue(address(module) != address(0), "Module should be deployed");
36
+ }
37
+
38
+ // ═══════════════════════════════════════════════════════════
39
+ // Test 2: Calling deploy() from any other address reverts
40
+ // ═══════════════════════════════════════════════════════════
41
+
42
+ /// @notice deploy() reverts with Unauthorized when msg.sender != hook.
43
+ function test_deploy_revertsWhenCallerIsNotHook() public {
44
+ address hookAddr = makeAddr("hook");
45
+ address attacker = makeAddr("attacker");
46
+
47
+ vm.prank(attacker);
48
+ vm.expectRevert(IJB721CheckpointsDeployer.JB721CheckpointsDeployer_Unauthorized.selector);
49
+ deployer.deploy(hookAddr, IJB721TiersHookStore(mockStore));
50
+ }
51
+
52
+ /// @notice deploy() reverts when caller passes their own address as hook but is not the actual hook.
53
+ function test_deploy_revertsWhenCallerPassesSelfButIsNotHook() public {
54
+ address attacker = makeAddr("attacker");
55
+ address realHook = makeAddr("realHook");
56
+
57
+ // Attacker tries to pass realHook as the hook parameter but calls from their own address.
58
+ vm.prank(attacker);
59
+ vm.expectRevert(IJB721CheckpointsDeployer.JB721CheckpointsDeployer_Unauthorized.selector);
60
+ deployer.deploy(realHook, IJB721TiersHookStore(mockStore));
61
+ }
62
+
63
+ // ═══════════════════════════════════════════════════════════
64
+ // Test 3: Front-running scenario
65
+ // ═══════════════════════════════════════════════════════════
66
+
67
+ /// @notice An attacker cannot front-run the hook by calling deploy() with the hook's address.
68
+ /// Since msg.sender must equal hook, the attacker's tx reverts.
69
+ function test_deploy_frontRunningRevertsForAttacker() public {
70
+ address hookAddr = makeAddr("hook");
71
+ address frontRunner = makeAddr("frontRunner");
72
+
73
+ // Front-runner attempts to call deploy with the hook's address before the hook does.
74
+ vm.prank(frontRunner);
75
+ vm.expectRevert(IJB721CheckpointsDeployer.JB721CheckpointsDeployer_Unauthorized.selector);
76
+ deployer.deploy(hookAddr, IJB721TiersHookStore(mockStore));
77
+
78
+ // The legitimate hook can still deploy successfully after the failed front-run attempt.
79
+ vm.prank(hookAddr);
80
+ IJB721Checkpoints module = deployer.deploy(hookAddr, IJB721TiersHookStore(mockStore));
81
+ assertTrue(address(module) != address(0), "Hook should deploy successfully after failed front-run");
82
+ }
83
+
84
+ /// @notice An attacker who calls deploy(attacker, store) from their own address gets a clone
85
+ /// for themselves, but this does NOT affect the real hook's future deployment.
86
+ function test_deploy_attackerDeploysOwnClone_doesNotAffectRealHook() public {
87
+ address hookAddr = makeAddr("hook");
88
+ address attacker = makeAddr("attacker");
89
+
90
+ // Attacker deploys their own clone (msg.sender == attacker == hook param).
91
+ // This succeeds because msg.sender == hook parameter.
92
+ vm.prank(attacker);
93
+ IJB721Checkpoints attackerModule = deployer.deploy(attacker, IJB721TiersHookStore(mockStore));
94
+ assertTrue(address(attackerModule) != address(0), "Attacker can deploy their own clone");
95
+
96
+ // The real hook can still deploy its own clone (different salt = different CREATE2 address).
97
+ vm.prank(hookAddr);
98
+ IJB721Checkpoints hookModule = deployer.deploy(hookAddr, IJB721TiersHookStore(mockStore));
99
+ assertTrue(address(hookModule) != address(0), "Real hook can still deploy its own clone");
100
+
101
+ // The two clones are at different addresses.
102
+ assertTrue(
103
+ address(attackerModule) != address(hookModule),
104
+ "Attacker clone and hook clone should be different addresses"
105
+ );
106
+ }
107
+
108
+ /// @notice Fuzz: any random caller that is not the hook reverts.
109
+ function testFuzz_deploy_revertsForArbitraryCaller(address caller, address hookAddr) public {
110
+ vm.assume(caller != hookAddr);
111
+
112
+ vm.prank(caller);
113
+ vm.expectRevert(IJB721CheckpointsDeployer.JB721CheckpointsDeployer_Unauthorized.selector);
114
+ deployer.deploy(hookAddr, IJB721TiersHookStore(mockStore));
115
+ }
116
+ }