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

Find transaction in transaction group by id #778

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MetaB0y
Copy link

@MetaB0y MetaB0y commented Sep 6, 2022

Without this change txn GroupIndex can inappropriately return -1 despite all fields of tx being the same as all fields of gtxns[x]. Apparently, the reason is that either tx or gtxns can be overwritten at some point by the same content but stored in a different memory location (indexOf uses === which compares objects by reference).

I had this problem when providing liquidity twice in a row in Pact smart contract

This change looks pretty safe, but I don't know if the root cause (change of memory locations) should be found and eliminated in addition or instead of this commit.

Without this change `txn GroupIndex` can inappropriately return `-1` despite all fields of `tx` are the same as all fields of `gtxns[x]`. Apparently, the reason is that either `tx` or `gtxns` can be overwritten at some point by the same content but stored in different memory location (`indexOf` uses `===` which compares objects *by reference*).

I had this problem when providing liquidity twice in a row in Pact smart contract (https://github.com/pactfi/algorand-testbed/blob/master/constant_product.teal)
@MetaB0y
Copy link
Author

MetaB0y commented Sep 7, 2022

Oh, actually it doesn't work for contract-to-contract calls (or inner txs in general) because they don't have ids. Not sure if they should though

@robert-zaremba
Copy link
Member

We should definitely look based on tx id. However yes - we probably need more inspection into that. Thanks for the update!

@robert-zaremba
Copy link
Member

I've updated the PR by using gtxns.find instead of map + indexOf

@robert-zaremba
Copy link
Member

it seams this breaks our tests.

@MetaB0y
Copy link
Author

MetaB0y commented Oct 5, 2022

I've updated the PR by using gtxns.find instead of map + indexOf

But find returns an element, not index. So it doesn't work after this change.

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

Successfully merging this pull request may close these issues.

None yet

2 participants