@callcium/sdk 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +23 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +97 -35
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -118,6 +118,23 @@ type QuantifierLimitExceededViolation = {
|
|
|
118
118
|
path: Hex; /** Hex-encoded element count of the offending array. */
|
|
119
119
|
resolvedValue: Hex;
|
|
120
120
|
};
|
|
121
|
+
/**
|
|
122
|
+
* A resolved word is not the canonical encoding of its declared type (spec §7.4).
|
|
123
|
+
*
|
|
124
|
+
* `resolvedValue` is the raw 32-byte word as it appeared in calldata, before any masking.
|
|
125
|
+
*/
|
|
126
|
+
type NonCanonicalValueViolation = {
|
|
127
|
+
code: "NON_CANONICAL_VALUE";
|
|
128
|
+
group: number;
|
|
129
|
+
rule: number;
|
|
130
|
+
scope: number;
|
|
131
|
+
path: Hex; /** Type code of the target whose encoding was violated. */
|
|
132
|
+
typeCode: number; /** Raw 32-byte word as it appeared in calldata, before any masking. */
|
|
133
|
+
resolvedValue: Hex;
|
|
134
|
+
opCode?: number;
|
|
135
|
+
operandData?: Hex;
|
|
136
|
+
elementIndex?: number;
|
|
137
|
+
};
|
|
121
138
|
/** A quantifier (`ANY` or `ALL`) was applied to an empty array. */
|
|
122
139
|
type QuantifierEmptyArrayViolation = {
|
|
123
140
|
code: "QUANTIFIER_EMPTY_ARRAY";
|
|
@@ -132,7 +149,7 @@ type QuantifierEmptyArrayViolation = {
|
|
|
132
149
|
* Carries semantic data only — message strings are the consumer's responsibility.
|
|
133
150
|
* Discriminate on `code` to narrow to the matching variant.
|
|
134
151
|
*/
|
|
135
|
-
type Violation = MissingSelectorViolation | SelectorMismatchViolation | MissingContextViolation | ValueMismatchViolation | CalldataNavigationViolation | QuantifierLimitExceededViolation | QuantifierEmptyArrayViolation;
|
|
152
|
+
type Violation = MissingSelectorViolation | SelectorMismatchViolation | MissingContextViolation | ValueMismatchViolation | CalldataNavigationViolation | NonCanonicalValueViolation | QuantifierLimitExceededViolation | QuantifierEmptyArrayViolation;
|
|
136
153
|
/** Machine-readable reason code for an enforcement violation. Derived from `Violation` to prevent drift. */
|
|
137
154
|
type ViolationCode = Violation["code"];
|
|
138
155
|
/** Canonical structured representation of a policy. */
|
|
@@ -427,7 +444,7 @@ declare function inspect(desc: Uint8Array, offset: number): TypeInfo;
|
|
|
427
444
|
* @param desc - Raw descriptor bytes.
|
|
428
445
|
* @param steps - Path steps, length >= 1.
|
|
429
446
|
* @returns TypeInfo for the node at the resolved path.
|
|
430
|
-
* @throws {CallciumError} On empty steps, out-of-bounds param, or descent into elementary type.
|
|
447
|
+
* @throws {CallciumError} On empty steps, out-of-bounds param or array index, or descent into elementary type.
|
|
431
448
|
*/
|
|
432
449
|
declare function typeAt(desc: Uint8Array, steps: number[]): TypeInfo;
|
|
433
450
|
/**
|
|
@@ -437,7 +454,7 @@ declare function typeAt(desc: Uint8Array, steps: number[]): TypeInfo;
|
|
|
437
454
|
* @param desc - Raw descriptor bytes.
|
|
438
455
|
* @param steps - Path steps, length >= 1.
|
|
439
456
|
* @returns TypeInfo at the resolved path and the quantified static array length.
|
|
440
|
-
* @throws {CallciumError} On empty steps, out-of-bounds param, or descent into elementary type.
|
|
457
|
+
* @throws {CallciumError} On empty steps, out-of-bounds param or array index, or descent into elementary type.
|
|
441
458
|
*/
|
|
442
459
|
declare function walkPath(desc: Uint8Array, steps: number[]): {
|
|
443
460
|
typeInfo: TypeInfo;
|
|
@@ -484,6 +501,8 @@ declare function isOpAllowed(opCode: number, typeInfo: TypeInfo): boolean;
|
|
|
484
501
|
* Validate a policy for type mismatches, contradictions, redundancies, and vacuities.
|
|
485
502
|
* @param data - The canonical policy data to validate.
|
|
486
503
|
* @returns All validation issues found, ordered by group and constraint index.
|
|
504
|
+
* @throws {CallciumError} If the descriptor is not well-formed; semantic validation is
|
|
505
|
+
* defined only over a well-formed descriptor.
|
|
487
506
|
*/
|
|
488
507
|
declare function validate(data: PolicyData): Issue[];
|
|
489
508
|
/** Semantic validation for policies. */
|
|
@@ -835,5 +854,5 @@ declare class PolicyViolationError extends Error {
|
|
|
835
854
|
constructor(violations: Violation[]);
|
|
836
855
|
}
|
|
837
856
|
//#endregion
|
|
838
|
-
export { type Address, CallciumError, type CallciumErrorCode, type CalldataNavigationViolation, type Constraint, type ConstraintBuilder, type Context, ContextProperty, type ContextPropertyInfo, type DecodedGroup, type DecodedParam, type DecodedPolicy, type DecodedRule, Descriptor, DescriptorCoder, type EnforceResult, type Field, type Hex, type Issue, type IssueCategory, type IssueSeverity, Limits, type MissingContextViolation, type MissingSelectorViolation, type NavigationViolationCode, Op, type OpInfo, type Operands, PolicyBuilder, PolicyCoder, type PolicyData, PolicyEnforcer, PolicyValidator, PolicyViolationError, Quantifier, type QuantifierEmptyArrayViolation, type QuantifierInfo, type QuantifierLimitExceededViolation, type ScalarValue, Scope, type ScopeInfo, type SelectorMismatchViolation, type Span, type TypeClass, type TypeClassInfo, TypeCode, type TypeCodeInfo, type TypeInfo, type ValueMismatchViolation, type Violation, type ViolationCode, arg, baseFee, blockNumber, blockTimestamp, bytesToHex, chainId, gasPrice, hexToBytes, isLengthOp, isOpAllowed, isQuantifier, lookupContextProperty, lookupOp, lookupQuantifier, lookupScope, lookupTypeCode, msgSender, msgValue, parsePathSteps, toAddress, txOrigin };
|
|
857
|
+
export { type Address, CallciumError, type CallciumErrorCode, type CalldataNavigationViolation, type Constraint, type ConstraintBuilder, type Context, ContextProperty, type ContextPropertyInfo, type DecodedGroup, type DecodedParam, type DecodedPolicy, type DecodedRule, Descriptor, DescriptorCoder, type EnforceResult, type Field, type Hex, type Issue, type IssueCategory, type IssueSeverity, Limits, type MissingContextViolation, type MissingSelectorViolation, type NavigationViolationCode, type NonCanonicalValueViolation, Op, type OpInfo, type Operands, PolicyBuilder, PolicyCoder, type PolicyData, PolicyEnforcer, PolicyValidator, PolicyViolationError, Quantifier, type QuantifierEmptyArrayViolation, type QuantifierInfo, type QuantifierLimitExceededViolation, type ScalarValue, Scope, type ScopeInfo, type SelectorMismatchViolation, type Span, type TypeClass, type TypeClassInfo, TypeCode, type TypeCodeInfo, type TypeInfo, type ValueMismatchViolation, type Violation, type ViolationCode, arg, baseFee, blockNumber, blockTimestamp, bytesToHex, chainId, gasPrice, hexToBytes, isLengthOp, isOpAllowed, isQuantifier, lookupContextProperty, lookupOp, lookupQuantifier, lookupScope, lookupTypeCode, msgSender, msgValue, parsePathSteps, toAddress, txOrigin };
|
|
839
858
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/constraint.ts","../src/policy-builder.ts","../src/policy-coder.ts","../src/descriptor.ts","../src/policy-validator.ts","../src/policy-enforcer.ts","../src/bytes.ts","../src/descriptor-coder.ts","../src/constants.ts","../src/operators.ts","../src/errors.ts"],"mappings":";;KAKY,GAAA;;KAGA,OAAA;;KAGA,IAAA;EAAS,KAAA;EAAe,GAAA;AAAA;;;;AAiEpC;;KAfY,OAAA;EACV,SAAA,GAAY,OAAA;EACZ,QAAA;EACA,cAAA;EACA,WAAA;EACA,OAAA;EACA,QAAA,GAAW,OAAA;EACX,OAAA;EACA,QAAA;AAAA;;KAIU,aAAA;EAAkB,EAAA;EAAU,YAAA;AAAA;EAA2B,EAAA;EAAW,UAAA,EAAY,SAAA;AAAA;;KAG9E,uBAAA;;KAGA,wBAAA;EACV,IAAA;AAAA;;KAIU,yBAAA;EACV,IAAA,uBAkBA;EAhBA,aAAA,EAAe,GAAA,EAkBf;EAhBA,aAAA,EAAe,GAAA;AAAA;;;;AAiCjB;;;KAxBY,uBAAA;EACV,IAAA;EACA,KAAA;EACA,IAAA;EACA,KAAA;EACA,IAAA,EAAM,GAAA,EAqBN;EAnBA,QAAA;EACA,MAAA;EACA,WAAA,GAAc,GAAA;AAAA;;;;;;;;;;AA6Bd;;;KAdU,sBAAA;EACV,IAAA;EACA,KAAA;EACA,IAAA;EACA,KAAA;EACA,IAAA,EAAM,GAAA,EAeuB;EAb7B,MAAA,UAcA;EAZA,WAAA,EAAa,GAAA,EAab;EAXA,QAAA;EACA,aAAA,GAAgB,GAAA;EAChB,YAAA;AAAA;;;;;KAOG,yBAAA,WAAoC,uBAAA;EACvC,IAAA,EAAM,CAAA;EACN,KAAA;EACA,IAAA;EACA,KAAA;EACA,IAAA,EAAM,GAAA;EACN,MAAA;EACA,WAAA,GAAc,GAAA;EACd,QAAA;EACA,YAAA;AAAA;;;;;;;;;;;KAaU,2BAAA,GACR,yBAAA,6BACA,yBAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/constraint.ts","../src/policy-builder.ts","../src/policy-coder.ts","../src/descriptor.ts","../src/policy-validator.ts","../src/policy-enforcer.ts","../src/bytes.ts","../src/descriptor-coder.ts","../src/constants.ts","../src/operators.ts","../src/errors.ts"],"mappings":";;KAKY,GAAA;;KAGA,OAAA;;KAGA,IAAA;EAAS,KAAA;EAAe,GAAA;AAAA;;;;AAiEpC;;KAfY,OAAA;EACV,SAAA,GAAY,OAAA;EACZ,QAAA;EACA,cAAA;EACA,WAAA;EACA,OAAA;EACA,QAAA,GAAW,OAAA;EACX,OAAA;EACA,QAAA;AAAA;;KAIU,aAAA;EAAkB,EAAA;EAAU,YAAA;AAAA;EAA2B,EAAA;EAAW,UAAA,EAAY,SAAA;AAAA;;KAG9E,uBAAA;;KAGA,wBAAA;EACV,IAAA;AAAA;;KAIU,yBAAA;EACV,IAAA,uBAkBA;EAhBA,aAAA,EAAe,GAAA,EAkBf;EAhBA,aAAA,EAAe,GAAA;AAAA;;;;AAiCjB;;;KAxBY,uBAAA;EACV,IAAA;EACA,KAAA;EACA,IAAA;EACA,KAAA;EACA,IAAA,EAAM,GAAA,EAq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steps - Path steps, length >= 1.
|
|
576
576
|
* @returns TypeInfo for the node at the resolved path.
|
|
577
|
-
* @throws {CallciumError} On empty steps, out-of-bounds param, or descent into elementary type.
|
|
577
|
+
* @throws {CallciumError} On empty steps, out-of-bounds param or array index, or descent into elementary type.
|
|
578
578
|
*/
|
|
579
579
|
function typeAt(desc, steps) {
|
|
580
580
|
return walkPath(desc, steps).typeInfo;
|
|
@@ -586,7 +586,7 @@ function typeAt(desc, steps) {
|
|
|
586
586
|
* @param desc - Raw descriptor bytes.
|
|
587
587
|
* @param steps - Path steps, length >= 1.
|
|
588
588
|
* @returns TypeInfo at the resolved path and the quantified static array length.
|
|
589
|
-
* @throws {CallciumError} On empty steps, out-of-bounds param, or descent into elementary type.
|
|
589
|
+
* @throws {CallciumError} On empty steps, out-of-bounds param or array index, or descent into elementary type.
|
|
590
590
|
*/
|
|
591
591
|
function walkPath(desc, steps) {
|
|
592
592
|
if (steps.length === 0) throw new CallciumError("INVALID_PATH", "Path must have at least one step.");
|
|
@@ -603,7 +603,11 @@ function walkPath(desc, steps) {
|
|
|
603
603
|
if (step >= fields) throw new CallciumError("INVALID_PATH", `Tuple field index ${step} out of range (tuple has ${fields} fields).`);
|
|
604
604
|
cursor = tupleFieldOffset(desc, cursor, step);
|
|
605
605
|
} else if (typeCode === TypeCode.STATIC_ARRAY || typeCode === TypeCode.DYNAMIC_ARRAY) {
|
|
606
|
-
if (typeCode === TypeCode.STATIC_ARRAY
|
|
606
|
+
if (typeCode === TypeCode.STATIC_ARRAY) if (isQuantifier(step)) quantifiedStaticLength = staticArrayLength(desc, cursor);
|
|
607
|
+
else {
|
|
608
|
+
const length = staticArrayLength(desc, cursor);
|
|
609
|
+
if (step >= length) throw new CallciumError("INVALID_PATH", `Array index ${step} out of range (length=${length}).`);
|
|
610
|
+
}
|
|
607
611
|
cursor = arrayElementOffset(cursor);
|
|
608
612
|
} else throw new CallciumError("INVALID_PATH", `Cannot descend into elementary type at offset ${cursor}.`);
|
|
609
613
|
}
|
|
@@ -807,6 +811,7 @@ function commaPositions(input, start, end) {
|
|
|
807
811
|
*/
|
|
808
812
|
function parseUint(input, start, end) {
|
|
809
813
|
if (start >= end) return -1;
|
|
814
|
+
if (end - start > 1 && input.charCodeAt(start) === 48) return -1;
|
|
810
815
|
let value = 0;
|
|
811
816
|
for (let i = start; i < end; i++) {
|
|
812
817
|
const code = input.charCodeAt(i);
|
|
@@ -1612,6 +1617,19 @@ function fromOpRule(code, message, groupIndex, constraintIndex, opCode) {
|
|
|
1612
1617
|
message
|
|
1613
1618
|
};
|
|
1614
1619
|
}
|
|
1620
|
+
/** Issue for a calldata path that does not navigate the descriptor. */
|
|
1621
|
+
function unnavigablePath(groupIndex, constraintIndex) {
|
|
1622
|
+
return {
|
|
1623
|
+
severity: "error",
|
|
1624
|
+
category: "typeMismatch",
|
|
1625
|
+
groupIndex,
|
|
1626
|
+
constraintIndex,
|
|
1627
|
+
code: "UNNAVIGABLE_PATH",
|
|
1628
|
+
value1: ZERO,
|
|
1629
|
+
value2: ZERO,
|
|
1630
|
+
message: "Path does not navigate the descriptor"
|
|
1631
|
+
};
|
|
1632
|
+
}
|
|
1615
1633
|
/** Issue for an operand that is not canonically encoded for the declared type. */
|
|
1616
1634
|
function nonCanonicalOperand(groupIndex, constraintIndex, operand, canonical) {
|
|
1617
1635
|
return {
|
|
@@ -1937,6 +1955,19 @@ function vacuousLte(isLength, groupIndex, constraintIndex, value) {
|
|
|
1937
1955
|
message: isLength ? "lengthLte() bound equals maximum (always true)" : "lte() bound equals type maximum (always true)"
|
|
1938
1956
|
};
|
|
1939
1957
|
}
|
|
1958
|
+
/** Negated range with inverted bounds excludes nothing (always true). */
|
|
1959
|
+
function vacuousNegatedRange(isLength, groupIndex, constraintIndex, low, high) {
|
|
1960
|
+
return {
|
|
1961
|
+
severity: "info",
|
|
1962
|
+
category: "vacuity",
|
|
1963
|
+
groupIndex,
|
|
1964
|
+
constraintIndex,
|
|
1965
|
+
code: isLength ? "VACUOUS_NEGATED_LENGTH_RANGE" : "VACUOUS_NEGATED_RANGE",
|
|
1966
|
+
value1: low,
|
|
1967
|
+
value2: high,
|
|
1968
|
+
message: isLength ? "Negated lengthBetween() with low > high excludes nothing (always true)" : "Negated between() with low > high excludes nothing (always true)"
|
|
1969
|
+
};
|
|
1970
|
+
}
|
|
1940
1971
|
/** Path deeper than the reference enforcer's cap. */
|
|
1941
1972
|
function pathDepthExceeded(groupIndex, constraintIndex, depth, maxDepth) {
|
|
1942
1973
|
return {
|
|
@@ -1992,20 +2023,8 @@ function negationUnderAny(groupIndex, constraintIndex, opCode) {
|
|
|
1992
2023
|
//#endregion
|
|
1993
2024
|
//#region src/policy-validator.ts
|
|
1994
2025
|
/**
|
|
1995
|
-
* Maximum
|
|
1996
|
-
* domain. A hole is a single value excluded via a negated equality (neq).
|
|
1997
|
-
* During cross-operator analysis, holes punch values out of isIn sets — if
|
|
1998
|
-
* every member of an isIn set is excluded by holes or notIn, the constraint
|
|
1999
|
-
* is unsatisfiable (SET_FULLY_EXCLUDED). When only some are excluded, the
|
|
2000
|
-
* validator emits SET_PARTIALLY_EXCLUDED.
|
|
2001
|
-
*
|
|
2002
|
-
* Both caps are protocol-defined limits. Beyond these limits,
|
|
2003
|
-
* additional exclusions are silently ignored — the validator becomes
|
|
2004
|
-
* best-effort for set-reduction diagnostics but never produces false
|
|
2005
|
-
* positives, only potential false negatives (missed redundancy warnings).
|
|
2026
|
+
* Maximum length value for dynamic types.
|
|
2006
2027
|
*/
|
|
2007
|
-
const MAX_HOLES = 8;
|
|
2008
|
-
const MAX_NOT_IN = 8;
|
|
2009
2028
|
const LENGTH_MAX = 4294967295n;
|
|
2010
2029
|
const UINT256_MAX = (1n << 256n) - 1n;
|
|
2011
2030
|
const INT256_SIGN_BIT = 1n << 255n;
|
|
@@ -2220,7 +2239,7 @@ function updateBound(domain, base, isNegated, value, isLength, groupIndex, const
|
|
|
2220
2239
|
alreadyHole = true;
|
|
2221
2240
|
break;
|
|
2222
2241
|
}
|
|
2223
|
-
if (!alreadyHole
|
|
2242
|
+
if (!alreadyHole) domain.holes.push(value);
|
|
2224
2243
|
} else updateBound(domain, negateBoundOp(base), false, value, isLength, groupIndex, constraintIndex, issues);
|
|
2225
2244
|
return;
|
|
2226
2245
|
}
|
|
@@ -2352,10 +2371,11 @@ function updateSet(ctx, isNegated, values, groupIndex, constraintIndex, issues)
|
|
|
2352
2371
|
}
|
|
2353
2372
|
if (inSet) issues.push(setReduction(groupIndex, constraintIndex, bigintToHex(value)));
|
|
2354
2373
|
}
|
|
2355
|
-
|
|
2374
|
+
ctx.set.notInValues.push(value);
|
|
2356
2375
|
}
|
|
2357
2376
|
checkSetEmpty(ctx, groupIndex, constraintIndex, issues);
|
|
2358
2377
|
} else {
|
|
2378
|
+
for (const value of values) if (signedCompare(value, ctx.numeric.min, ctx.numeric.isSigned) < 0n || signedCompare(value, ctx.numeric.max, ctx.numeric.isSigned) > 0n) issues.push(outOfPhysicalBounds(false, groupIndex, constraintIndex, bigintToHex(value)));
|
|
2359
2379
|
if (ctx.numeric.hasEq) {
|
|
2360
2380
|
let found = false;
|
|
2361
2381
|
for (const candidate of values) if (candidate === ctx.numeric.eq) {
|
|
@@ -2455,11 +2475,11 @@ function validateConstraint(ctx, constraint, groupIndex, constraintIndex, issues
|
|
|
2455
2475
|
}
|
|
2456
2476
|
}
|
|
2457
2477
|
if (base >= Op.EQ && base <= Op.BETWEEN) if (base === Op.BETWEEN) {
|
|
2478
|
+
const { low, high } = readPair(opHex);
|
|
2458
2479
|
if (!isNegated) {
|
|
2459
|
-
const { low, high } = readPair(opHex);
|
|
2460
2480
|
updateBound(ctx.numeric, Op.GTE, false, low, false, groupIndex, constraintIndex, issues);
|
|
2461
2481
|
updateBound(ctx.numeric, Op.LTE, false, high, false, groupIndex, constraintIndex, issues);
|
|
2462
|
-
}
|
|
2482
|
+
} else if (signedCompare(low, high, ctx.numeric.isSigned) > 0n) issues.push(vacuousNegatedRange(false, groupIndex, constraintIndex, bigintToHex(low), bigintToHex(high)));
|
|
2463
2483
|
} else {
|
|
2464
2484
|
const value = readValue(opHex);
|
|
2465
2485
|
const holesBefore = ctx.numeric.holes.length;
|
|
@@ -2473,11 +2493,11 @@ function validateConstraint(ctx, constraint, groupIndex, constraintIndex, issues
|
|
|
2473
2493
|
else updateSet(ctx, isNegated, values, groupIndex, constraintIndex, issues);
|
|
2474
2494
|
}
|
|
2475
2495
|
} else if (isLengthOp(base)) if (base === Op.LENGTH_BETWEEN) {
|
|
2496
|
+
const { low, high } = readPair(opHex);
|
|
2476
2497
|
if (!isNegated) {
|
|
2477
|
-
const { low, high } = readPair(opHex);
|
|
2478
2498
|
updateBound(ctx.length, Op.GTE, false, low, true, groupIndex, constraintIndex, issues);
|
|
2479
2499
|
updateBound(ctx.length, Op.LTE, false, high, true, groupIndex, constraintIndex, issues);
|
|
2480
|
-
}
|
|
2500
|
+
} else if (low > high) issues.push(vacuousNegatedRange(true, groupIndex, constraintIndex, bigintToHex(low), bigintToHex(high)));
|
|
2481
2501
|
} else {
|
|
2482
2502
|
const value = readValue(opHex);
|
|
2483
2503
|
updateBound(ctx.length, normalizeLengthOp(base), isNegated, value, true, groupIndex, constraintIndex, issues);
|
|
@@ -2502,7 +2522,16 @@ function validateGroup(data, descBytes, groupIndex, issues) {
|
|
|
2502
2522
|
if (constraint.scope === Scope.CALLDATA) {
|
|
2503
2523
|
const steps = parsePathSteps(constraint.path);
|
|
2504
2524
|
if (steps.length > Limits.MAX_PATH_DEPTH) issues.push(pathDepthExceeded(groupIndex, constraintIndex, bigintToHex(BigInt(steps.length)), bigintToHex(BigInt(Limits.MAX_PATH_DEPTH))));
|
|
2505
|
-
|
|
2525
|
+
let walk;
|
|
2526
|
+
try {
|
|
2527
|
+
walk = Descriptor.walkPath(descBytes, steps);
|
|
2528
|
+
} catch (error) {
|
|
2529
|
+
if (error instanceof CallciumError && error.code === "INVALID_PATH") {
|
|
2530
|
+
issues.push(unnavigablePath(groupIndex, constraintIndex));
|
|
2531
|
+
continue;
|
|
2532
|
+
}
|
|
2533
|
+
throw error;
|
|
2534
|
+
}
|
|
2506
2535
|
if (walk.quantifiedStaticLength > Limits.MAX_QUANTIFIED_ARRAY_LENGTH) issues.push(quantifierOverStaticLimit(groupIndex, constraintIndex, bigintToHex(BigInt(walk.quantifiedStaticLength)), bigintToHex(BigInt(Limits.MAX_QUANTIFIED_ARRAY_LENGTH))));
|
|
2507
2536
|
typeInfo = walk.typeInfo;
|
|
2508
2537
|
} else {
|
|
@@ -2531,10 +2560,13 @@ function validateGroup(data, descBytes, groupIndex, issues) {
|
|
|
2531
2560
|
* Validate a policy for type mismatches, contradictions, redundancies, and vacuities.
|
|
2532
2561
|
* @param data - The canonical policy data to validate.
|
|
2533
2562
|
* @returns All validation issues found, ordered by group and constraint index.
|
|
2563
|
+
* @throws {CallciumError} If the descriptor is not well-formed; semantic validation is
|
|
2564
|
+
* defined only over a well-formed descriptor.
|
|
2534
2565
|
*/
|
|
2535
2566
|
function validate(data) {
|
|
2536
2567
|
const issues = [];
|
|
2537
2568
|
const descBytes = hexToBytes(data.descriptor);
|
|
2569
|
+
decodeDescriptor(descBytes);
|
|
2538
2570
|
for (let groupIndex = 0; groupIndex < data.groups.length; groupIndex++) {
|
|
2539
2571
|
if (data.groups[groupIndex].length === 0) {
|
|
2540
2572
|
issues.push(emptyGroup(groupIndex));
|
|
@@ -3285,10 +3317,11 @@ function descendPath(callData, location, pathBytes) {
|
|
|
3285
3317
|
}
|
|
3286
3318
|
//#endregion
|
|
3287
3319
|
//#region src/policy-enforcer.ts
|
|
3288
|
-
/** Violations that abort evaluation instead of failing only their group (spec §
|
|
3320
|
+
/** Violations that abort evaluation instead of failing only their group (spec §9.3). */
|
|
3289
3321
|
const ABORT_VIOLATION_CODES = new Set([
|
|
3290
3322
|
"CALLDATA_OUT_OF_BOUNDS",
|
|
3291
3323
|
"ARRAY_INDEX_OUT_OF_BOUNDS",
|
|
3324
|
+
"NON_CANONICAL_VALUE",
|
|
3292
3325
|
"QUANTIFIER_LIMIT_EXCEEDED"
|
|
3293
3326
|
]);
|
|
3294
3327
|
/** Convert a hex address to a 256-bit bigint (zero-padded to 32 bytes). */
|
|
@@ -3461,7 +3494,11 @@ function applyLeafOperator(callDataBytes, location, opCode, operandData) {
|
|
|
3461
3494
|
if (node.isDynamic || node.type !== "elementary") throw new CallciumError("NOT_SCALAR", "Value operator on a target without a scalar word.");
|
|
3462
3495
|
const result = loadScalar(callDataBytes, location);
|
|
3463
3496
|
if (!result.ok) return { error: result.code };
|
|
3464
|
-
const value =
|
|
3497
|
+
const value = toBigInt(result.value, 0);
|
|
3498
|
+
if (canonicalize(value, node.typeCode) !== value) return {
|
|
3499
|
+
error: "NON_CANONICAL_VALUE",
|
|
3500
|
+
resolvedValue: bigintToHex(value)
|
|
3501
|
+
};
|
|
3465
3502
|
return {
|
|
3466
3503
|
passed: applyOperator(opCode, value, 32, operandData, node.typeCode),
|
|
3467
3504
|
resolvedValue: bigintToHex(value)
|
|
@@ -3471,16 +3508,29 @@ function applyLeafOperator(callDataBytes, location, opCode, operandData) {
|
|
|
3471
3508
|
function evaluateLeaf(location, callDataBytes, opCode, operandData, groupIndex, ruleIndex, pathHex) {
|
|
3472
3509
|
const result = applyLeafOperator(callDataBytes, location, opCode, operandData);
|
|
3473
3510
|
const typeCode = location.node.typeCode;
|
|
3474
|
-
if ("error" in result)
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3511
|
+
if ("error" in result) {
|
|
3512
|
+
if (result.error === "NON_CANONICAL_VALUE") return {
|
|
3513
|
+
group: groupIndex,
|
|
3514
|
+
rule: ruleIndex,
|
|
3515
|
+
code: result.error,
|
|
3516
|
+
scope: Scope.CALLDATA,
|
|
3517
|
+
path: pathHex,
|
|
3518
|
+
opCode,
|
|
3519
|
+
operandData: bytesToHex(operandData),
|
|
3520
|
+
typeCode,
|
|
3521
|
+
resolvedValue: result.resolvedValue
|
|
3522
|
+
};
|
|
3523
|
+
return {
|
|
3524
|
+
group: groupIndex,
|
|
3525
|
+
rule: ruleIndex,
|
|
3526
|
+
code: result.error,
|
|
3527
|
+
scope: Scope.CALLDATA,
|
|
3528
|
+
path: pathHex,
|
|
3529
|
+
opCode,
|
|
3530
|
+
operandData: bytesToHex(operandData),
|
|
3531
|
+
typeCode
|
|
3532
|
+
};
|
|
3533
|
+
}
|
|
3484
3534
|
if (!result.passed) return {
|
|
3485
3535
|
group: groupIndex,
|
|
3486
3536
|
rule: ruleIndex,
|
|
@@ -3570,6 +3620,18 @@ function evaluateQuantifier(qResult, callDataBytes, opCode, operandData, groupIn
|
|
|
3570
3620
|
} else leafLocation = elemLocation;
|
|
3571
3621
|
const applied = applyLeafOperator(callDataBytes, leafLocation, opCode, operandData);
|
|
3572
3622
|
if ("error" in applied) {
|
|
3623
|
+
if (applied.error === "NON_CANONICAL_VALUE") return {
|
|
3624
|
+
group: groupIndex,
|
|
3625
|
+
rule: ruleIndex,
|
|
3626
|
+
code: applied.error,
|
|
3627
|
+
scope: Scope.CALLDATA,
|
|
3628
|
+
path: pathHex,
|
|
3629
|
+
opCode,
|
|
3630
|
+
operandData: operandHex,
|
|
3631
|
+
typeCode: leafTypeCode,
|
|
3632
|
+
elementIndex: elemIndex,
|
|
3633
|
+
resolvedValue: applied.resolvedValue
|
|
3634
|
+
};
|
|
3573
3635
|
if (isUniversal) return {
|
|
3574
3636
|
group: groupIndex,
|
|
3575
3637
|
rule: ruleIndex,
|