Get_state_proof() is called with the current version leading to the epoch_changes of the StateProof always being empty
When a block is executed, the state proof is requested using the version after the block rather than before it, so the epoch change branch is never taken. This makes the epoch_changes of the state proof always empty, which can produce an invalid block commitment.
Originally disclosed on Immunefi
- Disclosed after under an hour
#43312 [BC-Medium] get_state_proof() is called with the current version leading to the epoch_changes of the StateProof always being empty
Submitted on Apr 4th 2025 at 14:00:01 UTC by @HollaDieWaldfee for Attackathon | Movement Labs
- Report ID: #43312
- Report Type: Blockchain/DLT
- Report severity: Medium
- Target: https://github.com/immunefi-team/attackathon-movement/tree/main/protocol-units/execution/maptos/opt-executor
- Impacts:
- A bug in the respective layer 0/1/2 network code that results in unintended smart contract behavior with no concrete funds at direct risk
Description
Brief/Intro
When executing a block, get_state_proof() is called but with the wrong version. As a result, the epoch_changes of the StateProof is always going to be empty, producing an invalid block commitment.
Vulnerability Details
After a block is executed, get_state_proof() is called with the version being the state_compute.version() after the new block is executed. This version is the current version and as a result, when get_state_proof_with_ledger_info() is called, it always enters the else-block which returns a StateProof with empty epoch_changes:
fn get_state_proof_with_ledger_info(
&self,
known_version: u64,
ledger_info_with_sigs: LedgerInfoWithSignatures,
) -> Result<StateProof> {
gauged_api("get_state_proof_with_ledger_info", || {
let ledger_info = ledger_info_with_sigs.ledger_info();
ensure!(
known_version <= ledger_info.version(),
"Client known_version {} larger than ledger version {}.",
known_version,
ledger_info.version(),
);
let known_epoch = self.ledger_db.metadata_db().get_epoch(known_version)?;
let end_epoch = ledger_info.next_block_epoch();
let epoch_change_proof = if known_epoch < end_epoch {
let (ledger_infos_with_sigs, more) =
self.get_epoch_ending_ledger_infos(known_epoch, end_epoch)?;
EpochChangeProof::new(ledger_infos_with_sigs, more)
@> } else {
EpochChangeProof::new(vec![], /* more = */ false)
};
Ok(StateProof::new(ledger_info_with_sigs, epoch_change_proof))
})
}
Instead, get_state_proof() should be called with the version BEFORE the block is executed such that a change in the epoch can be detected in the if-case.
Impact Details
The epoch_changes of the state proof after executing a block is always going to be empty.
As a result, the block commitment that is calculated from the state proof can be invalid:
let commitment = Commitment::digest_state_proof(&proof);
Ok(BlockCommitment::new(block_height.into(), Id::new(*block_id.clone()), commitment))
References
Proof of Concept
Proof of Concept
- During the block execution flow,
execute_block()is called. After the block is executed,get_state_proof()is called. However, this function is called with the wrong version, namely the version after the block is executed (reference (1)). - As a result,
get_state_proof_with_ledger_info()always returns a StateProof with empty epoch_changes sinceknown_epoch == end_epochand the function always enters the else-block.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the state proof is requested with the post-execution version instead of the pre-execution version, so the known epoch equals the end epoch and the epoch change branch is skipped.
Impact
The epoch_changes of the state proof after executing a block is always empty, so the block commitment calculated from the state proof can be invalid.
What the attacker needed
None
The fix
get_state_proof() should be called with the version before the block is executed so an epoch change can be detected.
How it was found
- Execute a block through the block execution flow.
- Observe that get_state_proof() is called with the version after the block is executed.
- See that get_state_proof_with_ledger_info() returns a state proof with empty epoch_changes because known_epoch equals end_epoch.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A blockchain node periodically groups blocks into periods called epochs, and when it hands out a proof about its state it should include a record of any epoch change. Here the code asks for that proof using a version number that is already past the change, so the check that would include the change always fails and the proof comes back with an empty list. That can make the commitment, a fingerprint of the block, wrong.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.