Repository navigation
feat(precompiles): read and write account config commitments from precompile storage - #8482
Conversation
…compile storage Adds config-commitment reads and writes to precompile storage, with the TIP-1108 write charges and an InvalidConfigCommitmentWrite error. Nothing calls them yet; only the in-memory provider stores commitments. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
cyclops audit fast note="7510 is the PR for the TIPs. This Pr only adds account config commitment reads and writes to precompile storage" |
✅ Cyclops Security Review: safe to mergeLast reviewed: 24b781f (latest) · no open findings |
…he storage module patterns The write check had one caller, the in-memory provider, so it moves into it. The static-context override joins the test-utils fixture setters, imports join the existing storage imports, and the error message is capitalized like its neighbours. The EVM read test now also pins that a read touches the account it was asked about. Co-Authored-By: Claude Opus 5.5 <[email protected]>
📊 Tempo Precompiles Coverage |
| Intrinsic, | ||
| /// Charge the explicit precompile operation here: the field write, plus TIP-1000's | ||
| /// new-account cost (regular and state gas) when the write finds the account still empty. | ||
| Precompile, | ||
| } | ||
|
|
||
| impl ConfigCommitmentWriteGas { | ||
| fn cost(self, previous: B256) -> Result<u64> { | ||
| match self { | ||
| Self::Intrinsic if previous.is_zero() => Ok(0), | ||
| Self::Intrinsic => Err(TempoPrecompileError::InvalidConfigCommitmentWrite), | ||
| Self::Precompile if previous.is_zero() => Ok(CONFIG_COMMITMENT_REGISTRATION_GAS), | ||
| Self::Precompile => Ok(CONFIG_COMMITMENT_UPDATE_GAS), | ||
| } | ||
| } |
There was a problem hiding this comment.
🟡 (optional) A precompile writing to a still-empty account would be undercharged, because the documented TIP-1000 new-account cost is never charged. The doc comment on ConfigCommitmentWriteGas::Precompile says that cost (regular and state gas) is included. cost() at mod.rs:55-56 returns only CONFIG_COMMITMENT_REGISTRATION_GAS (20,000) or 5,000. It never checks whether the account is empty. Fix: either charge the TIP-1000 new-account cost in the Precompile path when the account is empty, or change the doc so the planned multisig caller knows to charge it itself.
Why this was flagged
The doc comment at crates/precompiles/src/storage/mod.rs:46-47 says the Precompile variant charges "the field write, plus TIP-1000's new-account cost (regular and state gas) when the write finds the account still empty". ConfigCommitmentWriteGas::cost at mod.rs:51-59 looks only at previous. It returns 20,000 or 5,000 and never reads account emptiness or adds any new-account or state gas. The only implementation, HashMapStorageProvider::set_config_commitment at hashmap.rs:304-318, just calls deduct_gas(gas.cost(previous)?), and nothing else adds the cost. The PR says the native multisig precompile will be the first caller. If it trusts this doc, it will not charge new-account gas itself, so registering a commitment on an empty account would be underpriced compared with what TIP-1000 requires. There is no base behaviour to compare against because this API is new, and nothing guards against the doc and code disagreeing.
Verification: Trigger: a Precompile-mode write to an account that is still empty. The doc comment at crates/precompiles/src/storage/mod.rs:46-47 says the Precompile variant charges TIP-1000's new-account cost, but ConfigCommitmentWriteGas::cost (mod.rs:51-59) only looks at previous and never checks whether the account is empty. So the code charges less than its own documented contract.
There was a problem hiding this comment.
The doc covers the whole Precompile charge, not just cost(). cost() is the field write; the TIP-1000 new-account cost is added by the EVM write path when the account is still empty. That path isn't on main yet (the EVM provider rejects every commitment write here) and lands with the stack:
tempo/crates/precompiles/src/storage/evm.rs
Lines 455 to 461 in 51aa733
| /// Reads the commitment with normal account-access gas. | ||
| /// Providers that cannot store commitments report zero for every account. | ||
| fn config_commitment(&mut self, address: Address) -> Result<B256> { | ||
| self.with_account_info(address, &mut |_| {})?; | ||
| Ok(B256::ZERO) | ||
| } | ||
|
|
||
| /// Writes an authorized nonzero commitment through the account journal. | ||
| /// Callers must validate registration, rotation, or migration authority first. | ||
| /// Account-access gas belongs to that authorization read; this method charges | ||
| /// only what `gas` names, or nothing when registration was charged intrinsically. | ||
| /// Providers that cannot store commitments reject every write. | ||
| fn set_config_commitment( | ||
| &mut self, | ||
| _address: Address, | ||
| _commitment: B256, | ||
| _gas: ConfigCommitmentWriteGas, | ||
| ) -> Result<()> { | ||
| Err(TempoPrecompileError::InvalidConfigCommitmentWrite) | ||
| } |
There was a problem hiding this comment.
note: would be nice to drop default impls once we enable revm's account-ext cfg and do the actual evm impl
…red (tempoxyz#8486) Stacked on tempoxyz#8502 (the configurable account rename); merge after it. Adds the configurable account precompile (`IConfigurableAccount`): account derivation, config updates and `upgradeAccount`, which installs a version-one config commitment through tempoxyz#8482's precompile storage. It is not registered at an address yet, so nothing on main can call it; the stack registers it at T14. --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]>
Adds
config_commitmentandset_config_commitmenttoPrecompileStorageProviderandStorageCtx, so a precompile can read and write an account's config commitment. Writes need T14, a nonzero commitment and a non-static call, and an intrinsic write needs an empty commitment.Main has no account extension yet, so the EVM provider reads zero and rejects every write;
HashMapStorageProviderkeeps commitments in a side map for tests. Nothing calls it yet: the native multisig precompile is the first user.