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

new smart wallet #6084

Merged
merged 5 commits into from
Sep 7, 2022
Merged

new smart wallet #6084

merged 5 commits into from
Sep 7, 2022

Conversation

turadg
Copy link
Member

@turadg turadg commented Aug 29, 2022

closes: #4488

Description

A whole new Smart Wallet contract. This builds on the design and code of the agsolo wallet but the fresh start reduces the code surface to audit for PSM launch. It's also designed from the ground up for POLA and to take advantage of marshalling contexts instead of board ids.

Some features that aren't needed for PSM launch have been omitted and filed for future work:

And these are still needed for PSM launch:

Security Considerations

This let's anyone send a message to the contract that can execute arbitrary offers on a wallet instance. It relies on the bridge handler to ensure that the only messages that reach a wallet come from its owner.

Documentation Considerations

New docs including an attackers guide.

Testing Considerations

New tests

@turadg turadg force-pushed the ta/split-smartwallet branch 2 times, most recently from 930e7de to eb052cd Compare August 31, 2022 21:49
@turadg turadg requested review from dckc and michaelfig August 31, 2022 21:49
@dckc
Copy link
Member

dckc commented Aug 31, 2022

Let's please be sure numWantsSatisfied is in offer status records:
#4809 (comment)

Copy link
Member

@dckc dckc left a comment

Choose a reason for hiding this comment

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

solid progress!

packages/wallet/contract/src/smartWallet.js Outdated Show resolved Hide resolved
packages/wallet/contract/src/smartWallet.js Outdated Show resolved Hide resolved
packages/wallet/contract/src/smartWallet.js Outdated Show resolved Hide resolved
packages/wallet/contract/src/smartWallet.js Outdated Show resolved Hide resolved
packages/wallet/contract/src/smartWallet.js Outdated Show resolved Hide resolved
packages/wallet/contract/src/smartWallet.js Outdated Show resolved Hide resolved
packages/wallet/contract/src/smartWallet.js Outdated Show resolved Hide resolved
packages/wallet/contract/src/smartWallet.js Outdated Show resolved Hide resolved
packages/wallet/contract/src/walletFactory.js Outdated Show resolved Hide resolved
);

// @ts-expect-error faulty generic typedef
wallet.executeOffer(offerSpecCapData);
Copy link
Member

Choose a reason for hiding this comment

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

await? ah. no. We shouldn't rely on getting a promise for the result. Seems worth documenting with void if not a comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

you mean document at the callsite? the docs on executeOffer already say it's a synchronous function:

* @returns {void} when the offer has been sent to Zoe; payouts go into this wallet's purses

@dckc
Copy link
Member

dckc commented Sep 1, 2022

@turadg here's hoping the results of this work don't have memory performance issues such as

@turadg turadg force-pushed the ta/split-smartwallet branch 2 times, most recently from 1a58fc0 to cfd2b19 Compare September 2, 2022 17:42
@@ -149,7 +149,7 @@ export const start = async (zcf, privateArgs, baggage) => {
/**
* @param {ZCFSeat} seat
* @param {Amount<'nat'>} given
* @param {Amount<'nat'>} [wanted]
* @param {Amount<'nat'>} [wanted] defaults to maximum anchor (given exchange rate minus fees)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, when would you want anything less than the maximum?

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure myself. A case I can imagine is that if you want a certain amount and you don't know the fees you give a surplus and rely on the contract to only take what's necessary for the want.

packages/wallet/contract/src/invitations.js Outdated Show resolved Hide resolved
packages/wallet/contract/src/smartWallet.js Outdated Show resolved Hide resolved
packages/wallet/contract/src/utils.js Outdated Show resolved Hide resolved
/**
*
* @param {AmountKeywordRecord} amountKeywordRecord
* @param {(brand: Brand) => ERef<Purse>} purseForBrand
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Rename to getPurseForBrand (here and below). I thought that this was just a single purse reference based on the name.

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 function does just look up a single purse for a single brand.

packages/wallet/contract/src/utils.js Outdated Show resolved Hide resolved
packages/wallet/contract/src/smartWallet.js Outdated Show resolved Hide resolved
* @returns {void} when the offer has been sent to Zoe; payouts go into this wallet's purses
* @throws if any parts of the offer can be determined synchronously to be invalid
*/
executeOffer: capData => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this purposely doesn't handle attestations for now right?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, not in scope for PSM launch. @dckc will supporting that affect the API?

Copy link
Member

Choose a reason for hiding this comment

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

@samsiegart remind me how we represented "this offer should include an attestation" in our acceptOffer argument?

Copy link
Member

@dckc dckc left a comment

Choose a reason for hiding this comment

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

just a few comments here and there. I haven't managed to read through the whole thing.

packages/wallet/contract/src/smartWallet.js Outdated Show resolved Hide resolved
packages/wallet/contract/src/smartWallet.js Outdated Show resolved Hide resolved
packages/wallet/contract/src/smartWallet.js Outdated Show resolved Hide resolved
packages/wallet/contract/src/smartWallet.js Outdated Show resolved Hide resolved
*
* @type {MapStore<Brand, ERef<Purse<'set'>>>}
*/
const brandPurses = makeScalarBigMapStore('brand purses', { durable: true });
Copy link
Member

Choose a reason for hiding this comment

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

It still seems like we could reduce the scope of this by, for example, moving it along with publishPurses later in the file.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. For auditability I tried to gather the state and for upgradability I tried to gather precious state. But it would be better to have a comment explicitly about state requirements and let them be defined in the most advantageous place for safety.

@turadg turadg force-pushed the ta/split-smartwallet branch 2 times, most recently from 75371b5 to b63bf9f Compare September 3, 2022 23:33
@turadg turadg changed the title ta/split smartwallet new smart wallet Sep 3, 2022
@turadg turadg marked this pull request as ready for review September 4, 2022 00:42
@turadg turadg force-pushed the ta/split-smartwallet branch 2 times, most recently from 6c2c725 to d70db59 Compare September 4, 2022 21:28
Copy link
Member

@dckc dckc left a comment

Choose a reason for hiding this comment

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

oops; forgot to submit these comments...

packages/smart-wallet/src/walletFactory.js Show resolved Hide resolved
packages/smart-wallet/src/smartWallet.js Outdated Show resolved Hide resolved
packages/smart-wallet/src/smartWallet.js Outdated Show resolved Hide resolved
packages/smart-wallet/src/smartWallet.js Outdated Show resolved Hide resolved
@turadg turadg force-pushed the ta/split-smartwallet branch 2 times, most recently from 20f897d to abfb448 Compare September 6, 2022 19:24
@dckc dckc requested a review from dtribble September 7, 2022 17:19
@turadg turadg requested a review from dckc September 7, 2022 18:58
@turadg turadg added the automerge:no-update (expert!) Automatically merge without updates label Sep 7, 2022
Copy link
Member

@dckc dckc left a comment

Choose a reason for hiding this comment

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

Great work!

packages/smart-wallet/package.json Outdated Show resolved Hide resolved
packages/smart-wallet/src/utils.js Show resolved Hide resolved
@mergify mergify bot merged commit 1feaac3 into master Sep 7, 2022
@mergify mergify bot deleted the ta/split-smartwallet branch September 7, 2022 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:no-update (expert!) Automatically merge without updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor wallet backend for POLA
3 participants