Skip to content

Commit

Permalink
Fix terse bitstring status list config bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Feb 27, 2025
1 parent 7afbe57 commit a00d96b
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 35 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# bedrock-vc-issuer ChangeLog

## 29.0.1 - 2025-02-dd

### Fixed
- Ensure `MAX_BLOCK_SIZE` accommodates `MAX_LIST_SIZE`.

## 29.0.0 - 2025-02-27

### Changed
Expand All @@ -10,7 +15,10 @@
Existing deployments that do use it but where an upgrade is desirable, should
stop using existing instances that use `TerseBitstringStatusList`, upgrade
and then create new instances that use `TerseBitstringStatusList` to reenable
existing use. Other upgrade paths and behavior are undefined.
existing use. Other upgrade paths and behavior are undefined. Note that
the associated status instance must support larger list sizes as well, for
example, install `@bedrock/[email protected]` or later (if using bedrock) on
the status service.
- Increase `MAX_LIST_SIZE` to accommodate lists of up to size `2^26`, which is
how large terse bitstring status lists are by default.

Expand Down
30 changes: 19 additions & 11 deletions lib/constants.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
/*!
* Copyright (c) 2024-2025 Digital Bazaar, Inc. All rights reserved.
*/
export const DEFAULT_BLOCK_COUNT = 4096;
export const DEFAULT_BLOCK_SIZE = 32;

// default `TerseBitstringStatusList` list count is 32-bit integer size
// divided by default list size = 2^32/2^26 = 2^6 = 64; each list will
// be 2^26 in size = 67108864
export const DEFAULT_TERSE_LIST_COUNT = 64;

// maximum number of cryptosuites to be used in a proof set
export const MAX_CRYPTOSUITE_OPTIONS = 10;

// default list size is DEFAULT_BLOCK_COUNT * DEFAULT_BLOCK_SIZE = 131072
export const DEFAULT_LIST_SIZE = DEFAULT_BLOCK_COUNT * DEFAULT_BLOCK_SIZE;

// max list size is 2^26, which is the largest size a totally random,
// unencrypted list can be (8MiB) without breaking the max 10MiB storage
// barrier for a single VC -- leaving 2MiB of space for other information
// beyond the list in a status list credential
// 2^26/2^3/2^10/2^10=2^3 = 8
// 67108864 bits / 8 / 1024 / 1024 = 8MiB
export const MAX_LIST_SIZE = 67108864;
// 2^5 = 32; max block size should be small to increase concurrency
export const MAX_BLOCK_SIZE = 32;
// max block count is MAX_LIST_SIZE / MAX_BLOCK_SIZE
// 2^21 = 2^26/2^5 = 2097152
export const MAX_BLOCK_COUNT = 2097152;

// maximum number of lists this software can keep track of (applies only to
// status list configurations where the number of lists is limited)
export const MAX_LIST_COUNT = Number.MAX_SAFE_INTEGER;

export const MAX_STATUS_LIST_OPTIONS = 1;

// default `TerseBitstringStatusList` list count is 32-bit integer size
// divided by default list size = 2^32/2^26 = 2^6 = 64; each list will
// be 2^26 in size = 67108864
export const DEFAULT_TERSE_LIST_COUNT = 64;

// default is only 4096 for smaller use cases of ~100K populations
// where 4096 * 32 = 131072
export const DEFAULT_BLOCK_COUNT = 4096;
export const DEFAULT_BLOCK_SIZE = MAX_BLOCK_SIZE;

// default list size is DEFAULT_BLOCK_COUNT * DEFAULT_BLOCK_SIZE
// = 2^17 = 131072
export const DEFAULT_LIST_SIZE = DEFAULT_BLOCK_COUNT * DEFAULT_BLOCK_SIZE;

