diff --git a/.gas-snapshot b/.gas-snapshot index ca2019e..1207b64 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,5 +1,5 @@ -LibTransientTest:testTransientSetAndGet(bytes32,uint256) (runs: 256, μ: 700, ~: 700) -LibTransientTest:test__codesize() (gas: 1779) +LibTTest:testLibT(bytes32,uint256) (runs: 256, μ: 700, ~: 700) +LibTTest:test__codesize() (gas: 1779) ReentrancyGuardTest:testRecursiveDirectUnguardedCall() (gas: 32203) ReentrancyGuardTest:testRecursiveIndirectUnguardedCall() (gas: 45600) ReentrancyGuardTest:testRevertGuardLocked() (gas: 31984) diff --git a/README.md b/README.md index e334d59..55bb518 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ The Solidity smart contracts are located in the `src` directory. ```ml utils -├─ LibTransient — "Transient storage get/set helper" +├─ LibT — "Transient storage helper" └─ ReentrancyGuard — "Reentrancy guard mixin" ``` diff --git a/src/utils/LibTransient.sol b/src/utils/LibT.sol similarity index 67% rename from src/utils/LibTransient.sol rename to src/utils/LibT.sol index 26c25c7..1395f2c 100644 --- a/src/utils/LibTransient.sol +++ b/src/utils/LibT.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.24; -/// @notice Transient storage get/set helper. -/// @author Soledge (https://github.com/vectorized/soledge/blob/main/src/utils/LibTransient.sol) -library LibTransient { +/// @notice Transient storage helper. +/// @author Soledge (https://github.com/vectorized/soledge/blob/main/src/utils/LibT.sol) +library LibT { /// @dev Returns the value at `tSlot` in transient storage. function get(bytes32 tSlot) internal view returns (bytes32 result) { /// @solidity memory-safe-assembly @@ -19,4 +19,12 @@ library LibTransient { tstore(tSlot, value) } } + + /// @dev Resets the value at `tSlot` in transient storage to zero. + function reset(bytes32 tSlot) internal { + /// @solidity memory-safe-assembly + assembly { + tstore(tSlot, 0) + } + } } diff --git a/test/LibT.sol b/test/LibT.sol new file mode 100644 index 0000000..ac86ae3 --- /dev/null +++ b/test/LibT.sol @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.24; + +import "./utils/SoladyTest.sol"; +import {LibT} from "../src/utils/LibT.sol"; + +contract LibTTest is SoladyTest { + function testLibT(bytes32 s, uint256 i) public { + unchecked { + assertEq(LibT.get(s), bytes32(0)); + LibT.set(s, bytes32(i)); + assertEq(LibT.get(s), bytes32(i)); + } + } +} diff --git a/test/LibTransient.t.sol b/test/LibTransient.t.sol deleted file mode 100644 index a2b3c85..0000000 --- a/test/LibTransient.t.sol +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -import "./utils/SoladyTest.sol"; -import {LibTransient} from "../src/utils/LibTransient.sol"; - -contract LibTransientTest is SoladyTest { - function testTransientSetAndGet(bytes32 s, uint256 i) public { - unchecked { - assertEq(LibTransient.get(s), bytes32(0)); - LibTransient.set(s, bytes32(i)); - assertEq(LibTransient.get(s), bytes32(i)); - } - } -}