Skip to content

Commit

Permalink
feat: added storage options slotNames and slotTypes for assembly acce…
Browse files Browse the repository at this point in the history
…ssed slots
  • Loading branch information
naddison36 committed Sep 17, 2023
1 parent 0997e2b commit 786b754
Show file tree
Hide file tree
Showing 23 changed files with 568 additions and 90 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ Options:
-s, --storage <address> The address of the contract with the storage values. This will be different from the contract with the code if a proxy contract is used. This is not needed if `fileFolderAddress` is an address and the contract is not proxied.
-u, --url <url> URL of the Ethereum node to get storage values if the `data` option is used. (default: "http://localhost:8545", env: NODE_URL)
-bn, --block <number> Block number to get the contract storage values from. (default: "latest")
-sn, --slotNames <names> Comma-separated list of slot names when accessed by assembly. The names can be a string, which will be hashed to a slot, or a 32 bytes hexadecimal string with a 0x prefix.
-st, --slotTypes <types> Comma-separated list of types for the slots listed in the `slotNames` option. eg address,uint256,bool. If all types are the same, a single type can be used. eg address (default: ["bytes32"])
-a, --array <number> Number of slots to display at the start and end of arrays. (default: "2")
-hx, --hideExpand <variables> Comma-separated list of storage variables to not expand. That's arrays, structs, strings or bytes.
-hv, --hideValues Hide storage slot value column. (default: false)
Expand Down
27 changes: 27 additions & 0 deletions examples/storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,33 @@ The storage slots for contract `D` in [inheritance/common.sol](../../src/contrac
sol2uml storage ./src/contracts/inheritance -c D -o examples/storage/inheritanceStorage.svg
```

## Assembly Accessed Slots

The `-sn, --slotNames` option lists slots that are accessed by assembly rather than Solidity storage variables.
The option value is a comma-separate list of slot names.
The names can be a string, which will be hashed to a slot, or a 32 bytes hexadecimal string with a 0x prefix.

In the below example, `OUSD.governor` is keccak256 hashed to slot `0x7bea13895fa79d2831e0a9e28edede30099005a50d652d8957cf8a607ee6ca4a`.

The `-st, --slotTypes` options allows types to be specified for each of the named slots.
This is a comma-separated list of types or a single type if all the types are the same.

The following example is Origin's OETH Dripper contract.

The `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc` slot is the keccak256 hash of "eip1967.proxy.implementation" subtracted by 1.
This holds the address of the implementation contract `0x2fdfbb2b905484f1445e23a97c97f65fe0e43dec` of the proxy contract `0xc0f42f73b8f01849a2dd99753524d4ba14317eb3`.

![OETH Dripper](../../examples/storage/origin-oeth-dripper.svg)

```
sol2uml storage 0x2fdfbb2b905484f1445e23a97c97f65fe0e43dec -v \
--data --storage 0xc0f42f73b8f01849a2dd99753524d4ba14317eb3 \
--slotNames OUSD.governor,OUSD.pending.governor,OUSD.reentry.status,0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc \
--slotTypes address,address,bool,address \
--hideExpand drip \
-o examples/storage/origin-oeth-dripper.svg
```

## USDC

The USD Coin (USDC) token deployed to [0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48](https://etherscan.io/address/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48#code) on mainnet is a proxied contract.
Expand Down
88 changes: 88 additions & 0 deletions examples/storage/origin-oeth-dripper.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions lib/converterClasses2Storage.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ export declare enum StorageSectionType {
}
export interface Variable {
id: number;
fromSlot: number;
toSlot: number;
fromSlot?: number;
toSlot?: number;
offset?: string;
byteSize: number;
byteOffset: number;
type: string;
Expand Down Expand Up @@ -45,6 +46,10 @@ export interface StorageSection {
* @return storageSections array of storageSection objects
*/
export declare const convertClasses2StorageSections: (contractName: string, umlClasses: UmlClass[], arrayItems: number, contractFilename?: string, noExpandVariables?: string[]) => StorageSection[];
export declare const optionStorageVariables: (contractName: string, slotNames?: {
name: string;
offset: string;
}[], slotTypes?: string[]) => Variable[];
/**
* Recursively adds new storage sections under a class attribute.
* also returns the allowed enum values
Expand Down
106 changes: 78 additions & 28 deletions lib/converterClasses2Storage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions lib/converterStorage2Dot.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 786b754

Please sign in to comment.