Skip to content

Commit

Permalink
T
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized committed Jan 27, 2024
1 parent 0e65965 commit a751a1a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
```

Expand Down
14 changes: 11 additions & 3 deletions src/utils/LibTransient.sol → src/utils/LibT.sol
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}
}
}
15 changes: 15 additions & 0 deletions test/LibT.sol
Original file line number Diff line number Diff line change
@@ -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));
}
}
}
15 changes: 0 additions & 15 deletions test/LibTransient.t.sol

This file was deleted.

0 comments on commit a751a1a

Please sign in to comment.