Skip to content
Business logic Audit finding Intermediate

Inconsistency in sender address when creating cross chain messages on Starknet can lead to loss of funds

The cross-chain settlement function stored the contract's own address as the sender in the transaction record, while the emitted event used the actual caller's address. This inconsistency could cause off-chain validators to process transactions incorrectly, potentially leading to stuck funds.

Audinarey Follow with AllTooWell, said and 7 others

Originally disclosed on Code4rena

Submitted by Audinarey, also found by AllTooWell, said, fyamf, SBSecurity, b0g0, Tigerfrake, mojito_auditor, Draiakoo, and jasonxiale

Lines of code

https://github.com/code-423n4/2024-08-chakra/blob/d0d45ae1d26ca1b87034e67180fac07ce9642fd9/cairo/handler/src/handler_erc20.cairo#L188

https://github.com/code-423n4/2024-08-chakra/blob/d0d45ae1d26ca1b87034e67180fac07ce9642fd9/cairo/handler/src/handler_erc20.cairo#L222

Impact

  • Funds could get stuck in the handler_erc20.cairo contract.
  • Validators can evaluate transactions wrongly.

Proof of Concept

In the handler_erc20::cross_chain_erc20_settlement(...) function, the tx_id is saved with the CreatedCrossChainTx struct which contains info about the transaction including the sender whose account the token was transferred from.

However, on L188 the from value is supposed to be the caller’s address, but the handler_erc20 address is used instead of the get_caller_address().

Moreso, the event that are being used by the validators uses from: get_caller_address(),.

