Skip to content

Commit

Permalink
fix(orchestration): denomAmounts must be non-negative (#10458)
Browse files Browse the repository at this point in the history
closes: #XXXX
refs: #9532 which seems to be where the `M.bigint()` came from

## Description

The `DenomAmountShape` was using only `M.bigint()` to validate a DenomAmount, which misses an opportunity to easily ensure that these amount values never go negative. This PR changes this to `M.nat()`, making it consistent with the immediately following `AnyNatAmountShape` as well.

### Security Considerations

Accidentally admitting negative value amounts might enable attacks allowing overdrawn spending or creation of new units. There may or may not be such a security vulnerability in this code, depending on whether the non-negative condition is ensured by other means, which I cannot determine. But fixing this is *at least* a belt-and-suspenders enforcement, through a declarative expression of the constraint.

### Scaling Considerations

none

### Documentation Considerations

should just remove the need to explain something else for the programmer to worry about.

### Testing Considerations

If we can find an actual vulnerability that this PR fixes, then we could test the difference. But I have not.

### Upgrade Considerations

If there are any such negative values in existing use, this PR is likely to break them. But their presence likely indicates corruption that we'd be better off causing a failure, rather than proceeding silently to corrupt other state.
  • Loading branch information
erights authored Nov 13, 2024
1 parent 59b1a9f commit 40e0e4e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Generated by [AVA](https://avajs.dev).
denom: Object @match:string {
payload: [],
},
value: Object @match:bigint {
value: Object @match:nat {
payload: [],
},
},
Expand Down Expand Up @@ -174,7 +174,7 @@ Generated by [AVA](https://avajs.dev).
denom: Object @match:string {
payload: [],
},
value: Object @match:bigint {
value: Object @match:nat {
payload: [],
},
},
Expand Down Expand Up @@ -211,7 +211,7 @@ Generated by [AVA](https://avajs.dev).
denom: Object @match:string {
payload: [],
},
value: Object @match:bigint {
value: Object @match:nat {
payload: [],
},
},
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/orchestration/src/typeGuards.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const DenomInfoShape = {
};

/** @type {TypedPattern<DenomAmount>} */
export const DenomAmountShape = { denom: DenomShape, value: M.bigint() };
export const DenomAmountShape = { denom: DenomShape, value: M.nat() };

/** @type {TypedPattern<Amount<'nat'>>} */
export const AnyNatAmountShape = harden({
Expand Down

0 comments on commit 40e0e4e

Please sign in to comment.