fix(tholos): pin admin in __constructor to close initialize front-running - #214
Merged
Merged
Conversation
This was referenced Sep 11, 2026
This was referenced Sep 12, 2026
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.
Summary
initialize(contracts/tholos/src/lib.rs) used to takeadminas a caller-supplied parameter and only check that address's signature, so whoever'sinitializecall landed first, not necessarily the party who paid to deploy, became the permanent admin. Soroban deployment and initialization are separate transactions, so a third party watching the mempool could front-run a legitimate deployer'sinitializecall with their own.adminis now pinned by a__constructorfunction, which Soroban invokes atomically as part of the same operation that creates the contract instance.initializeno longer accepts anadminparameter at all; it authenticates against whatever__constructoralready fixed. This mirrors the already-merged fix for the same issue incontracts/tholos-v2(#154, PR #183), applying the same pattern to v1 for consistency, as the original issue requested.Closes #158
Also updated for consistency with the new deploy shape:
docs/src/CONTRACT.md: new__constructorentry,initialize's signature and CLI example updated,NotInitializedtable row corrected (admin-gated calls likeupdate_resolversno longer return it, since admin is fixed at deploy, not atinitialize)docs/src/CONTRACT_V2.md: removed a now-stale "unlike v1" comparison ininitialize's doc, since v1 uses the same__constructorpattern nowdocs/src/DEPLOYMENT.md: deploy example updated to passadminas a constructor argument; also fixed a pre-existing, unrelated staleness in the "Rotating the admin key" section, which still documented a one-stepset_admincall instead of the actual two-steppropose_admin/accept_adminflow already in the contractscripts/testnet-smoke.sh,scripts/testnet-load.sh: deploy commands updated to passadminas a constructor argumentpackages/tholos-sdk: bindings regenerated from the updated contract interfacecontracts/asserter-consumer,contracts/demo-consumer: test fixtures updated to register with the constructor argument and call the newinitializesignatureThree existing tests asserted
NotInitializedfrom calls (set_paused,update_resolvers,set_bond_amount) that only ever checked whetherAdminexists in storage. Since__constructornow setsAdminatomically with deployment, that state no longer exists for any live contract, so those calls succeed instead. Rewrote the three tests to assert the new, correct behavior, and two more that usedset_pausedas an indirect "nothing was persisted" proof to instead retryinitializedirectly. Added a new regression test,test_initialize_rejects_caller_other_than_constructor_admin, mirroring v2's equivalent.Test plan
cargo fmt --check,cargo clippy --workspace --all-targets -- -D warnings, andcargo test --workspacepass locally (all crates green, 89 tholos tests including the new regression test, 6 each for asserter-consumer and demo-consumer)CONTRACT.mdupdated for the public interface changescripts/testnet-smoke.shnot run against testnet for this change; the constructor-argument deploy shape mirrors v2's already-verified patternNote on assignment
This issue was assigned to @odiliflash-ops, who did not respond after two check-ins over several days, including an explicit 24-hour deadline. Unassigning and fixing directly here with the maintainer's go-ahead.