Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Patterns of False Positives for Transaction Field based detectors #95

Open
S3v3ru5 opened this issue Aug 17, 2022 · 0 comments
Open

Comments

@S3v3ru5
Copy link
Contributor

S3v3ru5 commented Aug 17, 2022

Detectors such as feeCheck, canCloseAccount, canCloseAsset, rekeyTo traverse the CFG and detect if there's a check involving a transaction field.

txn [Fee | CloseTo | AssetCloseTo | RekeyTo]
[int ... | (addr ... | global ZeroAddress)]
[ == | < | > | .. ]

The same checks could be implemented following different patterns:
1.) Verifies transaction index in the group and then checks the transaction field by accessing it with gtxn INDEX FIELD. issue #75
e.g

txn GroupIndex
int 0
==
assert
gtxn 0 AssetCloseTo
global ZeroAddress
==
assert

2.) Verify the GroupSize is certain value and verify fields of all transactions in the group. issue #87
e.g

global GroupSize
int 2
==
...
gtxn 0 CloseRemainderTo
global ZeroAddress
==
&&
gtxn 1 CloseRemainderTo
global ZeroAddress
==
&&
...

3.) Using a loop to iterate over all transactions in the group and verifying the transaction field.
e.g

12: int 0
13: store 9

14: label1:
15: load 9
16: Gtxns RekeyTo
17: global ZeroAddress
18: ==
19: assert
20: load 9
21: int 1
22: +
23: store 9
24: load 9
25: global GroupSize
26: <
27: bnz label1

Few false positives stem from not using pruning for stateless detectors.
e.g. Account can be closed only if the transaction is a payment transaction. canCloseAccount doesn't need to explore paths where the path is taken only if transaction type is not payment. And also canCloseAccount can only explore paths which are taken if and only if the transaction type is payment. Similar pruning conditions can be considered for canCloseAsset detector.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant