Skip to content

[New Permission 1/5] smartcontract: scaffold Permission account state and instruction variants#3204

Open
juan-malbeclabs wants to merge 1 commit intomainfrom
jo/permission-scaffolding
Open

[New Permission 1/5] smartcontract: scaffold Permission account state and instruction variants#3204
juan-malbeclabs wants to merge 1 commit intomainfrom
jo/permission-scaffolding

Conversation

@juan-malbeclabs
Copy link
Contributor

Summary of Changes

  • Introduces the Permission account type: Borsh-serialized state with owner, status (None/Activated/Suspended/Deleting), user_payer, and a u128 permissions bitmask
  • Defines permission_flags constants covering 15 roles across four tiers (governance, infra management, operational, technical/automated)
  • Registers 5 new instruction variants (97–101): CreatePermission, UpdatePermission, SuspendPermission, ResumePermission, DeletePermission — dispatched through the entrypoint but returning InvalidInstructionData (stub processors to be filled in the next PR)
  • Adds a RequirePermissionAccounts feature flag (bit 1) that, when set, disables the legacy GlobalState allowlist/authority fallback in favor of Permission-based authorization
  • Adds SEED_PERMISSION PDA seed and get_permission_pda() helper

Diff Breakdown

Category Files Lines (+/-) Net
Core logic 7 +209 / -7 +202
Scaffolding 9 +202 / -0 +202

Roughly equal split between new state definition/supporting infrastructure and boilerplate processor/dispatch scaffolding.

Key files (click to expand)
  • smartcontract/programs/doublezero-serviceability/src/state/permission.rs — new Permission struct, PermissionStatus enum, permission_flags bitmask constants, TryFrom<&[u8]> / TryFrom<&AccountInfo> deserialization, Validate impl
  • smartcontract/programs/doublezero-serviceability/src/instructions.rs — five new DoubleZeroInstruction variants (97–101) with args structs, dispatch matching, name/debug helpers, and roundtrip tests
  • smartcontract/programs/doublezero-serviceability/src/state/accountdata.rsAccountData::Permission variant, get_permission() accessor, TryFrom<&[u8]> arm
  • smartcontract/programs/doublezero-serviceability/src/entrypoint.rs — routes the five new instruction variants to stub processors
  • smartcontract/programs/doublezero-serviceability/src/state/feature_flags.rs — adds RequirePermissionAccounts flag (bit 1) with string serialization
  • smartcontract/programs/doublezero-serviceability/src/pda.rsget_permission_pda() using SEED_PERMISSION + user_payer
  • smartcontract/programs/doublezero-serviceability/src/state/accounttype.rsAccountType::Permission = 15

Testing Verification

  • Instruction roundtrip tests cover all five new variants: serialization → deserialization → name comparison
  • make rust-test passes with the new instruction variants in place

Copy link
Contributor

@elitegreg elitegreg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one comment you should addess

None = 0,
Activated = 1,
Suspended = 2,
Deleting = 3,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need a deleting status. That's state logic was only really needed for transitioning through the activator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants