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

fix: disallow contract registration in pxe of contract with duplicate private function selectors #9773

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sklppy88
Copy link
Contributor

@sklppy88 sklppy88 commented Nov 6, 2024

Related to #4433

This PR adds pretty naive validation when adding a contract artifact to the pxe database. Specifically it rejects adding contract artifacts to the PXE with duplicate private function selectors.

This also assumes the absence of partial artifacts.

Copy link
Contributor Author

sklppy88 commented Nov 6, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @sklppy88 and the rest of your teammates on Graphite Graphite

@sklppy88 sklppy88 changed the title init fix: ensure no duplicate private function selectors Nov 6, 2024
@sklppy88 sklppy88 marked this pull request as ready for review November 6, 2024 09:57
@sklppy88 sklppy88 force-pushed the ek/fix/4433/ensure-no-duplicate-private-function-selectors branch from 71afebc to 62ad893 Compare November 6, 2024 17:32
Copy link
Collaborator

@spalladino spalladino left a comment

Choose a reason for hiding this comment

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

The check looks good, but could you add a unit test?

That said, I'm still wondering if there's anywhere else where we should add this check. Eg should the class registerer require the caller to provide all leafs to ensure there are no duplicates? Still, a private contract can be used without going through the registerer. Do we need to make this check on every private kernel iteration? Seems wasteful. Anyway, my point is: I'd merge this PR (once it has a test) but not close the related issue until we've made a decision around this.

Also, regarding the "partial artifacts", I'm seeing that we have a (partially implemented) flow where the registerer can broadcast some private or unconstrained functions of a contract, just to make them more easily available. We can kill that flow if we find no use case for it.

Thoughts @nventuro ?

@AztecProtocol AztecProtocol deleted a comment from github-actions bot Nov 7, 2024
@nventuro
Copy link
Contributor

nventuro commented Nov 7, 2024

That said, I'm still wondering if there's anywhere else where we should add this check. Eg should the class registerer require the caller to provide all leafs to ensure there are no duplicates? Still, a private contract can be used without going through the registerer. Do we need to make this check on every private kernel iteration? Seems wasteful. Anyway, my point is: I'd merge this PR (once it has a test) but not close the related issue until we've made a decision around this.

I don't see an issue with a private contract having repeated selectors - you're free to do whatever. The real issue seems to be when this is a registered contract, i.e. a contract you intend other people to use. Notably I'm not considering scenarios in which you distribute the code without registration, but I'm not sure that's a problem.

So yeah in that case it does sound like it'd be good for the registerer to prevent this. But would we be able to provide all of the leaves in one go? I thought partial registration existed so that you could do it in smaller batches. Which relates to this:

Also, regarding the "partial artifacts", I'm seeing that we have a (partially implemented) flow where the registerer can broadcast some private or unconstrained functions of a contract, just to make them more easily available. We can kill that flow if we find no use case for it.

If we're unable to do full registration in a single call, then I'd consider introducing some intermediate 'partially registered' state.

@spalladino
Copy link
Collaborator

I thought partial registration existed so that you could do it in smaller batches.

Yep, that's the case. Private bytecode is pretty much unbounded, so it could be the case that you need multiple events across multiple txs to "post" all your contracts' private bytecode on-chain. But I'm still unsure if that's worth the effort.

I don't see an issue with a private contract having repeated selectors - you're free to do whatever.

That's my point: are you? I cannot think of a scenario where you could grief other users by setting up such a contract. It feels odd because it's just the PXE preventing duplicate selectors, but not the protocol, so a malicious user could have a tweaked PXE that can execute that contract but others can't. But I don't see how that's different from just not sharing the private bytecode for your contract.

@nventuro
Copy link
Contributor

nventuro commented Nov 7, 2024

so a malicious user could have a tweaked PXE that can execute that contract but others can't. But I don't see how that's different from just not sharing the private bytecode for your contract.

It's not just that - it's also that they could execute an alternative hidden function instead of the one they were supposed to call. But it does sound like the same as not fully shared code - if I can't see the entire thing, I can't trust it, and if I can't trust it then why do I care what it is you're running? (because I'm definitely not running it myself)

@sklppy88 sklppy88 force-pushed the ek/fix/4433/ensure-no-duplicate-private-function-selectors branch from 62ad893 to 08cb345 Compare November 13, 2024 20:54
@sklppy88
Copy link
Contributor Author

sklppy88 commented Nov 13, 2024

Have wrote a comment in the original issue here splitting it into three issues. This PR tackles one of them.

@sklppy88 sklppy88 force-pushed the ek/fix/4433/ensure-no-duplicate-private-function-selectors branch from 08cb345 to 3d0a9e2 Compare November 13, 2024 21:23
@sklppy88 sklppy88 changed the title fix: ensure no duplicate private function selectors fix: disallow contract registration in pxe of contract with duplicate private function selectors Nov 13, 2024
@sklppy88 sklppy88 force-pushed the ek/fix/4433/ensure-no-duplicate-private-function-selectors branch from 3d0a9e2 to e0bcc0f Compare November 14, 2024 13:52
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.

PXE should throw an error when trying to register a contract with duplicate selectors
3 participants