-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Have a deterministic Map struct that can be go-wired #553
Comments
Here are the options based on previous research.
|
I think this is worthwhile - even if we could write Gaia without it, I can imagine lots of SDK applications that would want to use a map - better that we provide a common option, test it ourselves, and provide clear documentation on how to use it safely (deterministically). |
I like the idea of getting a linter into SDK app build workflow - we can flag other sources of non-determinism too, like time, rand, float |
One thing to watch out for with deterministic maps is that attackers may be able to make operations extra expensive by choosing colliding hashmap hashes for many values, so that the bucket gets really long and you get worst-case performance. (This was a problem in Node.js for a while, they fixed it by making the hash function different across processes). I think we'd have to fix this by doing something like consuming gas based on the number of values in the bucket. |
Yeh good point. Linting obviously isn't enough. What about just using the KVStore interface for this ? We would just need a way to marshal/unmarshal KVStore ... |
I think maybe having a Map interface would be good, and then we can have like different implementations. TreeMap, HashMap, ListMap, etc? Also regarding a TreeMap, if amino gives us length of the bytes, could we serialize the TreeMap efficiently, such that we can read in log(n) without deserializing the entire tree? |
@mappum This is super insightful. |
Let's do this.
That would be great - will have to investigate |
I think we changed encoding formats since |
Alas, that was merely a name change - this is still a problem. Definitely post-launch though. |
Is this still something we should do? |
With the move to directly using proto (or a simple wrapper of one), I don't see the need for this. |
The way protobuf works is that the spec doesn't specific deterministic maps but most implementation sort keys before serialization. |
Seems reasonable to me. This is generally something we hold as an invariant in the SDK anyway. |
So going to close. |
No description provided.
The text was updated successfully, but these errors were encountered: