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

fix: mergeMultisigTransactions logic error #675

Merged
merged 5 commits into from
Nov 1, 2022
Merged

fix: mergeMultisigTransactions logic error #675

merged 5 commits into from
Nov 1, 2022

Conversation

AlgoDoggo
Copy link
Contributor

@AlgoDoggo AlgoDoggo commented Oct 21, 2022

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 is multisigTxnBlobs[0] + the ones from the current iteration of the loop. Thus when exiting the for loop the newSubsigs 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 with

const current = newSubsigs[index];

However 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.

@AlgoDoggo
Copy link
Contributor Author

@barnjamin could I have a bug-fix label so cicd passes plz?

@jasonpaulos
Copy link
Contributor

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).

@scholtz
Copy link

scholtz commented Oct 25, 2022

Please fix mergeMultisigTransactions .. it took us also quite some time that documented functionality does not work.

@AlgoDoggo
Copy link
Contributor Author

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.

Copy link
Contributor

@jasonpaulos jasonpaulos left a 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.

src/multisig.ts Outdated Show resolved Hide resolved
src/multisig.ts Show resolved Hide resolved
@AlgoDoggo
Copy link
Contributor Author

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.

@AlgoDoggo
Copy link
Contributor Author

@jasonpaulos Looks like cicd is failing at the npm ci step, chromedriver won't install. I'd try rerunning the workflows but I do not have permissions for this.

@AlgoDoggo
Copy link
Contributor Author

ah nvm, the dev branch had moved.

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

Successfully merging this pull request may close these issues.

5 participants