Skip to content

Conversation

@erights
Copy link
Member

@erights erights commented Feb 5, 2025

Staged on #11235 , which provides the E part

closes: #XXXX
refs: endojs/endo#2710 #1905 #1913 #1915 #2155 #2156 #2230 #4212 #4217 #10951 #11235

Description

Implements minimal want patterns, where the only supported pattern is M.containerHas

  • Zoe-level changes to accept want patterns

Security Considerations

none

Scaling Considerations

By allowing want patterns, might this make the processing of wants more expensive?

Documentation Considerations

Need to update the Zoe API docs to explain want-patterns

Testing Considerations

  • Need to add Zoe tests once the Zoe changes are in

Upgrade Considerations

None

  • Need to update NEWS.md for Zoe

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 5, 2025

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9b970c3
Status:🚫  Build failed.

View logs

@erights erights force-pushed the markm-min-want-patterns-3 branch 5 times, most recently from ffd5cdd to b2b30dc Compare February 11, 2025 01:38
@erights erights force-pushed the markm-min-want-patterns-3 branch 2 times, most recently from a2c8801 to b8ebc19 Compare March 13, 2025 21:39
@erights erights force-pushed the markm-min-want-patterns-3 branch 2 times, most recently from c1fbfcf to 3698a77 Compare March 14, 2025 21:01
@erights erights changed the title feat(ertp,zoe): minimal want patterns using M.has(el,n) feat(ertp,zoe): minimal want patterns using M.containerHas(el,n) Mar 18, 2025
@erights erights force-pushed the markm-min-want-patterns-3 branch from a04ee47 to 20b287d Compare March 18, 2025 18:46
erights added a commit to endojs/endo that referenced this pull request Mar 19, 2025
Closes: #XXXX
Refs: #2002 #2008 #2113 #1739
Agoric/agoric-sdk#10952

## Description

This PR adds a new `M.containerHas(elementPatt, positiveBigint)`
matcher, and exported `containerHasSplit` function. This is motivated to
support Agoric/agoric-sdk#10952 , which
introduces a minimal form of want pattern in terms of `M.containerHas`.

- [x] Actually merging this must happen only after we've decided either
to move forward with #2008 or to give up on it. Once a decision is made,
and even before it is acted on, then this PR can move forward. (Any
decision to move forward or not with #2008 should also consider changing
the default of the feature flag introduced by #2002 .)

### Security Considerations

none

### Scaling Considerations

Might help due to early termination of the split operations, which
Agoric/agoric-sdk#10952 uses for
`AmountMath.isGTE`.

### Documentation Considerations

Already doc-documents `M.containerHas` in the types.js file for `M`.
That's probably good enough for this PR. The interesting documentation
will be explaining want patterns in
Agoric/agoric-sdk#10952

### Testing Considerations

Added tests for `M.containerHas`

### Compatibility Considerations

The reason to postpone merging this PR until decisions are made on #2008
is that this PR will further expose `rankOrder` in the API, amplifying
the danger that changing the string order will cause surprising
observable changes.

### Upgrade Considerations

This PR itself does not introduce any BREAKING changes or Upgrade
issues.

- [x] Update `NEWS.md` for user-facing changes.
@erights erights force-pushed the markm-min-want-patterns-3 branch from 1efc171 to 27b3006 Compare March 22, 2025 16:10
@erights erights changed the base branch from master to markm-zoe-types-gardening March 22, 2025 16:11
@erights erights force-pushed the markm-zoe-types-gardening branch from bc8b038 to bbd4873 Compare March 22, 2025 17:03
Base automatically changed from markm-zoe-types-gardening to master March 22, 2025 19:35
@github-actions
Copy link

Base branch is changed to master. Please re-run the integration tests by adding 'force:integration' label.

@erights erights force-pushed the markm-min-want-patterns-3 branch 2 times, most recently from a91d27c to 28f79dd Compare March 24, 2025 22:51
kriskowal added a commit to endojs/endo that referenced this pull request Mar 24, 2025
# `ses` v1.12.0

- The `evalTaming:` option values are renamed:

  - from `'safeEval'`, `'unsafeEval'`, and `'noEval'`
  - to `'safe-eval'`, `'unsafe-eval'`, and `'no-eval'`

in order to follow the convention that lockdown option values use
kebob-case rather than camelCase. To avoid breaking old programs during
the transition, the old names are deprecated, but continue to work for
now.

- The value of expressions like `typeof unlikelyGlobal` is now
`undefined` instead of producing a `ReferenceError` because it proves
impossible to do so without revealing what properties exist on the host
`globalThis` to compartmentalized code.

# `@endo/patterns` v1.5.0

- New pattern: `M.containerHas(elementPatt, bound = 1n)` motivated to
support want patterns in Zoe, to pull out only `bound` number of
elements that match `elementPatt`. `bound` must be a positive bigint.

- Closely related, `@endo/patterns` now exports `containerHasSplit` to
support ERTP's use of `M.containerHas` on non-fungible (`set`,
`copySet`) and semifungible (`copyBag`) assets, respectively. See
Agoric/agoric-sdk#10952 .

