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

[Clarity] add functions to query the transaction asset map as it is running #3094

Open
jcnelson opened this issue Apr 18, 2022 · 7 comments
Open
Assignees
Labels
consensus-critical icebox Issues that are not being worked on

Comments

@jcnelson
Copy link
Member

The (as-contract) built-in should be extended to take a list of post-conditions on assets moved by the contract, in order to guard against things the contract might do (or might get tricked into doing). In particular, the fact that a trait implementation can be passed into (as-contract) means that a contract can be coerced to run arbitrary Clarity code (by design), which means that the caller of (as-contract) should be able to defend the contract against attempts to do things like move tokens and assets.

@jcnelson
Copy link
Member Author

Alternative: expose a way to query the asset map from Clarity. Then a contract that wanted to guard could do a lot more with this, and the cost assessment is a lot easier to tabulate.

@jcnelson
Copy link
Member Author

jcnelson commented Apr 25, 2022

Implement this as a special closure type that evaluates a code block, and then inspects the resulting asset map.

EDIT: Better yet, just add built-ins for querying the asset map at any point during the contract's execution.

@hstove
Copy link
Contributor

hstove commented May 5, 2022

I am unfamiliar with a use-case where a contract would use as-contract with a non-trusted trait. If an attacker was able to get a contract to transfer funds from itself, that seems like a full-stop exploit from a contract design standpoint.

@jcnelson jcnelson changed the title [clairty] (as-contract) should take post-conditions [clairty] expose post-conditions as first-class Clarity built-ins May 5, 2022
@jcnelson jcnelson changed the title [clairty] expose post-conditions as first-class Clarity built-ins [clairty] add functions to query the transaction asset map as it is running May 5, 2022
@jcnelson
Copy link
Member Author

jcnelson commented May 5, 2022

Right; the problem is that this is a design foot-gun. Fundamentally, the problem is that developers may find themselves wanting to do some sort of dynamic dispatch to user-submitted (untrusted) code. The contract developer should be able to specify post-conditions on the contract-call in order to guard against the user-submitted code from moving assets it's not supposed to be moving. The wallet could theoretically analyze the call graph and figure out what the set of reachable asset movements are, but that doesn't let the developer write out what kinds of safety assumptions they intend the code to adhere to. Similarly, a SIP could be written to require certain types of trait implementations, like SIP 009 and SIP 010, to supply a wallet-parseable set of post-conditions, but this would require all wallet implementations to correctly parse this list and attach it to transactions.

What we really need is a way to query the transaction's ongoing asset map -- i.e. the set of token movements that have occurred over the lifetime of the transaction. This data structure gets fed into the post-condition processor, but not the Clarity VM. If we could expose it to the Clarity VM, then it's trivial for the developer to add arbitrary safety guards on asset movements before and after contract-calls (or anywhere in the code).

@kantai kantai changed the title [clairty] add functions to query the transaction asset map as it is running [Clarity] add functions to query the transaction asset map as it is running Jan 19, 2023
@jcnelson jcnelson assigned obycode and unassigned jcnelson Feb 22, 2023
@jcnelson
Copy link
Member Author

Re-assigning to @obycode, since this is part of the Clarity VM. Please feel free to re-assign!

@hstove
Copy link
Contributor

hstove commented Mar 8, 2023

One interesting use case:

With contract-based multisigs, signers cannot attest to post conditions when approving a transaction - they can only approve a specific contract call. While they can read the source code of whatever the transaction, it's possible that the actual asset transfer amounts are varied. For example, if conducting a swap from one token to another.

With this feature, the multisig contract can persist something similar to post conditions and verify that they're all correct after executing the contract call.

@obycode
Copy link
Contributor

obycode commented Dec 20, 2024

See also #2921.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consensus-critical icebox Issues that are not being worked on
Projects
Status: Status: 🆕 New
Development

No branches or pull requests

4 participants