-
Notifications
You must be signed in to change notification settings - Fork 7
Description
The task is to remove the use of a global index as a seed in the derivation of Program Derived Addresses (PDAs) for accounts managed by the Serviceability smart contract.
Currently, the Serviceability program uses a sequential global index (e.g. an incrementing counter) as part of the seeds when deriving new PDA addresses for accounts such as Devices, Users, or Links. This approach creates a concurrency risk, because if two users attempt to create the same type of account at the same time, they might both derive the same PDA using the current value of the global index, causing a collision or failure during transaction execution.
The objective of this task is to refactor the PDA derivation logic to eliminate the dependency on this mutable global index. Instead, each PDA must be derived using a randomly generated index that ensures uniqueness while preserving deterministic behavior from the client side. The random index can be generated by the client (CLI) and passed as part of the instruction data when creating the account.
This change will improve the safety and scalability of the system, especially in parallel or high-volume onboarding scenarios. It also makes the logic easier to reason about, as there is no dependency on reading and updating a centralized counter within the contract state.
The final implementation must ensure backward compatibility (if needed), and should be verified with updated tests to confirm that new accounts are derived correctly, without collisions, and that old accounts still function as expected.