# `@endo/import-bundle` v1.4.0

- Adds support for `test` format bundles, which simply return a promise
for an object that resembles a module exports namespace with the objects
specified on the symbol-named property @exports, which is deliberately
not JSON serializable or passable.
- Adds a `typedImportBundle<ExpectedExportsNamespace>` function with a
proper type signature, to provide a narrower signature than `any`
without disrupting existing usage.

# `@endo/bundle-source` v4.0.0

- Replaces the implementation for the `nestedEvaluate` and `getExport`
formats with one based on Endo's Compartment Mapper instead of Rollup,
in order to obviate the need to reconcile source map transforms between
Rollup and the underlying Babel generator. As a consequence, we no
longer generate a source map for the bundle, but Babel ensures that we
preserve line and column numbers between the original source and the
bundled source.

# `@endo/compartment-mapper` v1.6.0

- Accommodates CommonJS modules that use `defineProperty` on `exports`.

- Divides the role of `makeBundle` into `makeScript` and `makeFunctor`.
The new `makeScript` replaces `makeBundle` without breaking changes,
producing a JavaScript string that is suitable as a `<script>` tag in a
web page.
- The new `makeFunctor` produces a JavaScript string that, when
evaluated, produces a partially applied function, so the caller can
provide runtime options.
- Both `makeScript` and `makeFunctor` now accept `format`, `useEvaluate`
and `sourceUrlPrefix` options.
- The functor produced by `makeFunctor` now accepts `evaluate`,
`require`, and `sourceUrlPrefix` runtime options.
- Both `makeScript` and `makeFunctor` now accept a `format` option.
Specifiying the `"cjs"` format allows the bundle to exit to the host's
CommonJS `require` for host modules.
- Adds `sourceDirname` to compartment descriptors in the compartment
maps generated by `mapNodeModules` and uses these to provide better
source URL comments for bundles generated by `makeScript` and
`makeFunctor`, by default.

These changes collectively allow us to replace the implementation of
`nestedEvaluate` and `getExports` formats in `@endo/bundle-source`,
including the preservation of useful line numbers and file names in
stack traces.

- `mapNodeModules`, `importLocation` and `loadLocation` now accept a
`log` option for users to define a custom logging function. As of this
writing, _only `mapNodeModules`_ will potentially call this function if
provided. Expansion of log messaging and support for the `log` option in
more APIs is expected _in the future_.

# `@endo/evasive-transform` v1.4.0

- Adds a `sourceMap` option so that the generated sourcemap can project
back to the original source code without `unmapLoc`.
- Removes support for sourcemap `unmapLoc` because it is not used by
contemporary Endo packages. The option is now ignored.
@erights erights force-pushed the markm-min-want-patterns-3 branch 2 times, most recently from 5260960 to 43794cc Compare March 25, 2025 14:04
@erights erights force-pushed the markm-min-want-patterns-3 branch 3 times, most recently from 7e865f7 to 113653c Compare April 8, 2025 01:33
@erights erights force-pushed the markm-min-want-patterns-3 branch 2 times, most recently from a1ed11d to 6f54123 Compare April 8, 2025 20:36
@erights erights changed the base branch from master to markm-want-patterns-only-ertp April 8, 2025 20:37
@erights erights force-pushed the markm-min-want-patterns-3 branch from 6f54123 to 67b544c Compare April 8, 2025 20:44
@erights erights changed the title feat(ertp,zoe): minimal want patterns using M.containerHas(el,n) zoe part of minimal want patterns using M.containerHas(el,n) Apr 8, 2025
@erights erights changed the title zoe part of minimal want patterns using M.containerHas(el,n) feat(zoe): zoe part of minimal want patterns using M.containerHas(el,n) Apr 8, 2025
@erights erights force-pushed the markm-want-patterns-only-ertp branch from ae6b40c to 2e4d932 Compare April 8, 2025 20:55
@erights erights force-pushed the markm-min-want-patterns-3 branch from 67b544c to 89b0caa Compare April 8, 2025 21:00
@erights erights force-pushed the markm-want-patterns-only-ertp branch from 2e4d932 to 979da2a Compare April 8, 2025 21:09
@erights erights force-pushed the markm-min-want-patterns-3 branch from 89b0caa to e13d700 Compare April 8, 2025 21:11
@erights erights force-pushed the markm-want-patterns-only-ertp branch from 979da2a to b01e796 Compare July 21, 2025 22:54
@erights erights force-pushed the markm-min-want-patterns-3 branch from e13d700 to 9b970c3 Compare July 21, 2025 23:01
@erights erights requested a review from Copilot September 16, 2025 08:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements minimal want patterns support in Zoe, allowing the use of M.containerHas(el,n) patterns in proposal wants. The implementation focuses on the Zoe-side infrastructure needed to handle amount bounds (patterns) rather than just exact amounts in proposal wants.

