From 9837916874579101c6c1cd11ec9ae7017f9dbb87 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 18 Jun 2024 11:24:21 +0100 Subject: [PATCH] Noted the problem with json field ordering --- crates/bft-json-crdt/src/json_crdt.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/bft-json-crdt/src/json_crdt.rs b/crates/bft-json-crdt/src/json_crdt.rs index 77527fd..087323c 100644 --- a/crates/bft-json-crdt/src/json_crdt.rs +++ b/crates/bft-json-crdt/src/json_crdt.rs @@ -17,6 +17,12 @@ use fastcrypto::{ traits::{KeyPair, ToFromBytes}, // Verifier, }; +// TODO: serde's json object serialization and deserialization (correctly) do not define anything +// object field order in JSON objects. However, the hash check impl in bft-json-crdt does take order +// into account. This is going to cause problems later for non-Rust implementations, BFT hash checking +// currently depends on JSON serialization/deserialization object order. This shouldn't be the case +// but I've hacked it for the moment to get the PoC working. To see the problem, replace this with +// a std HashMap, everything will screw up (annoyingly, only *most* of the time). use indexmap::IndexMap; use serde::{Deserialize, Serialize}; use serde_with::{serde_as, Bytes};