Skip to content

Commit 9413c86

Browse files
committed
fix: badge now measures strict path and parses test logs
Switch badge methodology from floor-path gas-report scraping to strict-path log parsing. Both benchmarks now emit structured logs (staking/extreme strict savings bps) from vm.lastCallGas(), and the badge workflow parses those directly instead of grep/awk on Foundry's ASCII gas-report table. Strict path is the apples-to-apples comparison: both raw and strict store the exact value, so savings reflect pure storage layout gains.
1 parent 309fc26 commit 9413c86

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

.github/workflows/gas-badges.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@ jobs:
2525
- name: Run showcase gas benchmark
2626
run: |
2727
set -o pipefail
28-
forge test --match-path test/showcase/ShowcaseGas.t.sol --gas-report -vv | tee gas_report.txt
28+
forge test --match-path test/showcase/ShowcaseGas.t.sol -vv | tee gas_output.txt
2929
3030
- name: Generate badge endpoint JSON
3131
run: |
3232
set -euo pipefail
33-
raw_staking=$(grep -A 20 'RawETHStakingShowcase Contract' gas_report.txt | grep '| stake ' | awk -F'|' '{gsub(/ /,"",$3); print $3}' | head -n 1)
34-
quant_staking=$(grep -A 20 'QuantizedETHStakingShowcase Contract' gas_report.txt | grep '| stake ' | awk -F'|' '{gsub(/ /,"",$3); print $3}' | head -n 1)
35-
raw_extreme=$(grep -A 20 'RawExtremePackingShowcase Contract' gas_report.txt | grep '| setExtremeRaw ' | awk -F'|' '{gsub(/ /,"",$3); print $3}' | head -n 1)
36-
quant_extreme=$(grep -A 20 'QuantizedExtremePackingShowcase Contract' gas_report.txt | grep '| setExtremeFloor ' | awk -F'|' '{gsub(/ /,"",$3); print $3}' | head -n 1)
3733
38-
for value in "$raw_staking" "$quant_staking" "$raw_extreme" "$quant_extreme"; do
39-
[[ "$value" =~ ^[0-9]+$ ]] || { echo "Failed to parse gas report value: '$value'"; exit 1; }
34+
extract() { grep "$1" gas_output.txt | awk '{print $NF}'; }
35+
36+
staking_bps=$(extract "staking strict savings bps")
37+
extreme_bps=$(extract "extreme strict savings bps")
38+
39+
for value in "$staking_bps" "$extreme_bps"; do
40+
[[ "$value" =~ ^[0-9]+$ ]] || { echo "Failed to parse: '$value'"; exit 1; }
4041
done
41-
(( raw_staking > 0 && raw_extreme > 0 )) || { echo "Raw gas values must be greater than zero."; exit 1; }
4242
43-
staking_pct=$(awk -v raw="$raw_staking" -v quant="$quant_staking" 'BEGIN { printf "%.1f", (1 - quant / raw) * 100 }')
44-
extreme_pct=$(awk -v raw="$raw_extreme" -v quant="$quant_extreme" 'BEGIN { printf "%.1f", (1 - quant / raw) * 100 }')
43+
staking_pct=$(awk -v bps="$staking_bps" 'BEGIN { printf "%.1f", bps / 100 }')
44+
extreme_pct=$(awk -v bps="$extreme_bps" 'BEGIN { printf "%.1f", bps / 100 }')
4545
4646
mkdir -p .badges
4747
cat > .badges/staking-savings.json <<EOF

test/showcase/ShowcaseGas.t.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ contract ShowcaseGasTest is Test {
6262
uint256 floorGas = _measureSolidityRealQuantFloorStake();
6363
uint256 strictGas = _measureSolidityRealQuantStrictStake();
6464

65+
emit log_named_uint("staking raw gas", rawGas);
66+
emit log_named_uint("staking strict gas", strictGas);
67+
emit log_named_uint("staking strict savings bps", _savingsBps(rawGas, strictGas));
68+
6569
assertGt(rawGas, floorGas);
6670
assertGt(rawGas, strictGas);
6771
assertGe(_savingsBps(rawGas, floorGas), MIN_REAL_SAVINGS_BPS);
@@ -76,9 +80,7 @@ contract ShowcaseGasTest is Test {
7680
uint256 strictGas = _measureSolidityExtremeQuantStrict();
7781

7882
emit log_named_uint("extreme raw gas", rawGas);
79-
emit log_named_uint("extreme floor gas", floorGas);
8083
emit log_named_uint("extreme strict gas", strictGas);
81-
emit log_named_uint("extreme floor savings bps", _savingsBps(rawGas, floorGas));
8284
emit log_named_uint("extreme strict savings bps", _savingsBps(rawGas, strictGas));
8385
}
8486

0 commit comments

Comments
 (0)