Description
The init function can currently be called multiple times, allowing an attacker who front-runs the deployer to hijack the contract by setting their own admin. A one-shot initialiser guard must ensure init can only execute once across the contract's lifetime.
Technical Context
Add an Initialised boolean to storage::instance in contracts/split/src/lib.rs. At the top of init, call env.storage().instance().get::<_, bool>(&DataKey::Initialised) and panic with AlreadyInitialised (new variant in types.rs) if it is set. Set the flag atomically at the end of init.
Acceptance Criteria
Description
The
initfunction can currently be called multiple times, allowing an attacker who front-runs the deployer to hijack the contract by setting their own admin. A one-shot initialiser guard must ensureinitcan only execute once across the contract's lifetime.Technical Context
Add an
Initialisedboolean tostorage::instanceincontracts/split/src/lib.rs. At the top ofinit, callenv.storage().instance().get::<_, bool>(&DataKey::Initialised)and panic withAlreadyInitialised(new variant intypes.rs) if it is set. Set the flag atomically at the end ofinit.Acceptance Criteria
initreturnsAlreadyInitialisederrorinitsetupstorage::instance