Skip to content

Commit

Permalink
Add DOMAIN_APPLICATION_MASK validation for builder domain (#4542)
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech authored Sep 13, 2022
1 parent 2dd1323 commit d2025cc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/params/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,17 @@ export const DOMAIN_SYNC_COMMITTEE = Uint8Array.from([7, 0, 0, 0]);
export const DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF = Uint8Array.from([8, 0, 0, 0]);
export const DOMAIN_CONTRIBUTION_AND_PROOF = Uint8Array.from([9, 0, 0, 0]);

// Application specfic domains

/**
* `DOMAIN_APPLICATION_MASK` reserves the rest of the bitspace in `DomainType` for application
* usage. This means for some `DomainType` `DOMAIN_SOME_APPLICATION`, `DOMAIN_SOME_APPLICATION
* & DOMAIN_APPLICATION_MASK` **MUST** be non-zero. This expression for any other `DomainType`
* in the consensus specs **MUST** be zero.
*/
export const DOMAIN_APPLICATION_MASK = Uint8Array.from([0, 0, 0, 1]);
export const DOMAIN_APPLICATION_BUILDER = Uint8Array.from([0, 0, 0, 1]);

// Participation flag indices

export const TIMELY_SOURCE_FLAG_INDEX = 0;
Expand Down
14 changes: 14 additions & 0 deletions packages/params/test/unit/applicationDomains.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {expect} from "chai";
import {DOMAIN_APPLICATION_MASK, DOMAIN_APPLICATION_BUILDER} from "../../src/index.js";

describe("validate application domains", async () => {
[{name: "builder domain", domain: DOMAIN_APPLICATION_BUILDER}].map(({name, domain}) => {
it(name, () => {
let r = 0;
for (let i = 0; i < DOMAIN_APPLICATION_MASK.length; i++) {
r += DOMAIN_APPLICATION_MASK[i] & domain[i];
}
expect(r > 0).to.equal(true, `${name} mask application should be valid`);
});
});
});

0 comments on commit d2025cc

Please sign in to comment.