File: handler_erc20.cairo
167:         fn cross_chain_erc20_settlement(ref self: ContractState, to_chain: felt252, to_handler: u256, to_token: u256, to: u256, amount: u256) -> felt252{
168:             assert(self.support_handler.read((to_chain, to_handler)), 'not support handler');
169:             let settlement = IChakraSettlementDispatcher {contract_address: self.settlement_address.read()};
170:             let from_chain = settlement.chain_name();
171:             let token = IERC20Dispatcher{contract_address: self.token_address.read()};
172:             let token_burnable = IERC20MintDispatcher{contract_address: self.token_address.read()};
173:             if self.mode.read() == SettlementMode::MintBurn{
174:                 token.transfer_from(get_caller_address(), get_contract_address(), amount);
SNIP        .......
182:
183:             let tx_id = LegacyHash::hash(get_tx_info().unbox().transaction_hash, self.msg_count.read());
184:             let tx: CreatedCrossChainTx = CreatedCrossChainTx{
185:                     tx_id: tx_id,
186:                     from_chain: from_chain,
187:                     to_chain: to_chain,
188:     @>              from: get_contract_address(), // @audit 8) wrong address used for sender when creating cc tx SUGG: replace with get_caller_address()
189:                     to: to,
190:                     from_token: self.token_address.read(),
191:                     to_token: to_token,
192:                     amount: amount,
193:                     tx_status: CrossChainTxStatus::PENDING
194:                 };

SNIP        .......

219:             self.emit(
220:                     CrossChainLocked{
221:                         tx_id: tx_id,
222:                         from: get_caller_address(),
223:                         to: to,
224:                         from_chain: get_tx_info().unbox().chain_id,
225:                         to_chain: to_chain,
226:    @>                   from_token: self.token_address.read(),
227:                         to_token: to_token,
228:                         amount: amount
229:                     }
230:                 );
231:             return tx_id;
232:         }

The problem is that

  • Since it is not clear from the audit README or the Docs how the validators would use the event, the event contains both the tx_id (formed with a wrong from value) and the correct from value, transactions could be processed erroneously.
  • If the transactions are processed wrongly, then the funds could be stuck in the contract. Without a way to retrieve them, this is a loss to the user.

Recommended Mitigation Steps

Modify the handler_erc20::cross_chain_erc20_settlement(...) function as shown below:

File: handler_erc20.cairo
167:         fn cross_chain_erc20_settlement(ref self: ContractState, to_chain: felt252, to_handler: u256, to_token: u256, to: u256, amount: u256) -> felt252{
168:             assert(self.support_handler.read((to_chain, to_handler)), 'not support handler');
169:             let settlement = IChakraSettlementDispatcher {contract_address: self.settlement_address.read()};
170:             let from_chain = settlement.chain_name();
171:             let token = IERC20Dispatcher{contract_address: self.token_address.read()};
172:             let token_burnable = IERC20MintDispatcher{contract_address: self.token_address.read()};
173:             if self.mode.read() == SettlementMode::MintBurn{
174:                 token.transfer_from(get_caller_address(), get_contract_address(), amount);
SNIP        .......
182:
183:             let tx_id = LegacyHash::hash(get_tx_info().unbox().transaction_hash, self.msg_count.read());
184:             let tx: CreatedCrossChainTx = CreatedCrossChainTx{
185:                     tx_id: tx_id,
186:                     from_chain: from_chain,
187:                     to_chain: to_chain,
-188:                    from: get_contract_address(),
+188:                    from: get_caller_address(),
189:                     to: to,
190:                     from_token: self.token_address.read(),
191:                     to_token: to_token,
192:                     amount: amount,
193:                     tx_status: CrossChainTxStatus::PENDING
194:                 };

SNIP        .......

219:             self.emit(
220:                     CrossChainLocked{
221:                         tx_id: tx_id,
222:                         from: get_caller_address(),
223:                         to: to,
224:                         from_chain: get_tx_info().unbox().chain_id,
225:                         to_chain: to_chain,
226:                         from_token: self.token_address.read(),
227:                         to_token: to_token,
228:                         amount: amount
229:                     }
230:                 );
231:             return tx_id;
232:         }

zvlwwj (Chakra) confirmed via duplicate issue #174

0xsomeone (judge) commented:

The Warden has identified an inconsistency in the way cross-chain message events are emitted and stored when the handler_erc20::cross_chain_erc20_settlement function is invoked.

Given that the documentation of the project is inadequate to properly assess the severity of the event emissions, I believe that estimating this discrepancy as a high-severity issue is appropriate given that events are usually imperative to the proper function of cross-chain bridges.

Abdessamed (warden) commented:

This is QA. There is indeed a wrong from set on the created struct, BUT, this information is not used anywhere else that could result in meaningful impact because:

  • The tokens are correctly locked or burned from the caller, and the Chakra nodes rely on the to argument to mint/unlock the tokens on the destination chain.

0xsomeone (judge) decreased severity to Medium and commented:

After re-evaluating this particular submission, I am inclined to downgrade it to medium severity.

I agree with @Abdessamed in that the event is actually emitted with the correct parameters but the struct is stored incorrectly which would normally make it QA, however, we have no way of knowing (nor can we make any assumptions about) how the nodes operate.

At the very least, off-chain software that attempts to showcase which transactions a user has made will fail to do so properly. In a worst-case scenario, failed transaction refunds (which we all know are nowhere implemented within the code but could theoretically be handled off-chain) would fail to be credited to the correct recipient. In a worst-case scenario, all transactions could fail to be processed due to the off-chain software attempting to validate the event’s data with the data stored on the chain.

I personally believe that the code of the Chakra nodes would hint toward a QA severity rating for this submission, however, I am inclined to consider it a medium-risk issue due to the known impact outlined above and the unknown possibility of a higher severity impact.


The original report as published on Code4rena, by Audinarey. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 code mistakenly used the contract's address instead of the caller's address when populating the sender field of the transaction record.

Impact

The inconsistency could cause off-chain validators to process transactions erroneously, potentially leading to stuck funds, though the event itself contains the correct sender and the actual token transfer is correct.

What the attacker needed

None

The fix

The sender field in the transaction record should be set to the caller's address instead of the contract's address.

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.

When you send tokens across chains, the contract records who sent them. Here, the record saved the contract's own address instead of yours, while the public announcement of the transfer used your real address. If the system that processes these transfers relies on the record, it might send funds to the wrong place or get confused, and your money could get stuck.

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.

More by Audinarey

View all

10 more disclosed reports, best first.

More from Chakra

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.