Skip to content

fix(tholos): pin admin in __constructor to close initialize front-running (#158) - #197

Closed
ZacLou wants to merge 1 commit into
drydocs:mainfrom
ZacLou:fix/158-constructor-admin-2
Closed

ZacLou wants to merge 1 commit into
drydocs:mainfrom
ZacLou:fix/158-constructor-admin-2

Conversation

@ZacLou

@ZacLou ZacLou commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Closes #158.

initialize in contracts/tholos took admin as 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 __constructor that pins admin atomically with contract creation (the same pattern already landed for v2 in #183 / #154). initialize no longer accepts an admin parameter; it reads the admin fixed at deploy time and authenticates against that.

Changes

  • New __constructor(env, admin): sets DataKey::Admin and bumps TTL, invoked automatically by Soroban as part of CreateContractV2.
  • Updated initialize: removes admin parameter, reads admin from storage (set by constructor), checks DataKey::Token for AlreadyInitialized instead of DataKey::Admin.
  • Tests: all existing tests updated to pass admin to env.register(Tholos, (admin,)) and drop &admin from initialize/try_initialize calls.
  • New test: test_initialize_rejects_caller_other_than_constructor_admin mocks auth for an attacker distinct from the real constructor-time admin and confirms initialize panics (auth rejection).

…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.
@collinsezedike

Copy link
Copy Markdown
Collaborator

@ZacLou Closing. #158 is assigned to odiliflash-ops, not you.

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.

[Bug] initialize is front-runnable in tholos v1

2 participants