Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No fake baggage #7636

Merged
merged 11 commits into from
May 10, 2023
Merged

No fake baggage #7636

merged 11 commits into from
May 10, 2023

Conversation

mhofman
Copy link
Member

@mhofman mhofman commented May 8, 2023

closes: #7578
closes: #7627
closes: #7651

Best reviewed commit-by-commit

Description

This is the result of a manual audit to track down and remove places where a fake baggage is created, or at least to explicitly contain it to tests, tools and demo contracts

In particular this PR does the following:

  • [refactor] Rename makeBoard to makeFakeBoard. I realized after the fact this was the same as reduce psuedo baggage #7627, but is slightly more complete and passes tests
  • [refactor] Introduce a makeDurableZoeKit which required a baggage, and deprecate makeZoeKit (with the removed options to specify a baggage). I also introduced a new makeZoeForTest tool and wrote a shared setupZoeForTest tool that creates a fake baggage, reducing the uses of makeDurableZoeKit to this test helper and the production vat-zoe
  • [refactor] Removed vat-zoe implementations used in tests and use the production one instead.
  • [fix] Make Zoe vat upgradable by stashing buildZoe params in the baggage. Fixes Zoe is not null-upgradable #7651
  • [fix] Remove the quoteMint from priceAuthority's privateArgs, and unconditionally create a durable issuer kit for it.
  • [chore] marked the remaining usages of makeIssueKit as not for production

Security Considerations

None

Scaling Considerations

None

Documentation Considerations

None

Testing Considerations

There is a new test tool for Zoe, which should be used instead of makeZoeKit, which is now deprecated.

Because of the makeFakeBoard rename, the following PR is required to land in documentation repo:

#documentation-branch: mhofman/7578-fix-make-zoe

@mhofman mhofman requested a review from turadg May 8, 2023 16:11
@@ -9,10 +9,15 @@ import { resolve as importMetaResolve } from 'import-meta-resolve';

import '../../exported.js';

// eslint-disable-next-line import/no-extraneous-dependencies
Copy link
Member

Choose a reason for hiding this comment

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

if it's a dep please include it in package.json. but I don't think it needs to be a dep…

Comment on lines 17 to 20
const { zoeService: zoe } = makeZoeKit(
makeScalarBigMapStore('zoe baggage', { durable: true }),
fakeVatAdmin,
);
Copy link
Member

Choose a reason for hiding this comment

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

