Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dyedm1 authored Sep 24, 2023
0 parents commit da02759
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TestSimpleTStore:testEmptyRead() (gas: 5614)
TestSimpleTStore:testStore() (gas: 6415)
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI
on:
push:
branches:
- master
pull_request:

env:
FOUNDRY_PROFILE: ci

jobs:
run-ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Install deps
run: forge install

- name: Check gas snapshots
run: forge snapshot --check --use bin/solc

- name: Run tests
run: forge test --use bin/solc
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cache/
out/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>
24 changes: 24 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Transient Store Foundry Template

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

```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)
}
}
}
```
34 changes: 34 additions & 0 deletions bin/solc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Function to detect the operating system
detect_os() {
local os
if [[ "$(uname)" == "Darwin" ]]; then
os="mac"
elif [[ "$(uname)" == "Linux" ]]; then
os="linux"
else
os="unknown"
fi
echo "$os"
}

# Main script logic
main() {
local os=$(detect_os)

case $os in
mac)
./bin/solc-osx "$@"
;;
linux)
./bin/solc-static-linux "$@"
;;
*)
echo "Unsupported OS"
exit 1
;;
esac
}

main "$@"
Binary file added bin/solc-osx
Binary file not shown.
Binary file added bin/solc-static-linux
Binary file not shown.
4 changes: 4 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[profile.default]
cancun = true
[profile.ci.fuzz]
runs = 10_000
1 change: 1 addition & 0 deletions lib/forge-std
Submodule forge-std added at 40977d
15 changes: 15 additions & 0 deletions src/SimpleTStore.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.20;

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)
}
}
}
23 changes: 23 additions & 0 deletions test/SimpleTStore.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.13;

import "forge-std/Test.sol";

import "src/SimpleTStore.sol";

contract TestSimpleTStore is Test {
SimpleTStore c;

function setUp() public {
c = new SimpleTStore();
}

function testEmptyRead() public {
assertEq(c.tload(0), 0);
}

function testStore() public {
c.tstore(0, 1);
assertEq(c.tload(0), 1);
}
}

0 comments on commit da02759

Please sign in to comment.