-
Notifications
You must be signed in to change notification settings - Fork 22
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
Add support for hashing SCPStatement & SCPEnvelope #546
Conversation
01bfd25
to
0d0fbb4
Compare
Codecov Report
@@ Coverage Diff @@
## v0.x.x #546 +/- ##
=========================================
+ Coverage 91.14% 91.25% +0.1%
=========================================
Files 63 63
Lines 4809 4892 +83
=========================================
+ Hits 4383 4464 +81
- Misses 426 428 +2
Continue to review full report at Codecov.
|
0d0fbb4
to
5208e8b
Compare
5208e8b
to
bb21f30
Compare
Is Travis broken all of a sudden? |
static assert(SCPNomination.sizeof == 80); | ||
|
||
/// instance | ||
const SCPStatement st; |
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.
Doesn't that do a copy tho ?
|
||
***************************************************************************/ | ||
|
||
public void computeHash (const ref SCPStatement._pledges_t._prepare_t prep, |
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.
Looks like those could be static ?
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.
Same for the following ones
bb21f30
to
3e936a8
Compare
Fixed the comments. And also added hashing for SCPEnvelope, which just embeds the SCPStatement and the signature. |
5b287cc
to
f4588b4
Compare
Hmm on ldc I am getting different hashes compared to DMD. lol |
I found a weird bug with lambdas. This code is OK: // OK
auto sign_data = pair.secret.sign(msg[]);
() @trusted {
auto sig = sign_data[];
env.signature = sig.toVec();
writefln("\n\nbef: %s", env.signature);
}();
writefln("\n\naft: %s", env.signature); Here the signature will be the same inside the lambda and outside of it. Output:
But if I move the sign data inside the lambda: () @trusted {
// FAIL
auto sign_data = pair.secret.sign(msg[]);
auto sig = sign_data[];
env.signature = sig.toVec();
writefln("\n\nbef: %s", env.signature);
}();
writefln("\n\naft: %s", env.signature); Then the signatures are different:
I've tried |
f4588b4
to
6ebdc4e
Compare
Fixed. Should go green soon. |
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.
Just 3 nits, otherwise LGTM. Feel free to fix and merge at will.
private const SCPStatement* st; | ||
|
||
/// Ctor | ||
public this (const SCPStatement* st) @nogc nothrow @trusted |
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.
public this (const SCPStatement* st) @nogc nothrow @trusted | |
public this (const SCPStatement* st) @nogc nothrow @safe pure |
No ?
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 did not really know ctors can be pure. I'm also surprised a function can be safe when assigning pointers. Oh well.
hashPart(this.st.slotIndex, dg); | ||
hashPart(this.st.pledges.type_, dg); | ||
|
||
switch (this.st.pledges.type_) |
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.
switch (this.st.pledges.type_) | |
final switch (this.st.pledges.type_) |
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 was gonna say that final switch sucks because of https://issues.dlang.org/show_bug.cgi?id=11051
But then I saw that the issue had a PR.. dlang/dmd#6095
lol
private const SCPEnvelope* env; | ||
|
||
/// Ctor | ||
public this (const SCPEnvelope* env) @nogc nothrow @trusted |
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.
public this (const SCPEnvelope* env) @nogc nothrow @trusted | |
public this (const SCPEnvelope* env) @nogc nothrow @safe pure |
Necessary prerequisite for signing SCP messages.
6ebdc4e
to
1d20c65
Compare
Fixed again. |
Drey 0 - Travis 1 |
This will be needed for signing SCP statements.
Edit: Now it's also necessary to fix the issue in #716
I'm not sure where to place this hashing support, other than into the Nominator module because this is the only place it will be used.
I cannot move it to
scpd.types.Stellar_SCP
because this module should not import hashing routines fromagora.*
, and I'm not sureagora.common.Hash
is a good place for it either.Also side-note: maybe there should be a generic way of testing hashing behavior for any struct types. Something like a "fuzzer" type helper function that manipulates each field and verifies that the hash changed.