export const serviceType = 'vc-issuer';
36 changes: 21 additions & 15 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/*!
* Copyright (c) 2021-2024 Digital Bazaar, Inc. All rights reserved.
* Copyright (c) 2021-2025 Digital Bazaar, Inc. All rights reserved.
*/
import * as bedrock from '@bedrock/core';
import * as issuer from './issuer.js';
import {createService, schemas} from '@bedrock/service-core';
import {
DEFAULT_BLOCK_COUNT, DEFAULT_BLOCK_SIZE, DEFAULT_TERSE_LIST_COUNT,
MAX_BLOCK_COUNT, MAX_BLOCK_SIZE,
MAX_CRYPTOSUITE_OPTIONS, MAX_LIST_SIZE, MAX_STATUS_LIST_OPTIONS, serviceType
} from './constants.js';
import {
Expand Down Expand Up @@ -138,11 +139,24 @@ async function validateConfigFn({config, op, existingConfig} = {}) {
}

// set default options
const options = {
blockCount: DEFAULT_BLOCK_COUNT,
blockSize: DEFAULT_BLOCK_SIZE,
...statusConfig.options
};
let options;
if(type === 'TerseBitstringStatusList') {
options = {
// must use max block count and size for terse defaults
blockCount: MAX_BLOCK_COUNT,
blockSize: MAX_BLOCK_SIZE,
// must be a list count for `TerseBitstringStatusList`
listCount: DEFAULT_TERSE_LIST_COUNT,
...statusConfig.options
};
} else {
// other list types
options = {
blockCount: DEFAULT_BLOCK_COUNT,
blockSize: DEFAULT_BLOCK_SIZE,
...statusConfig.options
};
}
// ensure list size is a multiple of 8 and less than the max list size
const listSize = options.blockCount * options.blockSize;
if(listSize % 8 !== 0) {
Expand All @@ -154,18 +168,10 @@ async function validateConfigFn({config, op, existingConfig} = {}) {
`Total status list size (${listSize}) must be less than ` +
`${MAX_LIST_SIZE}.`);
}
// `listCount` checks...
if(options.listCount !== undefined) {
// FIXME: re-enable this check
/*if(type !== 'TerseBitstringStatusList') {
if(type !== 'TerseBitstringStatusList') {
throw new Error(
'"listCount" can only be used with "TerseBitstringStatusList".');
}*/
}
if(type === 'TerseBitstringStatusList') {
// must be a list count for `TerseBitstringStatusList`
if(options.listCount === undefined) {
options.listCount = DEFAULT_TERSE_LIST_COUNT;
}
}
statusConfig.options = options;
Expand Down
8 changes: 4 additions & 4 deletions schemas/bedrock-vc-issuer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* Copyright (c) 2022-2024 Digital Bazaar, Inc. All rights reserved.
* Copyright (c) 2022-2025 Digital Bazaar, Inc. All rights reserved.
*/
import {
DEFAULT_BLOCK_COUNT, DEFAULT_BLOCK_SIZE, MAX_LIST_COUNT,
MAX_BLOCK_COUNT, MAX_BLOCK_SIZE, MAX_LIST_COUNT,
MAX_STATUS_LIST_OPTIONS
} from '../lib/constants.js';

Expand Down Expand Up @@ -201,12 +201,12 @@ export const statusListConfig = {
blockCount: {
type: 'integer',
minimum: 1,
maximum: DEFAULT_BLOCK_COUNT
maximum: MAX_BLOCK_COUNT
},
blockSize: {
type: 'integer',
minimum: 1,
maximum: DEFAULT_BLOCK_SIZE
maximum: MAX_BLOCK_SIZE
},
// note: some list types will require a `listCount`, each having their
// own different list count limits and defaults applied elsewhere; the
Expand Down
4 changes: 2 additions & 2 deletions test/mocha/assertions/testTerseBitstringStatusList.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Copyright (c) 2020-2024 Digital Bazaar, Inc. All rights reserved.
* Copyright (c) 2020-2025 Digital Bazaar, Inc. All rights reserved.
*/
import * as helpers from '../helpers.js';
import {createRequire} from 'node:module';
Expand Down Expand Up @@ -128,7 +128,7 @@ export function testTerseBitstringStatusList({
});

// get VC statuses
const listLength = 131072;
const listLength = 67108864;
const revocationStatusInfo = await helpers.getCredentialStatus(
{verifiableCredential, statusPurpose: 'revocation', listLength});
revocationStatusInfo.status.should.equal(false);
Expand Down
2 changes: 1 addition & 1 deletion test/mocha/helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2024 Digital Bazaar, Inc. All rights reserved.
* Copyright (c) 2019-2025 Digital Bazaar, Inc. All rights reserved.
*/
import * as base64url from 'base64url-universal';
import * as bedrock from '@bedrock/core';
Expand Down
2 changes: 1 addition & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@bedrock/test": "^8.2.0",
"@bedrock/validation": "^7.1.0",
"@bedrock/vc-issuer": "file:..",
"@bedrock/vc-status": "^1.0.0",
"@bedrock/vc-status": "^1.1.0",
"@bedrock/vc-status-list-context": "^6.0.2",
"@bedrock/veres-one-context": "^16.0.0",
"@bedrock/zcap-storage": "^8.0.1",
Expand Down

0 comments on commit a00d96b

Please sign in to comment.