-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add unique receipts for cross-subnet transactions #125
Conversation
Signed-off-by: Jawad Tariq <[email protected]>
Signed-off-by: Jawad Tariq <[email protected]>
Signed-off-by: Jawad Tariq <[email protected]>
I recommend renaming |
Signed-off-by: Jawad Tariq <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Signed-off-by: Jawad Tariq <[email protected]>
Signed-off-by: Jawad Tariq <[email protected]>
@JDawg287 Let's rename the PR to something not ERC20Messaging-specific? (the problem and the fix concern all messaging protocols) |
sendToken
transactions
Done |
@JDawg287 CI is angry. Seems like a legit problem. :/ |
We'll have to change the |
Description
This PR resolves the issue with the
receiptHash
not being unique for two or more cross-subnet transactions.Problem
Let's try to understand the issue with the following example. For two identical
sendToken
transactions from the same user on the same subnet, i.e. two transactions where the allowance amount and the arguments for thesendToken
transaction are kept the same, we would end up in a situation where thereceiptHash
would also be identical for these two transactions. This is because there is no nonce for receipts as opposed to transactions where a combination offrom
andnonce
is kept track of to prevent replay attacks. If the two transactions end up in different blocks (let's assume there are no other transactions in both blocks), then thereceiptsRoot
for both blocks would also be identical.This isn't a problem on the source subnet, as it is normal to have two blocks with the same
receiptsRoot
but, it is an issue on the target subnet when we try to execute those transactions. The first transaction would be executed normally but the second transaction would be rejected as it has the samereceiptHash
as the first transaction. We were using a combination of thereceiptsRoot
and thereceiptHash
to identify different transactions.So, in a nutshell, we need a method to identify these particular transactions uniquely.
Solution
As a solution, we emit an incrementing
nonce
and thesourceSubnetId
as part of theCrossSubnetMessageSent
event from theToposCore
contract. This would mean that the receiptdata
would contain an incrementing nonce for a particular subnet for eachsendToken
transaction. Since the receipt's trie keeps a record of the receipt'sdata
it would result in a uniquereceiptsRoot
for a block. Furthermore, since thereceiptHash
is calculated from the receipt'sdata
it would result in a uniquereceiptHash
. As a result, this allows us to uniquely identify different valid transactions with similar arguments.Fixes TP-864
PR Checklist: