Skip to content

fix(core): stop deversify mutating Vrsn_1_0 and read its version digits as hex - #424

Open
dhh1128 wants to merge 4 commits into
WebOfTrust:mainfrom
dhh1128:fix/deversify-version
Open

dhh1128 wants to merge 4 commits into
WebOfTrust:mainfrom
dhh1128:fix/deversify-version

Conversation

@dhh1128

@dhh1128 dhh1128 commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Fixes #423.

deversify wrote the parsed major and minor into Vrsn_1_0 and returned that same object. That had two effects. Every default that reads Vrsn_1_0 (versify, Serder, the event builders) picked up whatever version was parsed last, and the guard in sizeify compared against Vrsn_1_0 by reference, so it could never fire. The first commit has deversify return a new Version and makes sizeify compare major and minor by value. Once the guard could fire, its message printed [object Object], so it now prints the version, e.g. "unsupported version 1.1".

The second commit reads the version digits as hex. VEREX matches [0-9a-f] and versify writes with toString(16), but deversify used unary +, so a digit from a to f came back as NaN. The stream parser from #413 had the same problem and reads them as hex now, as keripy's VEREX1 does.

The last two commits are smaller. One freezes Vrsn_1_0, so that the next code to write to it fails instead of quietly changing every later serialization. Nothing writes to a Version's fields today. The other makes deversify reject a v1 version string whose major is above 1, as keripy's rematch does. Saider calls deversify directly rather than through sizeify, so without this it would digest a header like KERI20JSON…_ that keripy calls malformed.

There's one behavior change to note. sizeify, and therefore building a Serder from a ked, now throws on a version string other than 1.0, where before it accepted it silently. I checked every use of Vrsn_1_0, and none depends on its identity apart from that comparison.

The new tests cover a hex digit decoding to 10, parsing a 1.1 string leaving Vrsn_1_0 at 1.0 and frozen, sizeify rejecting 1.1, and deversify rejecting 2.0.

deversify wrote the parsed major and minor into Vrsn_1_0 and returned
that same object. After any non-1.0 version string was parsed, every
default that reads Vrsn_1_0 (versify, Serder, the event builders) used
the parsed version instead. sizeify's unsupported-version guard
compared the result to Vrsn_1_0 by reference, so it could never fire.

deversify now returns a new Version, and sizeify compares by value and
reports the version it rejects.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
VEREX matches hex digits and versify writes them with toString(16),
but deversify decoded them with unary +, so a digit of a-f became NaN.
Parse them with parseInt(_, 16).

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Vrsn_1_0 is the default version for versify, Serder and the event
builders, so any write to it changes every later serialization. The
previous commit removed the one writer; freezing the object stops the
next one.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
keripy's rematch raises VersionError for a v1-form version string with
major > 1. deversify accepted it, and Saider, which calls deversify
directly rather than going through sizeify, would digest a header
keripy calls malformed.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
@codecov

codecov Bot commented Oct 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.46%. Comparing base (e24c41d) to head (09cb10f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #424   +/-   ##
=======================================
  Coverage   97.46%   97.46%           
=======================================
  Files           1        1           
  Lines          79       79           
  Branches       28       28           
=======================================
  Hits           77       77           
  Misses          2        2           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@iFergal iFergal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment thread src/keri/core/core.ts
match[4],
match[5],
];
if (version.major > 1) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should be version.major != 1 as your regex allows for version 0.0.

Comment thread src/keri/core/core.ts
match[4],
match[5],
];
if (version.major > 1) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (version.major > 1) {
if (version.major != 1) {

Comment thread src/keri/core/core.ts
* Denotes version 1.0 of a protocol.
*/
export const Vrsn_1_0 = new Version();
export const Vrsn_1_0 = Object.freeze(new Version());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const Vrsn_1_0 = Object.freeze(new Version());
export const Vrsn_1_0 = Object.freeze(new Version(major: 1, minor: 0));

Since we use this as Version 1.0 global probably better to be explicit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: deversify mutates Vrsn_1_0 and misreads hex version digits

3 participants