Conversation
…ning (drydocs#158) Adds a Soroban __constructor that records admin atomically with contract creation, eliminating the deploy-then-initialize window where a mempool watcher could front-run the intended deployer and claim the admin role. - initialize no longer accepts an admin parameter; it reads the admin fixed by __constructor and require_auth against it. - AlreadyInitialized check now guards DataKey::Token instead of Admin, since Admin is set by the constructor. - All tests updated to pass admin to env.register(Tholos, (admin,)) and drop the admin arg from initialize/try_initialize calls. - New test confirms initialize rejects a caller whose auth is mocked for an address other than the constructor-time admin.
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #158.
initializeincontracts/tholostookadminas a caller-supplied parameter and only guarded against a second call (AlreadyInitialized). Since deploy and initialize are separate Soroban transactions, nothing tied the call to whoever actually deployed the contract.This PR adds a
__constructorthat pinsadminatomically with contract creation (the same pattern already landed for v2 in #183 / #154).initializeno longer accepts anadminparameter; it reads the admin fixed at deploy time and authenticates against that.Changes
__constructor(env, admin): setsDataKey::Adminand bumps TTL, invoked automatically by Soroban as part ofCreateContractV2.initialize: removesadminparameter, reads admin from storage (set by constructor), checksDataKey::TokenforAlreadyInitializedinstead ofDataKey::Admin.admintoenv.register(Tholos, (admin,))and drop&adminfrominitialize/try_initializecalls.test_initialize_rejects_caller_other_than_constructor_adminmocks auth for an attacker distinct from the real constructor-time admin and confirmsinitializepanics (auth rejection).