Oracles are vulnerable to cross-chain replay attacks
The oracle contract hard-codes a salt derived from the chain ID at construction time, so signatures for price updates do not include the current chain ID. After a hard fork, a keeper could replay a signature from the original chain on the forked chain, potentially causing invalid execution prices or liquidations.
Source: https://github.com/sherlock-audit/2023-02-gmx-judging/issues/152
Found by
IllIllI
Summary
Oracles are vulnerable to cross-chain replay attacks
Vulnerability Detail
If there's a hard fork (e.g. miner vs proof of stake), signatures/txns submitted on one chain can be replayed on the other chain.
Impact
Keepers on the forked chain can use oracle prices from the original chain, even though they may not be correct for the current chain (e.g. USDC's price on the fork may be worth zero until Circle adds support on that fork), leading to invalid execution prices and or liquidations.
Code Snippet
The SALT used in signatures is hard-coded to an immutable variable in the constructor, and uses the block.chainid from the time of construction:
// File: gmx-synthetics/contracts/oracle/Oracle.sol : Oracle.constructor() #1
108 constructor(
109 RoleStore _roleStore,
110 OracleStore _oracleStore
111 ) RoleModule(_roleStore) {
112 oracleStore = _oracleStore;
113
114 // sign prices with only the chainid and oracle name so that there is
115 // less config required in the oracle nodes
116 @> SALT = keccak256(abi.encode(block.chainid, "xget-oracle-v1"));
117: }
Signatures use the SALT without also including the block.chainid separately
Tool used
Manual Review
Recommendation
Include the block.chainid in the signature, separately from the SALT, and ensure that the value is looked up each time
Discussion
hack3r-0m
Escalate for 10 USDC
This finding should be invalid, because keepers are trusted entity as mentioned in REAMDE and signature of keeper on longest chain cannot be used on forks because of check that only keeper can update price.
sherlock-admin
Escalate for 10 USDC
This finding should be invalid, because keepers are trusted entity as mentioned in REAMDE and signature of keeper on longest chain cannot be used on forks because of check that only keeper can update price.
You've created a valid escalation for 10 USDC!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
IllIllI000
The readme says, Order keepers and frozen order keepers could potentially extract value through transaction ordering, delayed transaction execution etc, this will be partially mitigated with a keeper network so they are not fully-trusted entities
hrishibhat
Escalation rejected
Admin is restricted and keepers are trusted only to perform the actions assigned to them. As pointed out by the Lead watson, Keepers are not fully trusted entities
sherlock-admin
Escalation rejected
Admin is restricted and keepers are trusted only to perform the actions assigned to them. As pointed out by the Lead watson, Keepers are not fully trusted entities
This issue's escalations have been rejected!
Watsons who escalated this issue will have their escalation amount deducted from their next payout.
xvi10
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
The signature salt is computed once in the constructor using the chain ID at deployment, and the chain ID is not included separately in each signature, so signatures remain valid across a hard fork.
Impact
Keepers on the forked chain could use oracle prices from the original chain, which may be incorrect for the fork, leading to invalid execution prices or liquidations.
What the attacker needed
A hard fork occurs; keeper is not fully trusted
The fix
The fix was to include the current chain ID in the signature separately from the salt and look it up each time.
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 can split into two separate chains (a hard fork). If a signature authorising a price update is valid on both chains, someone can reuse it on the other chain. Here, the signature did not include the current chain's identity, so a keeper could replay old price data on the forked chain.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.