Re: [Cbor] 65-bit negatives, big nums conflict between CDE and dCBOR drafts?

Anders Rundgren <anders.rundgren.net@gmail.com> Sat, 06 April 2024 13:56 UTC

Return-Path: <anders.rundgren.net@gmail.com>
X-Original-To: cbor@ietfa.amsl.com
Delivered-To: cbor@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 53CEDC14F681 for <cbor@ietfa.amsl.com>; Sat, 6 Apr 2024 06:56:21 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.095
X-Spam-Level:
X-Spam-Status: No, score=-2.095 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001, URIBL_DBL_BLOCKED_OPENDNS=0.001, URIBL_ZEN_BLOCKED_OPENDNS=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com
Received: from mail.ietf.org ([50.223.129.194]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6KW40K5PFrUJ for <cbor@ietfa.amsl.com>; Sat, 6 Apr 2024 06:56:17 -0700 (PDT)
Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id B25D8C14F61F for <cbor@ietf.org>; Sat, 6 Apr 2024 06:56:17 -0700 (PDT)
Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4156c4fe401so20032405e9.1 for <cbor@ietf.org>; Sat, 06 Apr 2024 06:56:17 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712411776; x=1713016576; darn=ietf.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=rAHgmTYx21exSt+SndMusTXmL3h1Ha8/pz1ZAZgoKiE=; b=F1wDylb7lLHPS4fkxbWZxDHRNft5J5eVRIK2bIXn4piTdFBJubFxn+A3w+0NTHIVgY 3Rxt/QN2PmSLy4zz1dvdJEsGZG6BDOFn7sJA/09QYnny9DUTqud5VhlKBzEyS09zgHIh SzWdwEMaWKcwW8Y4+96Kkz7F8bjK9a+BTyQjy7lI/5MJDlMsZKzOsy36awya5GdFV2bE W80DsdLh1vhpRHBlzAe8taAc+8xPxXAfQYaK3YKrxuV8nqEMRM0Mhq89KCfwOgcTpOxr a8HDNiROAO8hoJHod58tfIjqfo1FoxPkFtXWUl35ZrZyGqsSRm5veRsLP/kZIZYVAaG/ uSig==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712411776; x=1713016576; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rAHgmTYx21exSt+SndMusTXmL3h1Ha8/pz1ZAZgoKiE=; b=Rw1im6ozfKlM4PAF7dvhlNY4qlYWd0Eg30EKUBL+KjH2OpE9UwD3/9YuF3gk3uzS7P dCArvHqho4SoGp2Atx4TWeQ7gg9D4aIKjbM4EwiQMsUXio+3iVPA+6KDwTPtlAwz7MTg I1Z7uaoNRtr3RD85gqw+eahRef8F9uKsPeRy9q2U6lkP8vA06A9iQesiSIMgFRTlBWYc BCbQtOd0KJgXzO66pAyNaUOEVdLGBYYCh5nAIdQIxl+G4Ij3SmkHshmyvCJ8tIn6BxP9 XbWaBtMwoVKOcoboTbXWaUdeqbSl9/fNlJ9/SXiXnqH9KIrTMWo86nWqcnF7eoMhrm9Y 9B3A==
X-Forwarded-Encrypted: i=1; AJvYcCX60zSEDDHfL89+3V6PmE2Zl3lImvKJ+3N3o2E8AmIxwX92s+/tgCK/I+nQoipzLQm/tPF46Ja7gR6bgL4r
X-Gm-Message-State: AOJu0Yy9GRnit7bdmkbHqbm3c7qlaRzdDMpjcWSyMfoSVzKFrKh5w1wF g8d8YL92gDG2SDyrOrGPkeJVOJMA/kFJV1p1RXmaxsmCPFRIuXlSr5ttrApO
X-Google-Smtp-Source: AGHT+IE7YaE8giVN3NirMR1fpQDJNYxf1eYi3YaZS50EXDd4ZfEEOVMS9Kayk1y440vlX86408/ujQ==
X-Received: by 2002:a05:600c:4506:b0:414:8c5:42ce with SMTP id t6-20020a05600c450600b0041408c542cemr3244693wmo.19.1712411775782; Sat, 06 Apr 2024 06:56:15 -0700 (PDT)
Received: from ?IPV6:2a01:e0a:e1b:64b0:7d5c:21b4:472a:58bb? ([2a01:e0a:e1b:64b0:7d5c:21b4:472a:58bb]) by smtp.googlemail.com with ESMTPSA id c9-20020a05600c0a4900b0041638a085d3sm2232599wmq.15.2024.04.06.06.56.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 06 Apr 2024 06:56:15 -0700 (PDT)
Message-ID: <1aea13ce-9646-41cb-8f1a-5a249d08e693@gmail.com>
Date: Sat, 06 Apr 2024 15:56:13 +0200
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
To: "lgl island-resort.com" <lgl@island-resort.com>, "cbor@ietf.org" <cbor@ietf.org>
References: <775D5398-1A78-4255-B337-B9B25ED03ED3@island-resort.com>
Content-Language: en-US
From: Anders Rundgren <anders.rundgren.net@gmail.com>
In-Reply-To: <775D5398-1A78-4255-B337-B9B25ED03ED3@island-resort.com>
Content-Type: text/plain; charset="UTF-8"; format="flowed"
Content-Transfer-Encoding: 8bit
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/RaTx3CP-ptL4Fgb891_uoXQ3bMQ>
Subject: Re: [Cbor] 65-bit negatives, big nums conflict between CDE and dCBOR drafts?
X-BeenThere: cbor@ietf.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: "Concise Binary Object Representation \(CBOR\)" <cbor.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/cbor>, <mailto:cbor-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/cbor/>
List-Post: <mailto:cbor@ietf.org>
List-Help: <mailto:cbor-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/cbor>, <mailto:cbor-request@ietf.org?subject=subscribe>
X-List-Received-Date: Sat, 06 Apr 2024 13:56:21 -0000

Although I personally don't find the CBOR int/bignum arrangement ideal, this boat has (since long) already sailed and nobody died.

However, when it comes to the various constraints introduced by dCBOR, I disagree with the authors because practically all existing CBOR-using applications (as well as many tools) have explicit or implicit constraints that didn't require a specific encoding standard.  In addition, the integer constraints imposed by dCBOR has (AFAICT...) no impact on determinism; they are rather specific limits for the Blockchain Commons applications.


Numeric Reduction (aka canonicalized numbers) is the (IMO) only thing that needs to depart from CDE in order to achieve determinism.

Anders

On 2024-04-05 22:37, lgl island-resort.com wrote:
> draft-ietf-cbor-cde-02 says:
> 
>     1. The CBOR Common Deterministic Encoding Profile (CDE) turns this recommendation into a mandate: Integers that can be represented by basic major type 0 and 1 are encoded using the deterministic encoding defined for them, and integers outside this range are encoded using the preferred serialization (Section 3.4.3 of RFC 8949 [STD94]) of tag 2 and 3 (i.e., no leading zero bytes).
> 
> 
> There’s no MUST, but it looks to me like CDE requires:
>   - type 1 must be used for the 65-bit negative integers range
>   - tag 2 and 3 must be used for integer values outside of type 0 and 1
> 
> That makes it clear that tag 3 can never be used for 65-bit negative range integers. One could also infer that 2^66 and such must be encoded as a big number, never a float. That is probably not what is intended, though.
> 
> Floats aside, CDE is still unifying the integer number space between type 0 and 1 with tag 2 and 3 for the sake of determinism. It is allowing only one representation of all the integer values. It’s a bit like dCBOR's unification of integer and float number spaces.
> 
> Is that really what we want to do? It seems simpler not to, but if there are clear use cases, maybe it is a good thing.
> 
> 
> On to dCBOR. To comply with CDE, you must either 1) implement 65-bit negative type 1 or 2) declare non-support of that range of negative integers.
> 
> It’s pretty clearly that dCBOR does not want to declare non-support of that range of negative integers, so 65-bit negative type 1 integers must be supported. However dCBOR disallows them (and dCBOR requires compliance with CDE) so there is a conflict between the two documents now.
> 
> Further, if tag 2 & 3 must be used rather than floats for 2^66 and such, there’s another conflict.
> 
> 
> Seems to me we should figure out what CDE should do here first. Figure out whether there is integer number unification or not. If not, then dCBOR is fine as is. If there is integer unification, then dCBOR has to allow 65-bit negatives.
> 
> If integer unification is to be required, then CDE implementations have two choices:
> 
> 1) Avoid it by declaring non-support of integers outside of int64_t/uint64_t.
> 2) Do the unification work.
> 
> The unification work isn’t a lot of code, but does need some thought. Also, with the current text, I think implementors may not realize it needs to be done.
> 
> Also, I suspect some non-CDE decoders that support big numbers might be surprised when 65-bit negative type 1 integers arrive. Those reaching for CDE to have better interoperability might not always get what they want.
> 
> Wait, there’s more…
> 
> We could do integer unification of the number space by requiring the 65-bit negative integer range always be encoded as a tag 3 big number, never as type 1. That is, disallow 65-bit negative type 1 like dCBOR. If we say that those values must be tag 3, then we’re not limiting the data model. And what’s the data model for -2^66? You have to do use tag 3 for it.
> 
> LL
> 
> 
> 
> 
> 
> _______________________________________________
> CBOR mailing list
> CBOR@ietf.org
> https://www.ietf.org/mailman/listinfo/cbor