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

config lint to harden exports #9734

Merged
merged 6 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/boot/test/bootstrapTests/zcf-upgrade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { makeZoeDriver } from '../../tools/drivers.ts';

const dirname = path.dirname(new URL(import.meta.url).pathname);

const ZCF_PROBE_SRC = './zcfProbe.js';
const ZCF_PROBE_SRC = './zcfProbe.contract.js';

/**
* @file Bootstrap test of upgrading ZCF to support atomicRearrange internally.
Expand Down Expand Up @@ -85,7 +85,7 @@ test('run restart-vats proposal', async t => {
await controller.validateAndInstallBundle(zcfProbeBundle);
// This test self-sufficiently builds all the artifacts it needs. The test in
// .../packages/deployment/upgradeTest/upgrade-test-scripts/unreleased-upgrade/zoe-upgrade/
// needs a bundled copy of ./zcfProbe.js as of the final commit that will be
// needs a bundled copy of ./zcfProbe.contract.js as of the final commit that will be
// installed on-chain. Uncomment the following line and add
// `import fs from "fs";` to generate a bundle of the contract.
// fs.writeFileSync('bundles/prober-contract-bundle.json', JSON.stringify(zcfProbeBundle));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,4 @@ export const start = async (zcf, privateArgs, baggage) => {
creatorFacet: probe,
});
};
harden(start);
8 changes: 8 additions & 0 deletions packages/eslint-config/eslint-config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,19 @@ module.exports = {
'no-unused-vars': 'off',
},
},
{
// Zoe contract module
files: ['**/*.contract.js'],
rules: {
'@endo/harden-exports': 'error',
},
},
{
// Orchestration flows
files: ['**/*.flows.js'],
rules: {
'no-restricted-syntax': ['error', ...orchestrationFlowRestrictions],
'@endo/harden-exports': 'error',
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const makeAllManagersDo = (collateralManagers, vaultManagers) => {
* @param {ERef<Marshaller>} marshaller
* @param {import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit} makeRecorderKit
* @param {import('@agoric/zoe/src/contractSupport/recorder.js').MakeERecorderKit} makeERecorderKit
* @param managerParams
* @param {Record<string, import('./params.js').VaultManagerParamOverrides>} managerParams
*/
const prepareVaultDirector = (
baggage,
Expand Down
7 changes: 2 additions & 5 deletions packages/inter-protocol/test/supports.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,8 @@ harden(setUpZoeForTest);
*/
export const setupBootstrap = async (t, optTimer) => {
const trace = makeTracer('PromiseSpace', false);
const space = /** @type {any} */ (makePromiseSpace(trace));
const { produce, consume } = /**
* @type {import('../src/proposals/econ-behaviors.js').EconomyBootstrapPowers &
* BootstrapPowers}
*/ (space);
const space = /** @type {Space} */ (makePromiseSpace(trace));
const { produce, consume } = space;

await produceDiagnostics(space);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ const contract = async (
};

export const start = withOrchestration(contract);
harden(start);

/** @typedef {typeof start} AutoStakeItSF */
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,4 @@ export const makeAccounts = async (
);
return portfolioHolder.asContinuingOffer();
};
harden(makeAccounts);
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@ const contract = async (
};

export const start = withOrchestration(contract);
harden(start);

/** @typedef {typeof start} BasicFlowsSF */
2 changes: 2 additions & 0 deletions packages/orchestration/src/examples/basic-flows.flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const makeOrchAccount = async (orch, _ctx, seat, { chainName }) => {
const orchAccount = await remoteChain.makeAccount();
return orchAccount.asContinuingOffer();
};
harden(makeOrchAccount);

/**
* Create accounts on multiple chains and return them in a single continuing
Expand Down Expand Up @@ -77,3 +78,4 @@ export const makePortfolioAccount = async (

return portfolioHolder.asContinuingOffer();
};
harden(makePortfolioAccount);
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const SingleAmountRecord = M.and(
}),
M.not(harden({})),
);
harden(SingleAmountRecord);

/**
* Orchestration contract to be wrapped by withOrchestration for Zoe
Expand Down Expand Up @@ -86,3 +87,4 @@ const contract = async (
};

export const start = withOrchestration(contract);
harden(start);
6 changes: 3 additions & 3 deletions packages/orchestration/src/examples/sendAnywhere.flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ const { entries } = Object;
* @param {ZCFSeat} seat
* @param {{ chainName: string; destAddr: string }} offerArgs
*/
export async function sendIt(
export const sendIt = async (
orch,
{ contractState, localTransfer },
seat,
offerArgs,
) {
) => {
mustMatch(offerArgs, harden({ chainName: M.scalar(), destAddr: M.string() }));
const { chainName, destAddr } = offerArgs;
// NOTE the proposal shape ensures that the `give` is a single asset
Expand Down Expand Up @@ -59,5 +59,5 @@ export async function sendIt(
chainId,
},
);
}
};
harden(sendIt);
1 change: 1 addition & 0 deletions packages/orchestration/src/examples/stakeBld.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,4 @@ export const start = async (zcf, privateArgs, baggage) => {

return { publicFacet };
};
harden(start);
3 changes: 3 additions & 0 deletions packages/orchestration/src/examples/stakeIca.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export const meta = harden({
timer: TimerServiceShape,
},
});
harden(meta);
export const privateArgsShape = meta.privateArgsShape;
harden(privateArgsShape);

/**
* @typedef {{
Expand Down Expand Up @@ -150,5 +152,6 @@ export const start = async (zcf, privateArgs, baggage) => {

return { publicFacet };
};
harden(start);

/** @typedef {typeof start} StakeIcaSF */
2 changes: 2 additions & 0 deletions packages/orchestration/src/examples/swapExample.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ harden(meta);
*/
export const makeNatAmountShape = (brand, min) =>
harden({ brand, value: min ? M.gte(min) : M.nat() });
harden(makeNatAmountShape);

/**
* Orchestration contract to be wrapped by withOrchestration for Zoe
Expand Down Expand Up @@ -127,3 +128,4 @@ const contract = async (zcf, privateArgs, zone, { orchestrate, zoeTools }) => {
};

export const start = withOrchestration(contract);
harden(start);
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ const contract = async (zcf, privateArgs, zone, { orchestrate }) => {
};

export const start = withOrchestration(contract);
harden(start);
18 changes: 13 additions & 5 deletions packages/orchestration/test/examples/bad.flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,29 @@
*/

// TODO error on exports that:
// - aren't hardened (probably a new rule in @endo/eslint-plugin )
// - don't satisfy orchestration flow type

// eslint-disable-next-line no-restricted-syntax -- intentional for test
import { E } from '@endo/far';

export function notFlow() {
console.log('This function is not a flow');
// eslint-disable-next-line @endo/harden-exports -- intentional for test
export function unhardenable() {
console.log('hardening on function keyword is not safe due to hoisting');
}
harden(unhardenable);

export const notFlow = () => {
console.log('This function is not a flow');
};
harden(notFlow);

// eslint-disable-next-line @endo/harden-exports -- intentional for test
export async function notHardened() {
console.log('This function is the most minimal flow, but it’s not hardened');
}

export async function usesE(orch, { someEref }) {
export const usesE = async (orch, { someEref }) => {
// eslint-disable-next-line no-restricted-syntax -- intentional for test
await E(someEref).foo();
}
};
harden(usesE);
Loading