Key changes:

  • Updates type definitions to distinguish between Amount and AmountBound types
  • Modifies proposal processing to support patterns in want clauses while maintaining backwards compatibility
  • Adds infrastructure for pattern validation and conversion

Reviewed Changes

Copilot reviewed 20 out of 22 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/zoe/tools/setup-zoe.js Updates import organization for Installation type
packages/zoe/test/unitTests/zoe/escrowStorage.test.js Adds mock getAssetKindByBrand function parameter to test calls
packages/zoe/test/unitTests/setupBasicMints.js Replaces AmountMath.make with direct amount construction and updates type annotations
packages/zoe/test/unitTests/cleanProposal.test.js Updates tests to use M.containerHas patterns instead of M.any()
packages/zoe/test/types.test-d.ts Reorganizes type imports for Installation
packages/zoe/src/zoeService/zoeStorageManager.js Passes getAssetKindByBrand function to provideEscrowStorage
packages/zoe/src/zoeService/types.ts Major type reorganization introducing AmountBound types and consolidating imports
packages/zoe/src/zoeService/internal-types.js Updates type imports and references
packages/zoe/src/zoeService/escrowStorage.js Adds getAssetKindByAmount helper and updates empty amount creation
packages/zoe/src/types.ts Minor import reorganization
packages/zoe/src/typeGuards.js Replaces AmountPatternKeywordRecordShape with AmountBoundKeywordRecordShape
packages/zoe/src/contracts/loan/borrow.js Adds type assertions and pattern validation for amounts
packages/zoe/src/contracts/auction/secondPriceLogic.js Adds type assertion for brand
packages/zoe/src/contracts/auction/firstPriceLogic.js Adds type assertion for brand
packages/zoe/src/contractSupport/zoeHelpers.js Adds mustBeKey helper and updates swapExact to handle amount bounds
packages/zoe/src/contractSupport/atomicTransfer.js Updates to support AmountBound types in transfer operations
packages/zoe/src/contractFacet/types.ts Updates TransferPart type to use AmountBoundKeywordRecord
packages/zoe/src/contractFacet/reallocate.js Adds pattern validation for transfer amounts
packages/zoe/src/contractFacet/offerSafety.js Updates to work with AmountBound types
packages/zoe/src/cleanProposal.js Major refactoring to support AmountBound validation and M.containerHas patterns

resultingAllocations.push([seat, newAlloc]);
}
return resultingAllocations;
return harden(resultingAllocations);
Copy link

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from returning resultingAllocations to harden(resultingAllocations) suggests the original array wasn't hardened. This should be verified against the function's return type expectations and existing callers to ensure compatibility.

Copilot uses AI. Check for mistakes.
Comment on lines +77 to +88
* @param {AmountBoundKeywordRecord} want
* @param {string} complaint
* @returns {AmountKeywordRecord}
*/
export const mustBeKey = (want, complaint) => {
if (isKey(want)) {
return want;
}
if (isPattern(want)) {
throw Fail`${b(complaint)}: ${want}`;
}
throw Fail`Must be key: ${want}`;
Copy link

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The function parameter is named want but the function is generic and could be used for other purposes. Consider renaming to value or input for better clarity.

Suggested change
* @param {AmountBoundKeywordRecord} want
* @param {string} complaint
* @returns {AmountKeywordRecord}
*/
export const mustBeKey = (want, complaint) => {
if (isKey(want)) {
return want;
}
if (isPattern(want)) {
throw Fail`${b(complaint)}: ${want}`;
}
throw Fail`Must be key: ${want}`;
* @param {AmountBoundKeywordRecord} value
* @param {string} complaint
* @returns {AmountKeywordRecord}
*/
export const mustBeKey = (value, complaint) => {
if (isKey(value)) {
return value;
}
if (isPattern(value)) {
throw Fail`${b(complaint)}: ${value}`;
}
throw Fail`Must be key: ${value}`;

Copilot uses AI. Check for mistakes.
}
const fromAmounts = mustBeKey(
fromAmountBounds,
'TODO: atomicRearange does not yet support AmountBounds',
Copy link

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"atomicRearange" should be "atomicRearrange" (missing 'r').

Suggested change
'TODO: atomicRearange does not yet support AmountBounds',
'TODO: atomicRearrange does not yet support AmountBounds',

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants