-
Notifications
You must be signed in to change notification settings - Fork 205
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
fix: mergeMultisigTransactions logic error #675
Conversation
@barnjamin could I have a bug-fix label so cicd passes plz? |
Hi @AlgoDoggo, thanks for making this PR. I only have one request: can you add a new test that merges > 2 multisigs, since you said that was missing from our test suite? I need to take a closer look at the code changes to be absolutely sure they work as intended, and a new test would help with that effort (in addition to being a regression test). |
Please fix mergeMultisigTransactions .. it took us also quite some time that documented functionality does not work. |
Hey, I've refactored a test to merge three tx instead of two. You can run it solo against the old and new logic to see the diff. |
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.
I believe this code change is correct, and I have independently verified the encoded test transactions.
I only have two small comments about the maintainability of the code.
At some point we'll need to run typescript in strict mode, or at least with strictNullChecks enabled. A lot of values that can be undefined are just assumed to exist now by the sdk. It's bound to cause runtime errors eventually. |
@jasonpaulos Looks like cicd is failing at the |
…into fix_mergeMultisig
ah nvm, the dev branch had moved. |
This bug will manifest when the length of input array is > 2. Because all the mocha tests try to merge only two transactions it wasn't caught.
Essentially you have a for loop that iterates over all the transactions and at every iteration the
newSubsigs
array which should comprise all the pk and signatures from all the txs is overwritten with the the one from the reference case which ismultisigTxnBlobs[0]
+ the ones from the current iteration of the loop. Thus when exiting the for loop thenewSubsigs
array is made of the signatures available in the reference tx + the last tx. All the other transactions signatures get overwritten.It it is possible to fix this bug with a one-liner, right at the beginning of the map it would be enough to replace
current
withHowever this whole function in general is a little clunky so I couldn't help refactoring slightly the
map
statement to avoid nested if statement and such. The for loop too can be instantiated at index 1 since index 0 is the base case calculated above. If you don't like style changes the one-liner above is enough to do the job.