You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Go doesn’t have a native set type. That means developers have to use either an array type or a map type. In both cases, there is high potential for a developer to make a backwards-incompatible change (in terms of hashing).
In the array case, the order of the array is significant for the hashing algorithm. However, for a developer to deduplicate the array, they would most likely use an intermediate map. The problem is Go forces the order of the map to be non-deterministic, so the order of the final array and thus the hash becomes non-deterministic. In this case, we should sort the array before hashing to ensure determinism.
In the map case, the values of the map are insignificant. We should ignore them to prevent the developer breaking the determinism of the hash by using a different map value.
I propose introducing a new struct tag called set that is a Boolean true or false. If true, the library will deduplicate and sort the set values. It would support arrays and maps.
The text was updated successfully, but these errors were encountered:
I started to implement this and the main issue I ran into is when we're decoding it's hard to check the struct tags as they're out of scope at that point.
To unblock myself, I went ahead and just implemented it on the user side by creating a type that is a string array that has a Strings method that returns a deduplicated sorted list of strings. Then I can use the method setting in the struct tag:
Go doesn’t have a native set type. That means developers have to use either an array type or a map type. In both cases, there is high potential for a developer to make a backwards-incompatible change (in terms of hashing).
In the array case, the order of the array is significant for the hashing algorithm. However, for a developer to deduplicate the array, they would most likely use an intermediate map. The problem is Go forces the order of the map to be non-deterministic, so the order of the final array and thus the hash becomes non-deterministic. In this case, we should sort the array before hashing to ensure determinism.
In the map case, the values of the map are insignificant. We should ignore them to prevent the developer breaking the determinism of the hash by using a different map value.
I propose introducing a new struct tag called
set
that is a Booleantrue
orfalse
. Iftrue
, the library will deduplicate and sort the set values. It would support arrays and maps.The text was updated successfully, but these errors were encountered: