-
Notifications
You must be signed in to change notification settings - Fork 44
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
Implement CAP-58 (constructor support) #1447
Conversation
If a pre-v22 contract gets its wasm updated in v22+ protocol with |
Nevermind, I see this mentioned in the CAP, |
2b4a5b0
to
25551c6
Compare
The implementation itself is fairly simple (thanks to not needing to support v21 semantics) and follows the CAP. It only has a few caveats: - Pre-v22 protocol Wasms are treated as if they don't have a constructor (they shouldn't have it anyway, but just in case they do we ignore it in order to not break the contract semantics). Thus we don't need to even try calling constructor for them - We try to call constructor for all v22+ contracts, so we charge for VM instantiation, which increases the creation cost to some degree. I'm not sure if we can discount calling non-existent functions; if we find that necessary, we can still improve this before the protocol release. Bulk of this change is tests, and testing is really not trivial as we want to cover a set product of several different options: - p21 vs p22 contracts - v1 vs v2 host function - Constructor return values and errors - constructor arguments present/not present/'default' constructor - auth for constructor itself and inside the constructor - deployer support - invoker auth support - custom account support To make things worse, a contract may only have a single constructor, so this needed a lot of new test Wasms. I'm sure I haven't covered every possible combination, but at least tried to have some basic coverage for most of the cases and most obvious combinations.
The diffs are quite significant, but generally seem to fall into the following categories: - Changed auth data structure hashes (as we use the new XDR structure for the host fn) - Slightly increased instructions and memory for the CreateContract host fn and other XDRs that include it (+24 bytes) - New calls to the 'default' constructor for applicable contracts (typically generated Wasms that target the current protocol)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple comments. I still need to look at the auth changes.
After thinking for a bit, it doesn't seem like this could cause any security or logic issues, so we can improve backwards compatibility without much added maintenance cost.
This reverts commit 5ed156b.
What
The implementation itself is fairly simple (thanks to not needing to support v21 semantics) and follows the CAP-58. It only has a few caveats:
Bulk of this change is tests, and testing is really not trivial as we want to cover a set product of several different options:
To make things worse, a contract may only have a single constructor, so this needed a lot of new test Wasms.
Why
See CAP-58 motivation.
Known limitations
I'm sure I haven't covered every possible combination of parameters in tests, but at least tried to have some basic coverage for most of the cases and most obvious combinations.