Skip to content

Commit 0f97b01

Browse files
authored
♻️ Tidy (#1473)
1 parent 8875f52 commit 0f97b01

File tree

7 files changed

+74
-32
lines changed

7 files changed

+74
-32
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ tokens
6262
utils
6363
├─ Base58 — "Library for Base58 encoding and decoding"
6464
├─ Base64 — "Library for Base64 encoding and decoding"
65+
├─ BlockHashLib — "Library for accessing block hashes way beyond the 256-block limit"
6566
├─ CallContextChecker — "Call context checker mixin"
6667
├─ CREATE3 — "Deterministic deployments agnostic to the initialization code"
6768
├─ DateTimeLib — "Library for date time operations"

docs/utils/blockhashlib.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# BlockHashLib
2+
3+
Library for accessing block hashes way beyond the 256-block limit.
4+
5+
6+
7+
8+
9+
10+
<!-- customintro:start --><!-- customintro:end -->
11+
12+
## Constants
13+
14+
### HISTORY_STORAGE_ADDRESS
15+
16+
```solidity
17+
address internal constant HISTORY_STORAGE_ADDRESS =
18+
0x0000F90827F1C53a10cb7A02335B175320002935
19+
```
20+
21+
Address of the EIP-2935 history storage contract.
22+
See: https://eips.ethereum.org/EIPS/eip-2935
23+
24+
## Operations
25+
26+
### blockHash(uint256)
27+
28+
```solidity
29+
function blockHash(uint256 blockNumber)
30+
internal
31+
view
32+
returns (bytes32 result)
33+
```
34+
35+
Retrieves the block hash for any historical block within the supported range.
36+
The function gracefully handles future blocks and blocks beyond the history window by returning zero,
37+
consistent with the EVM's native `BLOCKHASH` behavior.

docs/utils/libbit.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ function commonBytePrefix(uint256 x, uint256 y)
140140

141141
Returns the common prefix of `x` and `y` at the byte level.
142142

143+
### toNibbles(bytes)
144+
145+
```solidity
146+
function toNibbles(bytes memory s)
147+
internal
148+
pure
149+
returns (bytes memory result)
150+
```
151+
152+
hex"ABCD" -> hex"0A0B0C0D".
153+
143154
## Boolean Operations
144155

145156
A Solidity bool on the stack or memory is represented as a 256-bit word.

docs/utils/safetransferlib.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ The canonical Permit2 address.
132132
[Github](https://github.com/Uniswap/permit2)
133133
[Etherscan](https://etherscan.io/address/0x000000000022D473030F116dDEE9F6B43aC78BA3)
134134

135+
### ETH_MOVER
136+
137+
```solidity
138+
address internal constant ETH_MOVER =
139+
0x00000000000073c48c8055bD43D1A53799176f0D
140+
```
141+
142+
The canonical address of the `SELFDESTRUCT` ETH mover.
143+
See: https://gist.github.com/Vectorized/1cb8ad4cf393b1378e08f23f79bd99fa
144+
[Etherscan](https://etherscan.io/address/0x00000000000073c48c8055bD43D1A53799176f0D)
145+
135146
## ETH Operations
136147

137148
If the ETH transfer MUST succeed with a reasonable gas budget, use the force variants.
@@ -222,6 +233,18 @@ function trySafeTransferAllETH(address to, uint256 gasStipend)
222233

223234
Sends all the ETH in the current contract to `to`, with a `gasStipend`.
224235

236+
### safeMoveETH(address,uint256)
237+
238+
```solidity
239+
function safeMoveETH(address to, uint256 amount)
240+
internal
241+
returns (address vault)
242+
```
243+
244+
Force transfers ETH to `to`, without triggering the fallback (if any).
245+
This method attempts to use a separate contract to send via `SELFDESTRUCT`,
246+
and upon failure, deploys a minimal vault to accrue the ETH.
247+
225248
## ERC20 Operations
226249

227250
### safeTransferFrom(address,address,address,uint256)

src/Milady.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import "./tokens/ERC721.sol";
2525
import "./tokens/WETH.sol";
2626
import "./utils/Base58.sol";
2727
import "./utils/Base64.sol";
28+
import "./utils/BlockHashLib.sol";
2829
import "./utils/CREATE3.sol";
2930
import "./utils/CallContextChecker.sol";
3031
import "./utils/DateTimeLib.sol";

src/utils/BlockHashLib.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.4;
33

4-
/// @notice Library for accessing block hashes way beyond the 256-block limit. ref: EIP-2935
4+
/// @notice Library for accessing block hashes way beyond the 256-block limit.
55
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/BlockHashLib.sol)
66
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Blockhash.sol)
77
library BlockHashLib {

test/SafeTransferLib.t.sol

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,35 +1277,4 @@ contract SafeTransferLibTest is SoladyTest {
12771277
assertEq(mover.code, hex"3d35ff");
12781278
assertEq(mover, SafeTransferLib.ETH_MOVER);
12791279
}
1280-
1281-
function _deployOneTimeVault(address to, uint256 amount) internal returns (address vault) {
1282-
/// @solidity memory-safe-assembly
1283-
assembly {
1284-
to := shr(96, shl(96, to)) // Clean upper 96 bits.
1285-
for {} 1 {} {
1286-
let m := mload(0x40)
1287-
// If the mover is missing or bricked, deploy a minimal accrual contract
1288-
// that withdraws all ETH to `to` when being called only by `to`.
1289-
mstore(
1290-
add(m, 0x1f), 0x33146025575b600160005260206000f35b3d3d3d3d47335af1601a573d3dfd
1291-
)
1292-
mstore(m, or(to, shl(160, 0x6034600b3d3960343df3fe73)))
1293-
// Compute and store the bytecode hash.
1294-
mstore8(0x00, 0xff) // Write the prefix.
1295-
mstore(0x35, keccak256(m, 0x3f))
1296-
mstore(0x01, shl(96, address())) // Deployer.
1297-
mstore(0x15, 0) // Salt.
1298-
vault := keccak256(0x00, 0x55)
1299-
if iszero(
1300-
mul(
1301-
returndatasize(),
1302-
call(gas(), vault, amount, codesize(), 0x00, codesize(), 0x00)
1303-
)
1304-
) { if iszero(create2(0, m, 0x3f, 0)) { revert(codesize(), codesize()) } } // For gas estimation.
1305-
1306-
mstore(0x40, m)
1307-
break
1308-
}
1309-
}
1310-
}
13111280
}

0 commit comments

Comments
 (0)