Lab results

The lab sections below were run in our own sandbox; the last section is a read of mainnet. The error strings are what the node returned, copied verbatim from docs/NEAR-FACTS.md. Anything not listed here is not assumed.

Setup and scope

Lab environment
ItemValue
Sandboxnear-sandbox 0.4.0
Nodenearcore 2.14.0
Protocol versionprotocol 88
Topologysingle-shard, root account sandbox (parent.test.near becomes parent.sandbox)

Older model. The access-key rows were tested with gas keys on sub-accounts. The product now uses classic function-call keys on a contract account. The permission semantics are expected to carry over, but tests T5 to T9 are owed before relying on them. Testnet may also behave differently from the lab.

What is impossible

Five routes, each tested, each closed. Detecting a code change therefore requires an off-chain observer, and that is permanent under the current protocol.
Closed routes
ImpossibleWhy
A contract reading another account's code_hash, state or access keysNo host function exists. near-sys offers own-account storage, promises, crypto, validators.
A contract calling RPCThe runtime provides no such path.
A cross-contract call reading raw stateIt can invoke methods only.
Guaranteeing the target's code at execution time by checking beforehandTOCTOU window of at least 3 blocks.
Trusting a target to report its own code identityMalicious code can return a false value.

What a function-call key can and cannot do

Tested from an agent key restricted to one method on one contract.
Agent key actions and the exact errors
ActionResultExact errorOn chain
Transfer NEARrejectedRequiresFullAccessno
AddKey on itselfrejectedRequiresFullAccessno
DeployContract on itselfrejectedRequiresFullAccessno
FunctionCall to another contractrejectedReceiverMismatch { ak_receiver: gate.sandbox }no
FunctionCall to a method outside the listrejectedMethodNameMismatch { method_name: "other" }no
Parent AddKey, Deploy or DeleteAccount on a sub-accountrejectedActorNoPermission { actor_id: parent.sandbox }yes
FunctionCall with a 1 yocto depositrejectedDepositWithFunctionCallno

The first five rows are rejected by the node at validation, so their transaction hashes never reach the chain and cannot be looked up in an explorer. Only the parent case leaves an on-chain trace. Evidence is a re-runnable script that prints the RPC errors.

A restricted key cannot attach a deposit at all, and NEP-141 requires exactly 1 yoctoNEAR for ft_transfer and ft_transfer_call. With deposit 0 the contract panics: Requires attached deposit of exactly 1 yoctoNEAR. So an agent structurally cannot move NEP-141 tokens itself, and a vault holding pre-funded assets is the only possible architecture.

Immutability needs three checks

No full-access key does not mean immutable: a locked contract can still upgrade itself if its code exposes an authorized update method.
  1. 1code referenced by hash (not local, not global-by-account)
  2. 2no full-access keys on the account
  3. 3the WASM import section contains no deploy, use-global-contract, add-full-access-key, add-full-access-gas-key or delete-account host functions

Absence is sound: a contract cannot call a host function it does not import. Presence is weaker. Measured on 7 November 2026 with near-sdk 5.30.1 (release, LTO, no wasm-opt) on a one-method contract:

Host function imports by how a key is added
How it adds one function-call keypromise_batch_action imports
Promise::new(...).add_access_key_allowance(...)17, including deploy, delete-account, add-full-access-key, add-full-access-gas-key and use-global-contract
env::promise_batch_action_add_key_allowance_with_function_call(...)1: promise_batch_action_add_key_with_function_call

So the vault must use the low-level functions, and many ordinary near-sdk contracts carry these imports with no upgrade route. Open: a contract able to delete its own account frees the name, and a parent can recreate a sub-account with other code. Lab test T9 must confirm the behaviour.

The TOCTOU window

The gate transaction lands in block G, the gate runs at G+1, the target's method runs at G+2. Measured single-shard.
Which version runs by when the v2 deploy lands
v2 deploy lands atversion() returns
Gv2
G+1v2
G+2v2 (the local DeployContract receipt runs first in the same block)
G+3v1
self-upgrade via promise, sent at Gv2

The window is at least 3 blocks after the gate transaction, plus the delay between the observer's check and submission. This is a lower bound. Multi-shard is untested. The gate can refuse the next transaction to a changed target; it cannot stop one already in flight.

Global contracts: where monitors go blind

