Submitted by 13u9, also found by joicygiore (1, 2), aldarion (1, 2), Agontuk, pwnforce (1, 2), 0x37 (1, 2), Daniel_eth, Abdessamed (1, 2), kutugu, bhilare_, DPS (1, 2), jasonxiale (1, 2), Cybrid, DanielArmstrong, IzuMan, AllTooWell (1, 2), SBSecurity, Draiakoo, franfran20 (1, 2), Subroutine (1, 2), 0xabhay, 0xpetern, LuarSec, shaflow2 (1, 2, 3), klau5 (1, 2), fyamf (1, 2), gesha17, ZdravkoHr, mojito_auditor, and ABAIKUNANBAEV
There is a problem that anyone can increase another handler contract nonce (nonce_manager) in settlement contract.
nonce_manager is used to make txid
https://github.com/code-423n4/2024-08-chakra/blob/main/solidity/handler/contracts/ChakraSettlementHandler.sol#L139-L150
https://github.com/code-423n4/2024-08-chakra/blob/main/solidity/settlement/contracts/ChakraSettlement.sol#L122-L133
txid is generated using several arguments and the nonce_manager[msg.sender] value as shown above.
https://github.com/code-423n4/2024-08-chakra/blob/main/solidity/handler/contracts/ChakraSettlementHandler.sol#L212-L222
The handler function emits the corresponding txid value as an event.
https://github.com/code-423n4/2024-08-chakra/blob/main/solidity/handler/contracts/ChakraSettlementHandler.sol#L203-L209
https://github.com/code-423n4/2024-08-chakra/blob/main/solidity/settlement/contracts/ChakraSettlement.sol#L118-L133
https://github.com/code-423n4/2024-08-chakra/blob/main/solidity/settlement/contracts/ChakraSettlement.sol#L146-L155
Before the event emit, the handler function calls settlement.send_cross_chain_msg. The send_cross_chain_msg function of settlement also creates a txid and emits an event using this txid.
Through this process, the handler contract and the settlement contract emit the same txid event.
The system processes this emitted txid to handle the task.
However, there is a vulnerability that allows anyone to manipulate the nonce_manager value used when generating txid in the settlement contract with someone elses nonce_manager value, which can cause confusion in the system.
https://github.com/code-423n4/2024-08-chakra/blob/main/solidity/handler/contracts/ChakraSettlementHandler.sol#L139-L150
https://github.com/code-423n4/2024-08-chakra/blob/main/solidity/handler/contracts/ChakraSettlementHandler.sol#L203-L209
When the cross_chain_erc20_settlement function is called in the handler contract, a txid is generated and the send_cross_chain_msg function of the settlement contract is called.
In the send_cross_chain_msg function of the settlement contract, the from_address argument is set to the address of the user who called the cross_chain_erc20_settlement function of the handler set in the handler, the nonce value of the address is increased, and a txid is generated.
Here, the send_cross_chain_msg function is defined as external, so it is a function that can be called by outsiders, and since there is no other access control when increasing the nonce of from_address in nonce_manager, anyone can increase the nonce of a specific users settlement contract.
This can cause an imbalance between the handlers nonce and the settlements nonce, potentially causing system confusion.
Also, if the same user of another handler calls the cross_chain_erc20_settlement function, a mismatch between the user nonce of the handler and the settlement will occur.
https://github.com/code-423n4/2024-08-chakra/blob/main/solidity/handler/test/ChakraSettlementHandler.ts
Write test code in ChakraSettlementHandler.ts file
This test code tests whether the senders (users) nonce value has been manipulated by the Attacker.
Test log
Set the nonce value in the settlement contract to be managed by from_handler
Modify nonce_manager as in the code above so that the users nonce_manager can increase according to the handler.
This operation prevents an attacker from manipulating someone elses nonce by pretending to be a handler, and also prevents nonce collisions between other normal handlers.
pidb (Chakra) confirmed
0xsomeone (judge) commented:
