mirror of
https://github.com/selfxyz/self.git
synced 2026-01-09 14:48:06 -05:00
hotfix off-by-one issues (#145)
This commit is contained in:
@@ -87,7 +87,7 @@ template DSC(
|
||||
// this should guarantee the dsc commitment is unique for each commitment
|
||||
component byte_checks[MAX_DSC_LENGTH];
|
||||
for (var i = 0; i < MAX_DSC_LENGTH; i++) {
|
||||
byte_checks[i] = GreaterThan(12);
|
||||
byte_checks[i] = GreaterEqThan(12);
|
||||
byte_checks[i].in[0] <== i;
|
||||
byte_checks[i].in[1] <== raw_dsc_padded_length;
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ template SignatureVerifier(signatureAlgorithm, n, k) {
|
||||
signal input pubKey[kScaled];
|
||||
signal input signature[kScaled];
|
||||
|
||||
var msg_len = (HASH_LEN_BITS + n) \ n;
|
||||
var msg_len = (HASH_LEN_BITS + n - 1) \ n;
|
||||
|
||||
signal hashParsed[msg_len] <== HashParser(signatureAlgorithm, n, k)(hash);
|
||||
|
||||
@@ -124,7 +124,7 @@ template SignatureVerifier(signatureAlgorithm, n, k) {
|
||||
|
||||
template HashParser(signatureAlgorithm, n, k) {
|
||||
var HASH_LEN_BITS = getHashLength(signatureAlgorithm);
|
||||
var msg_len = (HASH_LEN_BITS + n) \ n;
|
||||
var msg_len = (HASH_LEN_BITS + n - 1) \ n;
|
||||
|
||||
component hashParser[msg_len];
|
||||
signal input hash[HASH_LEN_BITS];
|
||||
|
||||
@@ -283,6 +283,19 @@ testSuite.forEach(({ sigAlg, hashFunction, domainParameter, keyLength }) => {
|
||||
}
|
||||
});
|
||||
|
||||
it('should not allow tampering of raw_dsc[raw_dsc_padded_length]', async () => {
|
||||
try {
|
||||
const tamperedInputs = JSON.parse(JSON.stringify(inputs));
|
||||
const paddedLength = Number(tamperedInputs.raw_dsc_padded_length);
|
||||
tamperedInputs.raw_dsc[paddedLength] = '255'; // or any nonzero value
|
||||
|
||||
await circuit.calculateWitness(tamperedInputs);
|
||||
expect.fail('Expected an error but none was thrown.');
|
||||
} catch (error: any) {
|
||||
expect(error.message).to.include('Assert Failed');
|
||||
}
|
||||
});
|
||||
|
||||
it('should fail if raw_csca has a signal that is longer than a byte', async function () {
|
||||
try {
|
||||
const tamperedInputs = JSON.parse(JSON.stringify(inputs));
|
||||
|
||||
Reference in New Issue
Block a user