this is common enough that there should be a single function to do it. perhaps makeZoeKitForTest in a tools export. Then most of these changes would be four chars at the call site (and an extra import, but on a package that's already a dependency).

Moreover, Zoe's baggage should always be durable, so the caller shouldn't be allowed to pass in any MapStore.

Copy link
Member Author

Choose a reason for hiding this comment

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

I introduced a makeZoeForTest, makeZoeKitForTest and common setupZoeForTest, and refactored all the tests to use these new tools. Its was a big refactor, but I think it paid out!

Copy link
Member

Choose a reason for hiding this comment

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

Looks it to me!

*/
const start = async (zcf, privateArgs) => {
const start = async (zcf, privateArgs, baggage) => {
Copy link
Member

Choose a reason for hiding this comment

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

please leave this contract alone because it's just an example, not part of production

* @deprecated use fluxAggregator
*
* This contract aggregates price values from a set of oracles and provides a
* PriceAuthority for their median. This naive method is game-able and so this module
* is a stub until we complete what is now in `fluxAggregatorKit.js`.
*

It is confusing that zoe/src/contracts has examples and production contracts. We have deferred cleaning up package factoring #4645

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Reverted, and annotated contract to be notForProductionUse

@@ -34,9 +33,11 @@ import { makePriceAuthorityTransform } from '../contractSupport/priceAuthorityTr
*/
export const prepare = async (
zcf,
{ quoteMint = makeIssuerKit('quote', AssetKind.SET).mint } = {},
{ quoteMint: providedQuoteMint } = {},
Copy link
Member

Choose a reason for hiding this comment

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

I don't see anywhere that this privateArg is provided. I think we're better off excising the privateArgs param. Please confirm @dckc .

Copy link
Member

Choose a reason for hiding this comment

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

yes, if it were important we would/should have had a test.

@michaelfig if you know something we haven't considered, please let us know.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed

* @param {import('@agoric/vat-data').Baggage} baggage
* @param {ERef<Mint<'set'>>} [providedQuoteMint]
*/
export const prepareQuoteMint = (baggage, providedQuoteMint) => {
Copy link
Member

Choose a reason for hiding this comment

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

when we drop the privateArg (see below) I think this will be better factored as a provideQuoteMint.

@@ -460,6 +460,7 @@ export const publishAgoricNames = async (
const marshaller = E(board).getPublishingMarshaller();

// XXX will fail upon restart, but so would the makeStoredPublishKit this is replacing
// XXX is that ok?
Copy link
Member

Choose a reason for hiding this comment

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

yes, there's only one production use of makeStoredPublishKit which is vote outcomes and we've elected to defer durability of governance.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated with comment explaining why this is ok

@@ -29,6 +29,7 @@ import { assert } from '@agoric/assert';
const start = zcf => {
const { tokenName = 'token' } = zcf.getTerms();
// Create the internal token mint
// makeIssuerKit fails upgrade, safe because demo only?
Copy link
Member

Choose a reason for hiding this comment

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

in this case yes

Copy link
Member Author

Choose a reason for hiding this comment

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

marked contract as notForProductionUse

@@ -39,6 +39,7 @@ export function buildRootObject() {
* @param {[AssetKind?, DisplayInfo?]} issuerArgs
*/
makeMintAndIssuer: (issuerNameSingular, ...issuerArgs) => {
// makeIssuerKit fails upgrade, safe because demo only?
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure. I see this in demo and devnet configs but also

"mints": {
"sourceSpec": "@agoric/vats/src/vat-mints.js"
},
"priceAuthority": {

@michaelfig ?

Copy link
Member

Choose a reason for hiding this comment

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

decentral-core-config.json is also non-production. See the $comment at the top.

Copy link
Member

@dckc dckc May 9, 2023

Choose a reason for hiding this comment

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

vat-mints is very much demo-only. It has the poison pill that is enforced by static analysis in a test:

import { notForProductionUse } from '@agoric/internal/src/magic-cookie-test-only.js';

test('no test-only code is in production configs', async t => {

Copy link
Member Author

@mhofman mhofman May 9, 2023

Choose a reason for hiding this comment

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

This notForProductionUse is pretty cool. I added it to the other zoe contracts with makeIssuerKit that are supposed to not end up in production.

Copy link
Member

@gibson042 gibson042 left a comment

Choose a reason for hiding this comment

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

These look like nice improvements!

}),
makeZoeKit(
makeScalarBigMapStore('zoe baggage', { durable: true }),
makeFakeVatAdmin(() => {}).admin,
Copy link
Member

Choose a reason for hiding this comment

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

Nit: we could probably clarify the purpose of this empty function by naming it something like ignoreTestContext (and likewise in packages/smart-wallet/test/supports.js).

Copy link
Member Author

Choose a reason for hiding this comment

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

The empty function was not needed in the first place. Gone in the refactor

@mhofman
Copy link
Member Author

mhofman commented May 9, 2023

Once this is green, I will rebase and fix up the commits, and mark as ready for review.

@mhofman mhofman force-pushed the mhofman/7578-no-fake-baggage branch 2 times, most recently from bdb380c to caa9e77 Compare May 9, 2023 21:43
@mhofman mhofman marked this pull request as ready for review May 9, 2023 21:45
@mhofman
Copy link
Member Author

mhofman commented May 9, 2023

@turadg it looks like since I removed the optional quoteMint of the scaled price authority, the type of privateArgs becomes empty and allows assignment of an arg of type string. This would not be a problem except that your Zoe type tests use that contract to as an example, and the type checking of privateArgs now fails an expected error. This is likely a case where if we were running in strict type mode / no implicit any, it would be fine, but alas we're not. I'm not sure of the best way forward to fix that one. Is there another contract that can be used here in place?

Error: test/types.test-d.ts(50,5): error TS2578: Unused '@ts-expect-error' directive.

@turadg
Copy link
Member

turadg commented May 9, 2023

I'm not sure of the best way forward to fix that one.

It's there to test that the types are defined so we can just give a different invalid argument.

  E(zoe).startInstance(
    scaledPriceInstallation,
    validIssuers,
    // @ts-expect-error includes an extra term
    { ...validTerms, extra: string },
  );

Copy link
Member

@turadg turadg left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the clean commits.

I left a separate comment on how to get types passing.

@@ -460,6 +460,8 @@ export const publishAgoricNames = async (
const marshaller = E(board).getPublishingMarshaller();

// XXX will fail upon restart, but so would the makeStoredPublishKit this is replacing
// Since we expect the bootstrap vat to be replaced instead of upgraded this should be
Copy link
Member

Choose a reason for hiding this comment

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

✏️

export const provideQuoteMint = baggage => {
/** @type {ERef<Mint<'set'>>} */
let baggageQuoteMint;
if (baggage.has(`quoteMintIssuerBaggage`)) {
Copy link
Member

Choose a reason for hiding this comment

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

consider a const

@mhofman
Copy link
Member Author

mhofman commented May 9, 2023

It's there to test that the types are defined so we can just give a different invalid argument.

That won't do because privateArgs: object now, which means it's equivalent to any in non strict TS mode....

@mhofman mhofman force-pushed the mhofman/7578-no-fake-baggage branch 2 times, most recently from 842dde2 to 4cd1c0e Compare May 10, 2023 00:09
Copy link
Contributor

@Chris-Hibbert Chris-Hibbert left a comment

Choose a reason for hiding this comment

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

LGTM

@mhofman mhofman force-pushed the mhofman/7578-no-fake-baggage branch from 4cd1c0e to ff38968 Compare May 10, 2023 01:21
@mhofman mhofman enabled auto-merge May 10, 2023 01:21
@mhofman mhofman added this pull request to the merge queue May 10, 2023
Merged via the queue into master with commit c78cb4c May 10, 2023
@mhofman mhofman deleted the mhofman/7578-no-fake-baggage branch May 10, 2023 02:34
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.

Zoe is not null-upgradable Audit makeScalarBigMapStore usages for pseudo baggage
6 participants