generated from hrkrshnn/tstore-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be6492c
commit 946e327
Showing
7 changed files
with
1,108 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,15 @@ | ||
# Transient Store Foundry Template | ||
# Transient Store ERC20 (TERC20) | ||
|
||
This is a `TSTORE` version of ERC-20 implemented using a low iq search and replace on the [Solady](https://github.com/Vectorized/solady) ERC-20 implementation replacing the allowance `SSTORE` and `SLOAD` with `TSTORE` and `TLOAD`. | ||
|
||
A foundry template with custom `solc` binaries (from [transient-storage](https://github.com/ethereum/solidity/tree/transient-store)) that supports transient storage opcodes in inline assembly. | ||
```bash | ||
forge build --use bin/solc | ||
forge test --use bin/solc | ||
``` | ||
|
||
## Example contract | ||
# Why? | ||
|
||
```solidity | ||
contract SimpleTStore { | ||
function tstore(uint key, uint value) external { | ||
assembly { | ||
tstore(key, value) | ||
} | ||
} | ||
function tload(uint key) external view returns (uint value) { | ||
assembly { | ||
value := tload(key) | ||
} | ||
} | ||
} | ||
``` | ||
Arguably that the design for `approve` and `allowance` within the ERC-20 standard is necessary, but it creates a significant attack surface for unrevoked approvals. | ||
|
||
The design is meant to create approvals that only last for the duration of the transaction. If TERC-20 were to be combined with an [EIP-4337](https://eips.ethereum.org/EIPS/eip-4337) wallet, we could create a safe `approve/allowance` system for users, without the need to revoke approvals. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
solady/=lib/solady/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.4; | ||
|
||
import {TERC20} from "src/TERC20.sol"; | ||
|
||
/// @dev WARNING! This mock is strictly intended for testing purposes only. | ||
/// Do NOT copy anything here into production code unless you really know what you are doing. | ||
contract MockTERC20 is TERC20 { | ||
string internal _name; | ||
string internal _symbol; | ||
uint8 internal _decimals; | ||
bytes32 internal immutable _nameHash; | ||
|
||
constructor(string memory name_, string memory symbol_, uint8 decimals_) { | ||
_name = name_; | ||
_symbol = symbol_; | ||
_decimals = decimals_; | ||
_nameHash = keccak256(bytes(name_)); | ||
} | ||
|
||
function _constantNameHash() internal view virtual override returns (bytes32) { | ||
return _nameHash; | ||
} | ||
|
||
function name() public view virtual override returns (string memory) { | ||
return _name; | ||
} | ||
|
||
function symbol() public view virtual override returns (string memory) { | ||
return _symbol; | ||
} | ||
|
||
function decimals() public view virtual override returns (uint8) { | ||
return _decimals; | ||
} | ||
|
||
function mint(address to, uint256 value) public virtual { | ||
_mint(_brutalized(to), value); | ||
} | ||
|
||
function burn(address from, uint256 value) public virtual { | ||
_burn(_brutalized(from), value); | ||
} | ||
|
||
function directTransfer(address from, address to, uint256 amount) public virtual { | ||
_transfer(_brutalized(from), _brutalized(to), amount); | ||
} | ||
|
||
function directSpendAllowance(address owner, address spender, uint256 amount) public virtual { | ||
_spendAllowance(_brutalized(owner), _brutalized(spender), amount); | ||
} | ||
|
||
function transfer(address to, uint256 amount) public virtual override returns (bool) { | ||
return super.transfer(_brutalized(to), amount); | ||
} | ||
|
||
function transferFrom(address from, address to, uint256 amount) | ||
public | ||
virtual | ||
override | ||
returns (bool) | ||
{ | ||
return super.transferFrom(_brutalized(from), _brutalized(to), amount); | ||
} | ||
|
||
function _brutalized(address a) internal view returns (address result) { | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
result := or(a, shl(160, gas())) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.