From 2008b1a4dd12de099061e5c242e8a300e1a86304 Mon Sep 17 00:00:00 2001 From: "Leo Zhang (zhangchiqing)" Date: Fri, 2 Jan 2026 13:12:10 -0800 Subject: [PATCH 1/2] fix script execution for scripts that invokes system contract functions when the system contracts imports evm --- fvm/script.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fvm/script.go b/fvm/script.go index e79b8c5ff0f..1c8289d60ac 100644 --- a/fvm/script.go +++ b/fvm/script.go @@ -203,6 +203,11 @@ func (executor *scriptExecutor) executeScript() error { chainID := executor.ctx.Chain.ChainID() if executor.ctx.EVMEnabled { + // Setup InternalEVM in both environments because: + // - Scripts execute in ScriptRuntimeEnv + // - But system contract invocations (e.g., getAccount().balance) use TxRuntimeEnv + + // Setup InternalEVM in ScriptRuntimeEnv (for script execution) err := evm.SetupEnvironment( chainID, executor.env, @@ -211,6 +216,21 @@ func (executor *scriptExecutor) executeScript() error { if err != nil { return err } + + // Setup InternalEVM in TxRuntimeEnv (for system contract invocations) + // This solves the problem where FlowServiceAccount (which imports EVM) needs + // InternalEVM to be available during dependency checking when invoked via + // system contracts (e.g., getAccount().balance). Without this, type checking + // fails with "cannot find variable in this scope: `InternalEVM`" because + // system contract invocations use TxRuntimeEnv, not ScriptRuntimeEnv. + err = evm.SetupEnvironment( + chainID, + executor.env, + rt.TxRuntimeEnv, + ) + if err != nil { + return err + } } value, err := rt.ExecuteScript( From 2b5aaef358c2fcd67454bbbc50a3f44eb7710422 Mon Sep 17 00:00:00 2001 From: Peter Argue <89119817+peterargue@users.noreply.github.com> Date: Mon, 5 Jan 2026 16:24:52 -0800 Subject: [PATCH 2/2] remove executor.ctx.EVMEnabled --- fvm/script.go | 54 +++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/fvm/script.go b/fvm/script.go index 1c8289d60ac..038f4d03ebd 100644 --- a/fvm/script.go +++ b/fvm/script.go @@ -202,35 +202,33 @@ func (executor *scriptExecutor) executeScript() error { chainID := executor.ctx.Chain.ChainID() - if executor.ctx.EVMEnabled { - // Setup InternalEVM in both environments because: - // - Scripts execute in ScriptRuntimeEnv - // - But system contract invocations (e.g., getAccount().balance) use TxRuntimeEnv - - // Setup InternalEVM in ScriptRuntimeEnv (for script execution) - err := evm.SetupEnvironment( - chainID, - executor.env, - rt.ScriptRuntimeEnv, - ) - if err != nil { - return err - } + // Setup InternalEVM in both environments because: + // - Scripts execute in ScriptRuntimeEnv + // - But system contract invocations (e.g., getAccount().balance) use TxRuntimeEnv + + // Setup InternalEVM in ScriptRuntimeEnv (for script execution) + err := evm.SetupEnvironment( + chainID, + executor.env, + rt.ScriptRuntimeEnv, + ) + if err != nil { + return err + } - // Setup InternalEVM in TxRuntimeEnv (for system contract invocations) - // This solves the problem where FlowServiceAccount (which imports EVM) needs - // InternalEVM to be available during dependency checking when invoked via - // system contracts (e.g., getAccount().balance). Without this, type checking - // fails with "cannot find variable in this scope: `InternalEVM`" because - // system contract invocations use TxRuntimeEnv, not ScriptRuntimeEnv. - err = evm.SetupEnvironment( - chainID, - executor.env, - rt.TxRuntimeEnv, - ) - if err != nil { - return err - } + // Setup InternalEVM in TxRuntimeEnv (for system contract invocations) + // This solves the problem where FlowServiceAccount (which imports EVM) needs + // InternalEVM to be available during dependency checking when invoked via + // system contracts (e.g., getAccount().balance). Without this, type checking + // fails with "cannot find variable in this scope: `InternalEVM`" because + // system contract invocations use TxRuntimeEnv, not ScriptRuntimeEnv. + err = evm.SetupEnvironment( + chainID, + executor.env, + rt.TxRuntimeEnv, + ) + if err != nil { + return err } value, err := rt.ExecuteScript(