Closed tharvik closed 4 years ago
I'm not sure this is something that can and should be fixed in dedis/protobuf
. Imagine you fix it, and somebody sends a data from javascript, but in the wrong order. Now if you suppose that the order should be correct on the receiving side, you're screwed again.
Proposed fix: add a CheckForMap
method that recurses in the structure and checks if a map is present. Then use this method in ByzCoin when registering a contract, and throw an error if somebody uses it.
Imagine you fix it, and somebody sends a data from javascript, but in the wrong order. Now if you suppose that the order should be correct on the receiving side, you're screwed again.
I don't really get what you mean
StateChange.Value
map
is an unsorted collectionWhat I'm trying to fix is that the following doesn't yield the same encoding, which is not really important when used for data transmission but is when using it for byte equality
Encode(map[string]bool{"a": true, "b": true})
Encode(map[string]bool{"b": true, "a": true})
Yes, been bitten by that one, too. But from what I understand, you want to make protobuf.Encode
always return the same bytestring, even when maps are involved. Which would lead to people using maps in contracts. Which would lead to javascript code sending ClientTransactions
with these maps. Which would lead to confusion, unless you tell javascript to do the same encoding.
So it's easier not to use maps at all whenever the structure will be used in anything that involves hashing or such.
Makes more sense now?
Yes, been bitten by that one, too. But from what I understand, you want to make
protobuf.Encode
always return the same bytestring, even when maps are involved. Which would lead to people using maps in contracts. Which would lead to javascript code sendingClientTransactions
with these maps.
Correct; it is nicer to be able to serialise most basic data structures.
Which would lead to confusion, unless you tell javascript to do the same encoding.
Why would it lead to confusion? Or rather, what kind of confusion? I don't follow.
The serialisation is done by a single client, not redone on every node, so it doesn't need to be stable, only to be done once.
So it's easier not to use maps at all whenever the structure will be used in anything that involves hashing or such.
Yep, I intended this issue to be more of a "let's do it in a while" one, as it is not needed currently, but it would be a nice improvement IMO.
It's a little bit artificial, but I can see something like this happen:
ClientTransaction
with a protobuf-encoded map to be included in an instance. Only, javascript doesn't have the same order as protobuf.Encode
Catching that error seems as difficult as catching the 'standard' map in the contract error...
And now you know why the Argument
s are a key/value slice, and not a map ;)
So to me, an error being thrown when you register a contract that uses maps, is the best way...
So to me, an error being thrown when you register a contract that uses maps, is the best way...
Closed in favor of https://github.com/dedis/cothority/issues/2256
Currently,
encoder.handleMap
generates an unstable output, asValue.MapKeys
is used to retrieve the keys of a given map. To would allow to usemap
in many serialized state, such as conscensus in byzcoin contract.