Skip to content

Commit

Permalink
📖 Include Version and Configuration Information in Gas Snapshots (#282)
Browse files Browse the repository at this point in the history
### 🕓 Changelog

This commit adds a Bash script, `generate_gas_snapshot.sh`, that includes
version and configuration information into the gas snapshot files to
improve traceability. Specifically, it prepends the `vyper` commit
version, the `forge` commit version, and `vyper` configuration settings
(e.g. optimisation mode) to the `snapshot` files. The script also
supports generating snapshots for the `default-venom` profile using the
`--venom` flag. Eventually, we pin the specific `vyper` commit
[`d8f4032355773cd5e57e8902bd50808490de39b5`](vyperlang/vyper@d8f4032)
as the subsequent commit
[`fdc05d6029816ef57294e98753d9a3d60c761ab8`](vyperlang/vyper@fdc05d6)
(PR [#4039](vyperlang/vyper#4039)) currently
breaks our `venom`-based tests (refer to issue
[#4288](vyperlang/vyper#4288) for details).

---------

Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
  • Loading branch information
pcaversaccio authored Oct 11, 2024
1 parent 850d0df commit 3b63a27
Show file tree
Hide file tree
Showing 13 changed files with 308 additions and 180 deletions.
186 changes: 100 additions & 86 deletions .gas-snapshot

Large diffs are not rendered by default.

181 changes: 98 additions & 83 deletions .gas-snapshot-venom

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@ jobs:
- name: Validate URLs
run: |
awesome_bot ./*.md src/snekmate/**/*.vy src/snekmate/**/mocks/*.vy src/snekmate/**/interfaces/*.vyi \
test/**/*.sol test/**/interfaces/*.sol test/**/mocks/*.sol test/**/scripts/*.js lib/utils/*.sol lib/utils/*.py \
test/**/*.sol test/**/interfaces/*.sol test/**/mocks/*.sol test/**/scripts/*.js scripts/*.sh lib/utils/*.sol lib/utils/*.py \
--allow-dupe --allow-redirect --request-delay 0.4 \
--white-list https://www.wagmi.xyz,https://github.com/pcaversaccio/snekmate.git@,https://github.com/pcaversaccio/snekmate/releases/tag/v0.1.1,https://github.com/pcaversaccio/snekmate/blob/v0.1.1,https://github.com/pcaversaccio/snekmate/compare/v0.1.0...v0.1.1,https://hyperelliptic.org
2 changes: 1 addition & 1 deletion .github/workflows/halmos-venom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
architecture: ${{ matrix.architecture }}

- name: Install Vyper
run: pip install git+https://github.com/vyperlang/vyper@master
run: pip install git+https://github.com/vyperlang/vyper@d8f4032355773cd5e57e8902bd50808490de39b5

- name: Show the Vyper version
run: vyper --version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-contracts-venom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
architecture: ${{ matrix.architecture }}

- name: Install Vyper
run: pip install git+https://github.com/vyperlang/vyper@master
run: pip install git+https://github.com/vyperlang/vyper@d8f4032355773cd5e57e8902bd50808490de39b5

- name: Install pnpm
uses: pnpm/action-setup@v3
Expand Down
1 change: 1 addition & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
plugins:
- "prettier-plugin-solidity"
- "prettier-plugin-sh"
5 changes: 2 additions & 3 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ Please report any security issues you find to [pascal.caversaccio@hotmail.ch](ma

```sh
-----BEGIN PGP PUBLIC KEY BLOCK-----
Comment: Type: 3,072-bit RSA
Comment: Fingerprint: 063E966C93AB4356492FE0327C3B4B4B7725111F

Comment: Type: 3,072-bit RSA
Comment: Fingerprint: 063E966C93AB4356492FE0327C3B4B4B7725111F

mQGNBGBUv08BDADTYA0GjLhbKbCezlVAubakXh0jcIbkqZPF1wueSbSgDjlS6+d8
67V6ft4hNXJhpNxqr07LrcbUEDdB7WK8EUA9qsLtVRznR/B8y2HwrFs7jbYAUzl6
Expand Down
2 changes: 1 addition & 1 deletion lib/forge-std
Submodule forge-std updated 4 files
+181 −0 CONTRIBUTING.md
+16 −0 README.md
+53 −8 src/Vm.sol
+2 −2 test/Vm.t.sol
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"url": "https://github.com/pcaversaccio/snekmate/issues"
},
"scripts": {
"prettier:check": "npx prettier -c \"**/*.{md,sol,js,json,yml,yaml}\"",
"prettier:fix": "npx prettier -w \"**/*.{md,sol,js,json,yml,yaml}\"",
"prettier:check": "npx prettier -c \"**/*.{md,sol,js,json,yml,yaml,sh}\"",
"prettier:fix": "npx prettier -w \"**/*.{md,sol,js,json,yml,yaml,sh}\"",
"solhint:check": "npx solhint \"**/*.sol\"",
"solhint:fix": "npx solhint \"**/*.sol\" --fix",
"lint:check": "pnpm prettier:check && pnpm solhint:check && npx eslint .",
Expand All @@ -45,6 +45,7 @@
"keccak256": "^1.0.6",
"merkletreejs": "^0.4.0",
"prettier": "^3.3.3",
"prettier-plugin-sh": "^0.14.0",
"prettier-plugin-solidity": "^1.4.1",
"solhint": "^5.0.3"
}
Expand Down
33 changes: 33 additions & 0 deletions pnpm-lock.yaml

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

65 changes: 65 additions & 0 deletions scripts/generate_gas_snapshot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash

# Set the default values.
OUTPUT_FILE=".gas-snapshot"
FOUNDRY_PROFILE="default"
TEMP_FILE=$(mktemp)

# Utility function to print usage.
print_usage() {
echo "Usage: $0 [--venom]"
echo " --venom Use Venom configuration"
}

# Utility function to prepend content to the output file.
prepend_to_output() {
echo "$1" >> "$TEMP_FILE"
}

# Parse the command line arguments.
while [[ "$#" -gt 0 ]]; do
case $1 in
--venom)
OUTPUT_FILE=".gas-snapshot-venom"
FOUNDRY_PROFILE="default-venom"
;;
--help)
print_usage
exit 0
;;
*)
echo "Error: Unknown parameter passed: $1"
print_usage
exit 1
;;
esac
shift
done

# Set the environment variable.
export FOUNDRY_PROFILE

# Generate the snapshot file.
forge snapshot --snap "$OUTPUT_FILE"

# Prepare the content to be prepended.
prepend_to_output "Vyper version: $(vyper --version)"
prepend_to_output "Forge version: $(forge --version)"
prepend_to_output "Vyper config:"
forge config --json | jq -r ".vyper" >> "$TEMP_FILE"
prepend_to_output "=========================================="
prepend_to_output "██╗░░░██╗██╗░░░██╗██████╗░███████╗██████╗░"
prepend_to_output "██║░░░██║╚██╗░██╔╝██╔══██╗██╔════╝██╔══██╗"
prepend_to_output "╚██╗░██╔╝░╚████╔╝░██████╔╝█████╗░░██████╔╝"
prepend_to_output "░╚████╔╝░░░╚██╔╝░░██╔═══╝░██╔══╝░░██╔══██╗"
prepend_to_output "░░╚██╔╝░░░░░██║░░░██║░░░░░███████╗██║░░██║"
prepend_to_output "░░░╚═╝░░░░░░╚═╝░░░╚═╝░░░░░╚══════╝╚═╝░░╚═╝"
prepend_to_output "=========================================="

# Prepend the prepared content to the snapshot file.
cat "$TEMP_FILE" "$OUTPUT_FILE" > "${OUTPUT_FILE}.tmp" && mv "${OUTPUT_FILE}.tmp" "$OUTPUT_FILE"

# Clean up the temporary file.
rm "$TEMP_FILE"

echo "Gas snapshot generated in $OUTPUT_FILE"

0 comments on commit 3b63a27

Please sign in to comment.