Invalid token address used in ChakraSettlementHandler::cross_chain_erc20_settlement(...) leading to invalid transaction creation and event emission
The ChakraSettlementHandler contract incorrectly uses its own address instead of the token address when recording a cross-chain transaction and emitting the CrossChainLocked event. This could cause validators to process incorrect token information, potentially leading to failed or misdirected settlements.
0xb0k0 Follow with AllTooWell, rbserver and 15 others
Originally disclosed on Code4rena
Submitted by 0xb0k0, also found by AllTooWell, rbserver, said, shaflow2, fyamf, Abdessamed, SBSecurity, calfun0x, joicygiore, ABAIKUNANBAEV, Coinymous, Audinarey, b0g0, gajiknownnothing, mojito_auditor, devival, and jasonxiale
Lines of code
Impact
The ChakraSettlementHandler incorrectly passes the contract address instead of the token one, when creating the create_cross_txs transaction and when emitting the CrossChainLocked event. The contract depends heavily on correct event emission as the protocol’s validators listen for these events and execute state-changing operations based on them.
Proof of Concept
The ChakraSettlementHandler::cross_chain_erc20_settlement(...) function processes incoming cross-chain settlement user requests and sends data to the settlement contract. The method creates CreatedCrossChainTx along the way:
struct CreatedCrossChainTx {
uint256 txid;
string from_chain;
string to_chain;
address from;
uint256 to;
address from_token;
uint256 to_token;
uint256 amount;
CrossChainTxStatus status;
}
However, in the current implementation, instead of sending the from_token address it sends the actual contract address:
create_cross_txs[txid] = CreatedCrossChainTx(
txid,
chain,
to_chain,
msg.sender,
to,
@> address(this), // @audit - this should be the global variable `token`
to_token,
amount,
CrossChainTxStatus.Pending
);
When the transaction is sent to the settlement contract a CrossChainLocked is emitted:
event CrossChainLocked(
uint256 indexed txid,
address indexed from,
uint256 indexed to,
string from_chain,
string to_chain,
address from_token,
uint256 to_token,
uint256 amount,
SettlementMode mode
);
However, the method, once more sends the incorrect from_token address:
emit CrossChainLocked(
txid,
msg.sender,
to,
chain,
to_chain,
@> address(this), // @audit - this should be the global variable `token`
to_token,
amount,
mode
);
If we peek into the Cairo implementation we can see that the from_token address should indeed be the token address not the handler contract address:
fn cross_chain_erc20_settlement(ref self: ContractState, to_chain: felt252, to_handler: u256, to_token: u256, to: u256, amount: u256) -> felt252{
__SNIP__
let tx: CreatedCrossChainTx = CreatedCrossChainTx{
tx_id: tx_id,
from_chain: from_chain,
to_chain: to_chain,
from: get_contract_address(),
to: to,
@> from_token: self.token_address.read(), // proper token address passed
to_token: to_token,
amount: amount,
tx_status: CrossChainTxStatus::PENDING
};
__SNIPP
self.emit(
CrossChainLocked{
tx_id: tx_id,
from: get_caller_address(),
to: to,
from_chain: get_tx_info().unbox().chain_id,
to_chain: to_chain,
from_token: self.token_address.read(), // proper token address passed
to_token: to_token,
amount: amount
}
);
return tx_id;
}
Recommended Mitigation Steps
Use the correct from_token address in ChakraSettlementHandler::cross_chain_erc20_settlement(...).
diff --git a/solidity/handler/contracts/ChakraSettlementHandler.sol b/solidity/handler/contracts/ChakraSettlementHandler.sol
index 5d31ef9..b9cbd6d 100644
--- a/solidity/handler/contracts/ChakraSettlementHandler.sol
+++ b/solidity/handler/contracts/ChakraSettlementHandler.sol
@@ -157,7 +157,7 @@ contract ChakraSettlementHandler is BaseSettlementHandler, ISettlementHandler {
to_chain,
msg.sender,
to,
- address(this),
+ token,
to_token,
amount,
CrossChainTxStatus.Pending
@@ -215,7 +215,7 @@ contract ChakraSettlementHandler is BaseSettlementHandler, ISettlementHandler {
to,
chain,
to_chain,
- address(this),
+ token,
to_token,
amount,
mode
pidb (Chakra) confirmed via duplicate issue #175
0xsomeone (judge) increased severity to High and commented:
The Warden has identified an invalid
eventemission and transaction data storage both of which are imperative to the proper operation of a cross-chain bridge system.The documentation of the project does not adequately detail how those events are consumed, and inspection of the project’s
cairocode as well as the sponsor’s own affirmation on issue #175 confirms the present implementation is incorrect.I believe a high-risk issue is acceptable for this submission due to how crucial those components are to the proper operation of a cross-chain bridge.
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 code uses `address(this)` (the handler contract's address) instead of the `token` state variable when populating the `from_token` field in the transaction struct and the event.
Impact
Validators relying on the event and stored transaction data may process incorrect token information, potentially causing failed or misdirected cross-chain settlements.
What the attacker needed
None
The fix
The code should be fixed by replacing `address(this)` with the `token` variable in both the transaction creation and the event emission.
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.
In a cross-chain bridge, a contract on one blockchain locks tokens and emits an event so that validators on another chain know to release the equivalent tokens. This report found that the contract was putting its own address where the token's address should be, both in its internal records and in the event it emitted. That mistake could confuse the validators and break the transfer.
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.