Skip to content

Commit 7ba821e

Browse files
committed
prettier
1 parent 5e16180 commit 7ba821e

File tree

2 files changed

+80
-57
lines changed

2 files changed

+80
-57
lines changed

src/lib/ECDSA.sol

Lines changed: 64 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ library ECDSA {
3838
assembly {
3939
result := 1
4040
let m := mload(0x40) // Cache the free memory pointer.
41-
for {} 1 {} {
41+
for {
42+
43+
} 1 {
44+
45+
} {
4246
mstore(0x00, hash)
4347
mstore(0x40, mload(add(signature, 0x20))) // `r`.
4448
if eq(mload(signature), 64) {
@@ -55,17 +59,16 @@ library ECDSA {
5559
result := 0
5660
break
5761
}
58-
result :=
59-
mload(
60-
staticcall(
61-
gas(), // Amount of gas left for the transaction.
62-
result, // Address of `ecrecover`.
63-
0x00, // Start of input.
64-
0x80, // Size of input.
65-
0x01, // Start of output.
66-
0x20 // Size of output.
67-
)
62+
result := mload(
63+
staticcall(
64+
gas(), // Amount of gas left for the transaction.
65+
result, // Address of `ecrecover`.
66+
0x00, // Start of input.
67+
0x80, // Size of input.
68+
0x01, // Start of output.
69+
0x20 // Size of output.
6870
)
71+
)
6972
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
7073
if iszero(returndatasize()) {
7174
mstore(0x00, 0x8baa579f) // `InvalidSignature()`.
@@ -83,7 +86,11 @@ library ECDSA {
8386
result := 1
8487
let m := mload(0x40) // Cache the free memory pointer.
8588
mstore(0x00, hash)
86-
for {} 1 {} {
89+
for {
90+
91+
} 1 {
92+
93+
} {
8794
if eq(signature.length, 64) {
8895
let vs := calldataload(add(signature.offset, 0x20))
8996
mstore(0x20, add(shr(255, vs), 27)) // `v`.
@@ -99,17 +106,16 @@ library ECDSA {
99106
result := 0
100107
break
101108
}
102-
result :=
103-
mload(
104-
staticcall(
105-
gas(), // Amount of gas left for the transaction.
106-
result, // Address of `ecrecover`.
107-
0x00, // Start of input.
108-
0x80, // Size of input.
109-
0x01, // Start of output.
110-
0x20 // Size of output.
111-
)
109+
result := mload(
110+
staticcall(
111+
gas(), // Amount of gas left for the transaction.
112+
result, // Address of `ecrecover`.
113+
0x00, // Start of input.
114+
0x80, // Size of input.
115+
0x01, // Start of output.
116+
0x20 // Size of output.
112117
)
118+
)
113119
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
114120
if iszero(returndatasize()) {
115121
mstore(0x00, 0x8baa579f) // `InvalidSignature()`.
@@ -130,17 +136,16 @@ library ECDSA {
130136
mstore(0x20, add(shr(255, vs), 27)) // `v`.
131137
mstore(0x40, r)
132138
mstore(0x60, shr(1, shl(1, vs))) // `s`.
133-
result :=
134-
mload(
135-
staticcall(
136-
gas(), // Amount of gas left for the transaction.
137-
1, // Address of `ecrecover`.
138-
0x00, // Start of input.
139-
0x80, // Size of input.
140-
0x01, // Start of output.
141-
0x20 // Size of output.
142-
)
139+
result := mload(
140+
staticcall(
141+
gas(), // Amount of gas left for the transaction.
142+
1, // Address of `ecrecover`.
143+
0x00, // Start of input.
144+
0x80, // Size of input.
145+
0x01, // Start of output.
146+
0x20 // Size of output.
143147
)
148+
)
144149
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
145150
if iszero(returndatasize()) {
146151
mstore(0x00, 0x8baa579f) // `InvalidSignature()`.
@@ -161,17 +166,16 @@ library ECDSA {
161166
mstore(0x20, and(v, 0xff))
162167
mstore(0x40, r)
163168
mstore(0x60, s)
164-
result :=
165-
mload(
166-
staticcall(
167-
gas(), // Amount of gas left for the transaction.
168-
1, // Address of `ecrecover`.
169-
0x00, // Start of input.
170-
0x80, // Size of input.
171-
0x01, // Start of output.
172-
0x20 // Size of output.
173-
)
169+
result := mload(
170+
staticcall(
171+
gas(), // Amount of gas left for the transaction.
172+
1, // Address of `ecrecover`.
173+
0x00, // Start of input.
174+
0x80, // Size of input.
175+
0x01, // Start of output.
176+
0x20 // Size of output.
174177
)
178+
)
175179
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
176180
if iszero(returndatasize()) {
177181
mstore(0x00, 0x8baa579f) // `InvalidSignature()`.
@@ -198,7 +202,11 @@ library ECDSA {
198202
assembly {
199203
result := 1
200204
let m := mload(0x40) // Cache the free memory pointer.
201-
for {} 1 {} {
205+
for {
206+
207+
} 1 {
208+
209+
} {
202210
mstore(0x00, hash)
203211
mstore(0x40, mload(add(signature, 0x20))) // `r`.
204212
if eq(mload(signature), 64) {
@@ -239,7 +247,11 @@ library ECDSA {
239247
result := 1
240248
let m := mload(0x40) // Cache the free memory pointer.
241249
mstore(0x00, hash)
242-
for {} 1 {} {
250+
for {
251+
252+
} 1 {
253+
254+
} {
243255
if eq(signature.length, 64) {
244256
let vs := calldataload(add(signature.offset, 0x20))
245257
mstore(0x20, add(shr(255, vs), 27)) // `v`.
@@ -356,11 +368,17 @@ library ECDSA {
356368
mstore(o, "\x19Ethereum Signed Message:\n") // 26 bytes, zero-right-padded.
357369
mstore(0x00, 0x00)
358370
// Convert the `s.length` to ASCII decimal representation: `base10(s.length)`.
359-
for { let temp := sLength } 1 {} {
371+
for {
372+
let temp := sLength
373+
} 1 {
374+
375+
} {
360376
o := sub(o, 1)
361377
mstore8(o, add(48, mod(temp, 10)))
362378
temp := div(temp, 10)
363-
if iszero(temp) { break }
379+
if iszero(temp) {
380+
break
381+
}
364382
}
365383
let n := sub(0x3a, o) // Header length: `26 + 32 - o`.
366384
// Throw an out-of-offset error (consumes all gas) if the header exceeds 32 bytes.

src/lib/SafeTransferLib.sol

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ library SafeTransferLib {
9595
mstore(0x00, to) // Store the address in scratch space.
9696
mstore8(0x0b, 0x73) // Opcode `PUSH20`.
9797
mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
98-
if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
98+
if iszero(create(amount, 0x0b, 0x16)) {
99+
revert(codesize(), codesize())
100+
} // For gas estimation.
99101
}
100102
}
101103
}
@@ -108,7 +110,9 @@ library SafeTransferLib {
108110
mstore(0x00, to) // Store the address in scratch space.
109111
mstore8(0x0b, 0x73) // Opcode `PUSH20`.
110112
mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
111-
if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
113+
if iszero(create(selfbalance(), 0x0b, 0x16)) {
114+
revert(codesize(), codesize())
115+
} // For gas estimation.
112116
}
113117
}
114118
}
@@ -125,7 +129,9 @@ library SafeTransferLib {
125129
mstore(0x00, to) // Store the address in scratch space.
126130
mstore8(0x0b, 0x73) // Opcode `PUSH20`.
127131
mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
128-
if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
132+
if iszero(create(amount, 0x0b, 0x16)) {
133+
revert(codesize(), codesize())
134+
} // For gas estimation.
129135
}
130136
}
131137
}
@@ -362,15 +368,14 @@ library SafeTransferLib {
362368
assembly {
363369
mstore(0x14, account) // Store the `account` argument.
364370
mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
365-
amount :=
366-
mul(
367-
mload(0x20),
368-
and(
369-
// The arguments of `and` are evaluated from right to left.
370-
gt(returndatasize(), 0x1f), // At least 32 bytes returned.
371-
staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20)
372-
)
371+
amount := mul(
372+
mload(0x20),
373+
and(
374+
// The arguments of `and` are evaluated from right to left.
375+
gt(returndatasize(), 0x1f), // At least 32 bytes returned.
376+
staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20)
373377
)
378+
)
374379
}
375380
}
376381
}

0 commit comments

Comments
 (0)