rlp, p2p, p2p/discover: EIP-8 changes #2091
Conversation
Current coverage is
|
The s2 parameter was not actually written to the MAC.
@obscuren @karalabe @Gustav-Simonsson please review |
@@ -192,11 +192,9 @@ func concatKDF(hash hash.Hash, z, s1 []byte, kdLen int) (k []byte, err error) { | |||
// messageTag computes the MAC of a message (called the tag) as per | |||
// SEC 1, 3.5. | |||
func messageTag(hash func() hash.Hash, km, msg, shared []byte) []byte { | |||
if shared == nil { | |||
shared = make([]byte, 0) | |||
} |
karalabe
Feb 18, 2016
Member
Was this shared
thing never used until now? Why is it only added to the hash now?
Was this shared
thing never used until now? Why is it only added to the hash now?
fjl
Feb 18, 2016
Author
Contributor
We didn't use it until now.
We didn't use it until now.
// decode as a nil pointer. This tag can be useful when decoding recursive | ||
// types. | ||
// decode as a nil pointer. This tag can be useful when decoding | ||
// recursive types. |
karalabe
Feb 18, 2016
Member
Since you explain here how the nil
tag works, please also add how the ..
works.
Since you explain here how the nil
tag works, please also add how the ..
works.
input: "C3010203", | ||
ptr: new(dotdotRaw), | ||
value: dotdotRaw{A: 1, DotDot: []RawValue{unhex("02"), unhex("03")}}, | ||
}, |
karalabe
Feb 18, 2016
Member
Please add a test case where the tag is correctly set, but the input RLP contains something wrong. E.g. you want to parse into a list of strings and one of the elements it an int, not a string. Or something like this, to verify that mixing elements are caught and does not crash or similar.
Please add a test case where the tag is correctly set, but the input RLP contains something wrong. E.g. you want to parse into a list of strings and one of the elements it an int, not a string. Or something like this, to verify that mixing elements are caught and does not crash or similar.
karalabe
Feb 18, 2016
Member
Also it would be nice to see examples tests where:
..
is used, but only one element is supplied
..
is used, but 0 elements are supplied
Also it would be nice to see examples tests where:
..
is used, but only one element is supplied..
is used, but 0 elements are supplied
fjl
Feb 18, 2016
Author
Contributor
The example already checks this, right?
The example already checks this, right?
karalabe
Feb 18, 2016
Member
I'm not seeing either of the three cases checked?
Edit: The example fails when B is missing too. It doesn't check what happens when all the obligatory (A, B) fields are present, but C is missing or C contains only a single element or if C contains mixed elements. Those are the issues I'd like tested.
I'm not seeing either of the three cases checked?
Edit: The example fails when B is missing too. It doesn't check what happens when all the obligatory (A, B) fields are present, but C is missing or C contains only a single element or if C contains mixed elements. Those are the issues I'd like tested.
etypeinfo, err := cachedTypeInfo1(typ.Elem(), tags{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
writer := func(val reflect.Value, w *encbuf) error { | ||
lh := w.list() |
karalabe
Feb 18, 2016
Member
Where to you start the list in the new code? I can only see the listEnd
being used.
Where to you start the list in the new code? I can only see the listEnd
being used.
return tags{ | ||
nilOK: strings.Contains(tag, "nil"), | ||
dotdot: strings.Contains(tag, ".."), | ||
} |
karalabe
Feb 18, 2016
Member
I think it would catch potential errors if these would do strict checks and not contains
. I.e. split the tag
by commas, and check each element for nil
, or ...
equality and also error out if there's something else in there.
I think it would catch potential errors if these would do strict checks and not contains
. I.e. split the tag
by commas, and check each element for nil
, or ...
equality and also error out if there's something else in there.
obscuren
Feb 18, 2016
Member
What kind of potential errors?
Hmm thinking about this and I see what you mean. rlp:"nilling"
rlp:"nonil"
would also yield a positive.
What kind of potential errors?
Hmm thinking about this and I see what you mean. rlp:"nilling"
rlp:"nonil"
would also yield a positive.
@@ -214,6 +214,7 @@ var encTests = []encTest{ | |||
{val: simplestruct{A: 3, B: "foo"}, output: "C50383666F6F"}, | |||
{val: &recstruct{5, nil}, output: "C205C0"}, | |||
{val: &recstruct{5, &recstruct{4, &recstruct{3, nil}}}, output: "C605C404C203C0"}, | |||
{val: &dotdotRaw{A: 1, DotDot: []RawValue{unhex("02"), unhex("03")}}, output: "C3010203"}, |
karalabe
Feb 18, 2016
Member
Could you also add a case here when you only have one element and when zero elements? :D I would really like these corner cases covered by tests.
Could you also add a case here when you only have one element and when zero elements? :D I would really like these corner cases covered by tests.
etypeinfo, err := cachedTypeInfo1(typ.Elem(), tags{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
writer := func(val reflect.Value, w *encbuf) error { | ||
lh := w.list() | ||
if !ts.dotdot { | ||
defer w.listEnd(w.list()) |
obscuren
Feb 18, 2016
Member
@karalabe here. w.list()
is executed prior to the rest of the code.
EDIT: nifty pattern BTW :-D cool trick!
@karalabe here. w.list()
is executed prior to the rest of the code.
EDIT: nifty pattern BTW :-D cool trick!
As discussed on gitter change the |
@@ -460,6 +468,29 @@ func isTemporaryError(err error) bool { | |||
return ok && tempErr.Temporary() || isPacketTooBig(err) | |||
} | |||
|
|||
func encodePacket1(priv *ecdsa.PrivateKey, ptype byte, req interface{}, additional []byte) ([]byte, error) { |
karalabe
Feb 18, 2016
Member
What does this method do? I don't see it used in any of the code.
What does this method do? I don't see it used in any of the code.
@@ -234,7 +256,9 @@ func (h *encHandshake) secrets(auth, authResp []byte) (secrets, error) { | |||
return s, nil | |||
} | |||
|
|||
func (h *encHandshake) ecdhShared(prv *ecdsa.PrivateKey) ([]byte, error) { | |||
// ecdhShared returns the static shared secret, the result |
karalabe
Feb 18, 2016
Member
Method name in the doc is wrong.
Method name in the doc is wrong.
if err != nil { | ||
return s, err | ||
} | ||
auth, err := h.authMsg(prv, token) | ||
var authPacket []byte | ||
if os.Getenv("RLPX_EIP8") != "" { |
karalabe
Feb 18, 2016
Member
Wasn't this only used for testing? Shouldn't EIP-8 be used always?
Wasn't this only used for testing? Shouldn't EIP-8 be used always?
karalabe
Feb 18, 2016
Member
Hmmm, or is this here so we push out the change to first only accept EIP-8, but don't initiate it and when people upgraded then switch over to use it by everyone?
Hmmm, or is this here so we push out the change to first only accept EIP-8, but don't initiate it and when people upgraded then switch over to use it by everyone?
fjl
Feb 19, 2016
Author
Contributor
Yes, it's more like the latter comment. I used the env variable for testing with other clients.
Would be nice to ensure that the majority of the network will send EIP-8 soon-ish, maybe through
something like
if time.Now().After(switchoverDate) {
// send EIP-8
}
Yes, it's more like the latter comment. I used the env variable for testing with other clients.
Would be nice to ensure that the majority of the network will send EIP-8 soon-ish, maybe through
something like
if time.Now().After(switchoverDate) {
// send EIP-8
}
Code looks solid to me. The crypto aspects I cannot verify, but given the thorough tests + the cross client interop experiments, I guess those parts are correct. Please address the issues I've raised and the it's a Go from my part. |
PTAL. will squash when you're done reviewing. |
LGTM |
|
@fjl Please squash. |
@fjl please re-open. |
Implements ethereum/EIPs#49