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

feat: add support for SEP-0010. #264

Merged

Conversation

overcat
Copy link
Member

@overcat overcat commented Jan 30, 2020

This resolves #263 and resolves #235.

Feel free to add comments if you have any questions.

Thanks.

@overcat overcat changed the title [WIP] feat: add support for SEP-0010. feat: add support for SEP-0010. Jan 31, 2020
@leighmcculloch leighmcculloch self-assigned this Jan 31, 2020
@tamirms
Copy link
Contributor

tamirms commented Jan 31, 2020

@overcat thank you for your contribution!

I think if you use Sets and Maps instead of List the code will be simpler. Let me know what you think.

Copy link
Contributor

@leighmcculloch leighmcculloch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @overcat ! A few things inline:

leighmcculloch added a commit to stellar/go that referenced this pull request Feb 3, 2020
### What
Ignore txhash (T...) signers, used for preauth transactions, xhash (X...)
signers, and other future types of signers the server might not know
about, during SEP-10 verification.

### Why
Developers will likely pass through to the verification functions the
signers on accounts as provided by Horizon. Accounts can have other
non-ed25519 signers and they're likely going to be passed through
verbatim. The verification logic's goal is to confirm the transaction
has been signed by the signers and so ignoring unsupported types like
txhash and xhash seems like a safe thing to do given that the
verification function will also ignore ed25519 signers that don't match
a signature.

Without this in a typical SEP-10 implementation any account with a
txhash or xhash signer will likely fail SEP-10 verification.

Issues that might be caused by this new behavior is if a user passes in
an account seed (S...) or some other string they won't see an error.
I think that's unlikely and hopefully a smaller impact than is worth
making this solution more complex.

This issue was first identified by @overcat in lightsail-network/java-stellar-sdk#264,
but solved in a way that depends on data from Horizon. This solution
does not depend on data from Horizon and should be portable to all our
SDKs. This was previously discussed at:
lightsail-network/java-stellar-sdk#264 (comment).
Copy link
Contributor

@tamirms tamirms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@overcat great job, this looks good to me! I will defer to @leighmcculloch for the final approval before we can merge

@leighmcculloch
Copy link
Contributor

leighmcculloch commented Feb 6, 2020

I will defer to @leighmcculloch for the final approval before we can merge

@tamirms Thanks, I've got it in my queue to do a final pass over this PR and I hope to get to it before the end of this week.

@overcat Before I do a final pass, I noticed that during my first pass the number of tests seemed smaller than the number of tests we have in the Go SDK. We need to make sure we're covering at least the same test scenarios that are there. I haven't dug into the specifics of the tests here yet, but are there less tests because you combined some of the scenarios or are we missing some?

@overcat
Copy link
Member Author

overcat commented Feb 7, 2020

Hi, @leighmcculloch, thank you for your reminder, I will add more tests later.

When I checked the test code of Golang, I found that the behavior of TestReadChallengeTx_invalidNotSignedByServer was different from what I expected. This should be a bug, maybe this line should be changed to if tx.xdrEnvelope.Signatures == nil {

@leighmcculloch
Copy link
Contributor

leighmcculloch commented Feb 7, 2020

When I checked the test code of Golang, I found that the behavior of TestReadChallengeTx_invalidNotSignedByServer was different from what I expected. This should be a bug, maybe this line should be changed to if tx.xdrEnvelope.Signatures == nil {

Good catch, that if statement is guarding on the event someone passes a Transaction that has no xdrEnvelope, and it is not really testing if the transaction has signatures and the error being returned at that if statement has misleading text. However, I believe the test TestReadChallengeTx_invalidNotSignedByServer is still accurate in its expectations. Let me know if you think otherwise.

thank you for your reminder, I will add more tests later.

Thanks! Please mention me when you've added the tests and I'll take another look, and feel free to mention me if you see any other issues with the tests too. Thanks!

@overcat
Copy link
Member Author

overcat commented Feb 7, 2020

Hi @leighmcculloch, I added more tests with reference to the Golang implementation, but I did not add the following tests:

BTW, I think this line should be modified to err = tx.Sign(serverKP, clientKP2).

@leighmcculloch
Copy link
Contributor

@overcat Thanks for reporting the unnecessary signer in that test, I'll get that fixed up in stellar/go#2279.

I agree you don't need to add the duplicate signers test this the language protects against that with the use of a Set. 🎉

Thanks for being so thorough with the addition of more tests. I need a couple days to go over them and to review the questions about the other two tests that you left out. Look out for a follow up from me next week.

Thanks!

Copy link
Contributor

@leighmcculloch leighmcculloch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@overcat I reviewed all the new tests, and they look awesome. I love that you used the same order as in the Go SDK as it made reviewing the tests so much simpler ❤️. We're very close now to merging this. I've left some inline comments below.

💡 – Two ideas for how we could make this easier to use and optimal, but that would be entirely building on what is here, so I think we could keep them for a separate PR once this has merged so we can get this merged sooner. Feel free to ignore these.

👀 – @tamirms Would love your 👀 on this one.

❗️ – A couple very small mistakes to fix up (test names got mixed up I think 😬). Plus I had a look at the two tests you asked about (TestReadChallengeTx_invalidCorrupted, TestReadChallengeTx_invalidDataValueCorruptBase64) and I think we should add them as tests. The code doesn't need to catch a base64 encoding error, we just want to capture those failure scenarios and make sure that if the code behaves one way today when invalid base64 is provided that it continues to behave the same way as the code evolves and is maintained.

weightsForSigner.put(signer.getKey(), signer.getWeight());
}

Set<String> signersFound = verifyChallengeTransactionSigners(challengeXdr, serverAccountId, network, weightsForSigner.keySet());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Any reason we're passing in weightsForSigner.keySet() here and not just signers? It results in creating another copy of the set in memory. This doesn't need to block this PR, but it might be an area to optimize later if it isn't being done for a particular reason.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because in my opinion, the weight of the signer is completely useless for verifyChallengeTransactionSigners, so I don't think it is necessary to pass it in. Of course, memory consumption is a noteworthy point, thank you for your reminder.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but you can pass in the signers value which is one of the function parameters and is a Set<String>.

src/test/java/org/stellar/sdk/Sep10ChallengeTest.java Outdated Show resolved Hide resolved
@tamirms tamirms changed the base branch from master to release-0.14.0 February 19, 2020 17:35
@leighmcculloch

This comment has been minimized.

Copy link
Contributor

@leighmcculloch leighmcculloch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Thanks for the huge effort and thorough testing @overcat !

@overcat
Copy link
Member Author

overcat commented Feb 20, 2020

@leighmcculloch, @tamirms

Thank you both for your hard work, you have really given me a lot of help, and I have gained a lot here.

Thank you sincerely. ❤️

@leighmcculloch leighmcculloch merged commit b7ea488 into lightsail-network:release-0.14.0 Feb 20, 2020
@overcat overcat deleted the dev-sep10 branch February 20, 2020 01:14
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.

Update challenge transaction helpers for SEP-10 v1.3.0 Support for SEP 10 challenge transaction
3 participants