-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement solidity ast parsing
- Loading branch information
Showing
10 changed files
with
304 additions
and
193 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,66 +1,106 @@ | ||
## Foundry | ||
|
||
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.** | ||
|
||
Foundry consists of: | ||
# Spack | ||
|
||
Spack parses Solidity structs and packs the fields efficiently to reduce the | ||
number of storage slots they use. It also adds struct packing comments to clearly indicate | ||
how the fields are packed. | ||
|
||
It can deal with comments and whitespace in the struct definition, and will | ||
preserve them in the output. It handles unknown types by assuming they cannot be | ||
packed, treating they as `bytes32`. | ||
|
||
## Disclaimer | ||
|
||
This code is a work in progress and can contain bugs. Use it at your own risk. | ||
Feature request and bug reports are welcome. | ||
|
||
### Example | ||
|
||
input | ||
|
||
```solidity | ||
struct RequestMeta { | ||
uint64 completedRequests; | ||
Custom.Datatype data; | ||
address requestingContract; | ||
uint72 adminFee; // in wei | ||
address subscriptionOwner; | ||
bytes32 flags; // 32 bytes of flags | ||
uint96 availableBalance; // in wei. 0 if not specified. | ||
uint64 subscriptionId; | ||
uint64 initiatedRequests;// number of requests initiated by this contract | ||
uint32 callbackGasLimit; | ||
uint16 dataVersion; | ||
} | ||
``` | ||
|
||
- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools). | ||
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data. | ||
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network. | ||
- **Chisel**: Fast, utilitarian, and verbose solidity REPL. | ||
output | ||
|
||
```solidity | ||
struct RequestMeta { | ||
Custom.Datatype data; // | ||
bytes32 flags; // | ||
address requestingContract; // ──╮ | ||
uint96 availableBalance; // ─────╯ | ||
address subscriptionOwner; // ───╮ | ||
uint64 completedRequests; // │ | ||
uint32 callbackGasLimit; // ─────╯ | ||
uint72 adminFee; // ─────────────╮ | ||
uint64 subscriptionId; // │ | ||
uint64 initiatedRequests; // │ | ||
uint16 dataVersion; // ──────────╯ | ||
} | ||
``` | ||
|
||
## Documentation | ||
## Quickstart | ||
|
||
https://book.getfoundry.sh/ | ||
build | ||
|
||
## Usage | ||
```bash | ||
go build | ||
``` | ||
|
||
### Build | ||
Selecting all structs from a contract | ||
|
||
```shell | ||
$ forge build | ||
```bash | ||
./spack -c <CONTRACT> <COMMAND> | ||
``` | ||
|
||
### Test | ||
Selecting a specific struct from a contract | ||
|
||
```shell | ||
$ forge test | ||
```bash | ||
./spack -c <CONTRACT> -s <STRUCT> <COMMAND> | ||
``` | ||
|
||
### Format | ||
Counting storage slots | ||
|
||
```shell | ||
$ forge fmt | ||
```bash | ||
./spack -c Spack count | ||
``` | ||
|
||
### Gas Snapshots | ||
Printing structs without optimizations but with struct packing comments | ||
|
||
```shell | ||
$ forge snapshot | ||
```bash | ||
./spack -c Spack -u <COMMAND> | ||
``` | ||
|
||
### Anvil | ||
Printing the struct with optimizations and struct packing comments: | ||
|
||
```shell | ||
$ anvil | ||
``` | ||
## Commands and flags | ||
|
||
### Deploy | ||
### Commands | ||
|
||
```shell | ||
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key> | ||
``` | ||
- `pack` - packs the struct | ||
- `count` - counts the number of storage slots the struct uses | ||
|
||
### Cast | ||
### Flags | ||
|
||
```shell | ||
$ cast <subcommand> | ||
``` | ||
- `-c` or `--contract` - load all structs from a contract | ||
- `-s` or `--struct` - load a specific struct from a contract | ||
- `-u` or `--unoptimized` - print structs without optimizations but with struct packing comments | ||
- `--cfg` or `--config` - load the config from a file | ||
|
||
### Help | ||
## TODO | ||
|
||
```shell | ||
$ forge --help | ||
$ anvil --help | ||
$ cast --help | ||
``` | ||
- [ ] Add more flexible command line options | ||
- [ ] Add tests | ||
- [ ] Improve error handling |
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
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.