By account id, the owner redeploys v2 and no transaction touches the user's account.
Before and after the owner redeploys
FieldBeforeAfter
view_account.code_hash1111…1111 (zero hash)1111…1111, unchanged
view_account.global_contract_account_idowner.sandboxunchanged
view_code.hash73ETF… (v1)J2gKR… (v2), changed
version()v1v2

New code is active 3 blocks after the owner's deploy. A trigger keyed on view_account.code_hash never sees this change. Watch view_code (the resolved hash) or DeployGlobalContract on the owner. An account with no contract of its own also reports a zero code_hash, so a zero hash does not mean no code. By hash, an account that still has a full-access key can re-point it with UseGlobalContract (tested: v2 to v1 succeeded).

current_contract_code() is self-introspection only

A host function from nearcore 2.10 (protocol 82), behind the deterministic-account-ids feature.
What current_contract_code returns
Account stateReturns
Local deploylocal:<code hash>
Global by hashglobal_hash:<hash>
Global by accountglobal_account:<owner id> (never a hash)

After the owner redeploys v2 on the by-account path, version() returns v2 and view_code changes, but this function still returns the account id. It must not be used to verify a target: the method wrapping it is written by the target, and malicious code can lie.

Gas keys (NEP-611)

Aruna does not use gas keys. Agents are function-call keys on the vault with a classic allowance. The lab results are kept because the facts remain true. Gas key funds are one-way: an agent without a full key can never withdraw them.

Show the gas key results
Gas key scenarios
ScenarioResult
AddKey with balance > 0rejected: AddGasKeyWithNonZeroBalance (balance cannot be set at AddKey)
Batch [CreateAccount, Transfer, AddKey(balance 0), TransferToGasKey]accepted
Factory contract via promise batchaccepted
Parent TransferToGasKey afterwardsaccepted
Unrelated account TransferToGasKeyaccepted (top-up is permissionless)
Third-party contract promise_batch_action_transfer_to_gas_keyaccepted
DelegateV2 with the agent as senderrejected: RemovedProtocolFeature { protocol_feature: "DelegateV2", version: 88 }
Withdrawal by the parentrejected: ActorNoPermission
Withdrawal by the agent's gas keyrejected: RequiresFullAccess
Gas key exhaustedrejected: NotEnoughGasKeyBalance { balance: "1", cost: "30919103596387000000000" }

Mainnet measurement

The 1,000 mainnet accounts that received the most function calls between 2026-10-09 and 2026-11-08, classified from public RPC on 2026-11-09. A state read at one point in time: it says which contracts can change, not how often they did.
Class distribution, 997 classified accounts
ClassAccountsShareCalls receivedShare of calls
immutable_verified545.4%255,2580.4%
local_upgradeable81982.1%61,518,58898.8%
global_by_account30.3%10,8220.0%
unknown12112.1%461,3040.7%

98.8% of the calls went to local_upgradeable contracts. 44.2% went to contracts where a full-access key exists, so its holder can replace the code at any moment. 54.6% went to contracts with no full-access key whose code still imports a deploy, full-access-key or delete-account host function: an upgrade path cannot be ruled out, though it may have no reachable route.

Why each class holds
BasisClassAccountsShareShare of calls
no_detected_pathimmutable_verified545.4%0.4%
full_access_keylocal_upgradeable19719.8%44.2%
upgrade_importslocal_upgradeable61761.9%54.6%
own_codelocal_upgradeable50.5%0.0%
global_ownerglobal_by_account30.3%0.0%
undeterminedunknown12112.1%0.7%

The invisible class exists on mainnet and is rare here. 3 of 997 accounts (0.3%) are global_by_account: 0x4e4542dd.c.aurora, 0x4e4542bc.c.aurora, npoint.noamarket.near. A monitor keyed on view_account.code_hash sees the zero hash for them and misses a redeploy by the publisher. The finding is about monitoring correctness, not frequency. Accounts outside this list were not measured.

3 accounts could not be classified because the read failed (embr.playember_reserve.near, near, contract.dollaaa.near); a failed read is never counted as unknown. Source: measurement/results/2026-11-10, blocks 223,796,370 to 223,797,070. Method and limits: measurement/REPORT.md. Reproduce: pnpm measure, then node apps/web/scripts/sync-measurement.mjs measurement/results/2026-11-10.