Skip to content

[#4923] Fix the revm fork Low findings of the delta audit - #100

Merged
isaacdoidge merged 2 commits into
feature/revm-43-syncfrom
task/issue-4923
Dec 2, 2026
Merged

isaacdoidge merged 2 commits into
feature/revm-43-syncfrom
task/issue-4923

Conversation

@aregng

@aregng aregng commented Dec 1, 2026

Copy link
Copy Markdown

Summary

Fixes the Low findings of the revm fork delta audit roll-up, Entropy-Foundation/smr-moonshot#4923, except three that other changes cover:

Registry (Solidity)

  • V3-2: withdrawFees is accepted while the cycle is STARTED or READY. While a cycle transition is pending (FINISHED or SUSPENDED), it reverts with the new IConfigFacet.CycleTransitionInProgress. Because the ABI changed, the ConfigFacet golden hash is updated.
  • V10-3: NatSpec only. A user task's priority is always its task index. Only registerSystemTask applies _priority, and 0 there selects the default.
  • Gas-config comments: DiamondInit and LibCommon now state that the gas-config precompile serves the published EVM gas parameters during genesis. They also say why DiamondInit does not depend on it: the Forge fixtures and the ee-tests run without the precompile.

Genesis generator (supra-extension)

  • V5-1: the configuration requires cycle_duration_secs > 0, strictly below both task duration caps. This mirrors LibCommon.validateConfigParameters.
  • V5-2: the embedded bytecode is compiled from the project's foundry.toml alone.
    • Every FOUNDRY_*/DAPP_* variable is removed, with a cargo warning, except two kinds:
      • variables the caller allows;
      • FOUNDRY_OFFLINE, which cannot change the bytecode.
    • The global ~/.foundry/foundry.toml is not read: HOME points to an empty directory while the configuration loads.
    • Build-script reruns:
      • The fixed list of watched variables is replaced by watching only the variables that reach the compiler.
      • remappings.txt is watched only when it exists. A watched path that does not exist made the build script rerun on every build, rebuilding every dependent crate each time.

Operator scripts

  • V4-3: each governance action has a digest() function. submit_governance_action.sh resumes a pending transaction only when the named action's digest equals both GOV_TXN_CONTENT_HASH and the hash the wallet stores.
  • V4-4: deploy_automation_registry.sh (local testing only) changes:
    • it signs with a Foundry keystore account and takes no private key on the command line;
    • it has --help;
    • it reads .env as data, never as shell code (script/dotenv.sh);
    • it resolves ETH_PASSWORD, including a leading ~/, from the caller's directory.
  • V10-4: the scripts no longer use ${var,,} or realpath, so they run with macOS's /bin/bash 3.2, and realpath is not needed on releases before macOS 13. submit_governance_action.sh is now executable, as the README's ./submit_governance_action.sh assumes.

Tests (V1 gaps, V6-3, V13-1, #41, #42, #47, #51, #74)

  • Forge: withdrawFees in each cycle state, the auxData total-length cap, event trimming in cancelSystemTasks/stopSystemTasks, no squaring after the last exponent bit, and the AppStorage slot.
  • Rust:
    • the native enums are checked against the LibCommon.sol enums, by name, order and uint8 value;
    • GenesisTransaction carries no value field;
    • the default fees equal their stated SUPRA amounts;
    • a damaged artifact is recompiled;
    • the Foundry configuration isolation (environment variables and the global foundry.toml).
  • Shell: test/shell/operator_scripts_test.sh runs the operator scripts against stub forge and cast. CI runs it in the forge-tests job.

Motivation

These are the findings of Entropy-Foundation/smr-moonshot#4923 that were still open on feature/evm_automation (rc28), each with the decision recorded on the issue. The added tests fill the V1 test gaps: at rc28, each guard below could be removed without any test failing.

Test plan

  • cargo fmt --all --check
  • RUSTFLAGS=-Dwarnings cargo clippy --release --workspace --all-targets --all-features
  • cargo nextest run --release --workspace --all-features: 707 passed, 1 skipped
  • forge test: 710 passed
  • check_event_indexing.sh, check_facet_selectors.sh, and forge build --sizes under the default and production profiles
  • ./test/shell/operator_scripts_test.sh: 15 passed under bash 5
  • Mutation checks: removing each guard fails the intended test.
    • Solidity: the auxData cap, event trimming, the exponent bound, the AppStorage slot, and each withdrawFees state.
    • Rust: both halves of the configuration isolation.
    • Shell: the ETH_PASSWORD resolution and the realpath check.
  • Cargo: with nothing changed, a release rebuild is Fresh, and setting FOUNDRY_OPTIMIZER=false no longer reruns the build script.
  • macOS /bin/bash 3.2 run (requested from a macOS reviewer):
    cd solidity/supra_contracts
    /bin/bash --version | head -1                     # GNU bash, version 3.2.57...
    /bin/bash -c 'h=0xABCD; echo "${h,,}"'            # bad substitution (the old construct)
    /bin/bash -c 'printf "%s" 0xABCD | tr "[:upper:]" "[:lower:]"; echo'   # 0xabcd
    TEST_BASH=/bin/bash /bin/bash ./test/shell/operator_scripts_test.sh
    # last line: 15 tests, 0 failed (scripts run with /bin/bash: 3.2.57(1)-release)

Notes

🤖 Generated with Claude Code

Registry:
- withdrawFees is accepted while the cycle is STARTED or READY and reverts
  with the new IConfigFacet.CycleTransitionInProgress while a cycle
  transition is pending (FINISHED or SUSPENDED).
- NatSpec: a user task's priority is always its task index; only
  registerSystemTask applies _priority, and 0 selects the default.
- DiamondInit and LibCommon state that the gas-config precompile serves the
  published EVM gas parameters during genesis, and why DiamondInit does not
  depend on it.

Genesis generator (supra-extension):
- The configuration requires a positive cycle duration strictly below both
  task duration caps.
- The embedded Solidity bytecode is compiled from the project's
  foundry.toml alone: FOUNDRY_*/DAPP_* variables other than the allowed and
  bytecode-neutral ones are removed with a warning, and the global
  ~/.foundry/foundry.toml is not read. The build re-runs only for the
  variables that reach the compiler, and watches remappings.txt only when it
  exists, so an unchanged tree no longer re-runs the build script.

Operator scripts:
- Each governance action has digest(), and submit_governance_action.sh
  resumes a pending transaction only when the named action's digest equals
  the stored content hash.
- deploy_automation_registry.sh signs with a Foundry keystore account, has
  --help, reads .env as data (script/dotenv.sh) and resolves ETH_PASSWORD
  from the caller's directory.
- The scripts run under bash 3.2 and do not need realpath (macOS).

Tests: withdrawFees per cycle state, auxData total-length cap, system task
event trimming, fee multiplier exponent bound, AppStorage slot, Solidity
enum mirrors, GenesisTransaction fields, default fees, damaged-artifact
recompilation, Foundry configuration isolation, and the operator scripts
(run in CI against stub forge and cast).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aregng

aregng commented Dec 1, 2026

Copy link
Copy Markdown
Author

macOS check: operator scripts under /bin/bash 3.2

The operator scripts (submit_governance_action.sh, deploy_automation_registry.sh) should now work with macOS's built-in /bin/bash 3.2, but they have not been run on a Mac yet. Could someone on macOS run the following? It takes about a minute. The tests use stand-in forge and cast, so nothing needs to be installed and no chain is contacted.

git fetch origin && git checkout task/issue-4923
cd solidity/supra_contracts

/bin/bash --version | head -1        # expect: GNU bash, version 3.2.57...
/bin/bash -c 'h=0xABCD; echo "${h,,}"'                                  # expect: "bad substitution" (the old code)
/bin/bash -c 'printf "%s" 0xABCD | tr "[:upper:]" "[:lower:]"; echo'   # expect: 0xabcd (the new code)
TEST_BASH=/bin/bash /bin/bash ./test/shell/operator_scripts_test.sh

The last command should end with:
15 tests, 0 failed (scripts run with /bin/bash: 3.2.57(1)-release)

Please reply with that last line and your macOS version (sw_vers -productVersion). The scripts no longer call realpath, which macOS ships only from version 13, so a result from an older version is especially useful. If anything fails, please paste the full output; each failing test prints its name and what the script printed.

@isaacdoidge isaacdoidge left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 05572e8e. The V3-2, V4-3, V5-1 and V10-3 changes match the fix sketches on Entropy-Foundation/smr-moonshot#4923, and each added guard test fails without its guard. Inline: three changes needed (load_dotenv names, Foundry prefix matching, the stand-in home directory) and four nits.

macOS /bin/bash 3.2 test-plan item: passes. On macOS 27.2.1 with GNU bash, version 3.2.57(1)-release (arm64-apple-darwin26):

  • ${h,,} fails with bad substitution;
  • the tr replacement prints 0xabcd;
  • TEST_BASH=/bin/bash /bin/bash ./test/shell/operator_scripts_test.sh ends with 15 tests, 0 failed (scripts run with /bin/bash: 3.2.57(1)-release).

CI (nit): V10-4 is guarded by a grep for a few bash 4 constructs, and forge-tests runs the shell tests under ubuntu's bash 5 only. A macOS job running the suite with TEST_BASH=/bin/bash would cover bash 3.2 compatibility as a whole rather than the listed constructs.

Question on V3-2: withdrawFees is refused for the whole of FINISHED and SUSPENDED, not only while isTransitionInProgress() is true. While the node keeps automation paused (getRecordMaxTaskCount returning 0), the cycle can stay FINISHED and the owner cannot withdraw until it advances. Is that the intended behaviour?

Comment on lines +14 to +26
local file=$1 line name value
while IFS= read -r line || [ -n "${line}" ]; do
[[ "${line}" =~ ^[[:space:]]*(export[[:space:]]+)?([A-Za-z_][A-Za-z0-9_]*)=(.*)$ ]] || continue
name=${BASH_REMATCH[2]}
value=${BASH_REMATCH[3]}
if [ -n "${!name+set}" ]; then
echo "Using ${name} from the environment, not from ${file}"
continue
fi
if [[ "${value}" =~ ^\"(.*)\"$ || "${value}" =~ ^\'(.*)\'$ ]]; then
value=${BASH_REMATCH[1]}
fi
export "${name}=${value}"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

V4-4: load_dotenv should export only the names the calling script documents, e.g. an allow-list passed as a second argument, and ignore (with a message) any other name in the file. Please add a shell test for a name outside the list.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 5c9d8e9. load_dotenv <file> <name>... exports only the listed names and ignores any other name with "Ignoring NAME in : not a variable this script reads". Each script passes the names it documents. GOV_TXN_INDEX/GOV_TXN_CONTENT_HASH are not on the list, so they come from the environment only. New shell tests: test_deploy_dotenv_ignores_names_the_script_does_not_read (checks that forge does not see a FOUNDRY_SENDER from .env), test_submit_dotenv_ignores_the_resume_variables and test_load_dotenv_requires_the_names_to_read. Each fails without the allow-list.

Comment on lines +79 to +88
fn ambient_foundry_vars<'a>(
names: impl IntoIterator<Item = &'a str>,
allowed_env: &[&str],
) -> Vec<String> {
let mut ambient: Vec<String> = names
.into_iter()
.filter(|name| {
FOUNDRY_ENV_PREFIXES
.iter()
.any(|prefix| name.starts_with(prefix))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

V5-2: foundry-config reads the environment through figment's Env, which trims each name and matches the prefix ignoring ASCII case (UncasedStr); Profile::from_env does the same for FOUNDRY_PROFILE. The filter here should select the same set of names: trim, compare the prefix case-insensitively, apply the same comparison against allowed_env, and cover case variants of FOUNDRY_PROFILE. every_foundry_and_dapp_variable_is_ambient could then include lowercase and space-padded names.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 5c9d8e9. foundry_env_key trims and uppercases, and every comparison (prefix, allowed names, FOUNDRY_PROFILE) goes through it. Every variant of FOUNDRY_PROFILE is removed even when allowed, because Profile::from_env takes the first match and select_foundry_profile sets the exact name afterwards. Names that are not UTF-8 are matched in their lossy form, as figment reads them, and removed by their original bytes. Unit tests cover lowercase, space-padded and allowed-variant names. The integration test sets foundry_optimizer and " Foundry_Optimizer ", and it fails if matching is made case-sensitive again.

Comment on lines +132 to +136
let empty_home = std::env::temp_dir().join(format!(
"supra-foundry-config-home-{}",
std::process::id()
));
std::fs::create_dir_all(&empty_home)?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stand-in home should be a directory this build creates itself and only this user can access: create_dir (not create_dir_all) with mode 0700 and an unpredictable name, or a directory under OUT_DIR when it is set. On Linux temp_dir() is the shared /tmp, and create_dir_all succeeds on a fixed name that already exists.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 5c9d8e9. create_private_dir: DirBuilder::create (not create_dir_all) with mode 0700 on Unix and a RandomState-seeded suffix. It tries a new name on AlreadyExists, so an existing directory is never used. The parent is OUT_DIR when set, the temp dir otherwise. private_directories_are_new_empty_and_owner_only checks that each call gets its own directory, that it is empty and that its mode is 0700.

/// at an empty directory for the duration of the load and restored before this returns.
/// Compilation runs after the restore, so the compiler is found in the usual place.
///
/// Changes `HOME` for the whole process while it runs; a build script is single-threaded.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: on the retry path (discard_compiled_output → load_project_config), foundry-compilers' rayon pool has already started, so the process is not single-threaded. Suggest stating what holds: no other thread reads the environment while the configuration loads.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworded in 5c9d8e9: no other thread may read the environment while the configuration loads. On the retry path the compiler's thread pool exists but is idle then: the first compilation has returned and the second has not started.

}

# Runs the script $1 of the scratch project with the remaining arguments, under TEST_BASH, with
# the stubs first on PATH and a clean environment apart from the variables the caller exports.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: run_script passes on the caller's whole environment, so "a clean environment apart from the variables the caller exports" does not describe what happens. Either clear it (env -i plus PATH/HOME) or reword the comment.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5c9d8e9: the harness now unsets every variable the scripts read, from the environment or .env, before any test runs. The comment says the scripts inherit that environment plus what the test exports.

Comment on lines +72 to +74
case "${ETH_PASSWORD}" in
/*) ;;
*) ETH_PASSWORD="$(pwd)/${ETH_PASSWORD}" ;;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: a relative ETH_PASSWORD read from .env resolves against the caller's directory, not the directory of the .env file. The PR says that is intended; the --help text should then say what a relative path is relative to.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 5c9d8e9: --help now says a relative ETH_PASSWORD is relative to the directory the script is run from, also when set in .env, and that a leading ~/ is expanded.

let link = home.join(&svm);
std::fs::create_dir_all(link.parent().expect("a relative path has a parent"))
.expect("the link's directory is creatable");
std::os::unix::fs::symlink(&real, &link).expect("the solc installs are linkable");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: std::os::unix::fs::symlink is not under #[cfg(unix)], so --all-features tests do not compile on Windows. The test relies on HOME, which is Unix-only too, so gating the whole test file with #![cfg(unix)] fits. CI is ubuntu-only, so nothing fails today.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 5c9d8e9: #![cfg(unix)] on the whole file, with the reason in its header.

@aregng

aregng commented Dec 2, 2026

Copy link
Copy Markdown
Author

Question on V3-2: withdrawFees is refused for the whole of FINISHED and SUSPENDED, not only while isTransitionInProgress() is true. While the node keeps automation paused (getRecordMaxTaskCount returning 0), the cycle can stay FINISHED and the owner cannot withdraw until it advances. Is that the intended behaviour?

Yes it is the intended behaviour. If you see any use-case that the current logic will affect UX please let me know.

… as foundry-config does

Review of #100:
- load_dotenv exports only the names the calling script documents and
  ignores any other name in .env with a message. GOV_TXN_INDEX and
  GOV_TXN_CONTENT_HASH are read from the environment only.
- The Foundry environment isolation matches names as foundry-config does
  (trimmed, prefix compared ignoring ASCII case), against allowed names
  too, and removes every variant of FOUNDRY_PROFILE before the build sets
  it.
- The stand-in home directory used while loading the Foundry configuration
  is a new directory with an unpredictable name, mode 0700, under OUT_DIR
  when set.
- Docs: the threading condition of load_project_config, what a relative
  ETH_PASSWORD is relative to, the operator-script test harness's
  environment, and the .env allow-list in the README.
- foundry_config_isolation builds on Unix only.
- CI runs the operator-script tests on macOS under /bin/bash 3.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aregng

aregng commented Dec 2, 2026

Copy link
Copy Markdown
Author

Thanks for the review and the macOS run. Everything is addressed in 5c9d8e9 (replies on each thread). On the CI nit: a new job, operator-scripts-macos, runs on macos-latest. It checks that /bin/bash is 3.2, then runs test/shell/operator_scripts_test.sh with TEST_BASH=/bin/bash, so the whole suite is checked under bash 3.2 rather than only the grep for bash-4 constructs. The V3-2 behaviour is intended (answered above).

@isaacdoidge
isaacdoidge merged commit dcb9fea into feature/revm-43-sync Dec 2, 2026
21 checks passed
@aregng
aregng deleted the task/issue-4923 branch December 2, 2026 11:54
isaacdoidge added a commit that referenced this pull request Dec 3, 2026
GovActions.t.sol keeps #100's digest tests and this branch's
test_acceptsTheLargestLimitBlockMetaAccepts, which replaced
test_acceptsALimitEqualToTheCallableShare.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
isaacdoidge added a commit that referenced this pull request Dec 3, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants