-
Notifications
You must be signed in to change notification settings - Fork 9
feat: new program interaction policy creation format #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Edit: Comments discussed, no additional change to perform Issue: Unbounded Constraint ComplexityI identified a potential improvement that applies to both the legacy and new indexed formats. Currently, there are no limits on:
Example of potentially expensive policy: InstructionConstraint {
account_constraints: vec![
AccountConstraint {
account_constraint: Pubkey(vec![pubkey1, pubkey2, ..., pubkey50])
},
// ... repeated 20 times
]
}I know this is actually bound by tx size so a policy like the one above it's not possible, but still during constraint evaluation, each pubkey list is checked via linear scan ( We could decide to add a per-constraint complexity limits during policy creation: // Constants at module level
const MAX_ACCOUNT_CONSTRAINTS_PER_INSTRUCTION: usize = 20;
const MAX_PUBKEYS_PER_ACCOUNT_CONSTRAINT: usize = 10;
impl PolicyPayloadConversionTrait for ProgramInteractionPolicyCreationPayload {
fn to_policy_state(self) -> Result<ProgramInteractionPolicy> {
// ... existing validations ...
// Validate constraint complexity
for ic in &self.instructions_constraints {
require!(
ic.account_constraints.len() <= MAX_ACCOUNT_CONSTRAINTS_PER_INSTRUCTION,
SmartAccountError::ProgramInteractionTooManyAccountConstraints
);
for ac in &ic.account_constraints {
if let AccountConstraintTypeIndexed::Pubkey(indices) = &ac.account_constraint {
require!(
indices.len() <= MAX_PUBKEYS_PER_ACCOUNT_CONSTRAINT,
SmartAccountError::ProgramInteractionTooManyPubkeysInSingleConstraint
);
}
}
}
// ... rest of expansion logic ...
}
}Issue: Duplicate Pubkeys in ConstraintsThe current implementation (in both legacy and indexed formats) allows duplicate pubkeys within a single constraint:
Both expand to constraints with duplicate pubkeys in the final policy state, which wastes space and compute.~~ |
|
To make the impl<L, T> Deref for SmallVec<L, T> {
type Target = Vec<T>;
fn deref(&self) -> &Self::Target {
&self.0
}
}This shouldn't break any existing code |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|
SmallVec Serialization FixThe ProblemSolita generates This caused serialization mismatches between the SDK and on-chain program. Previously, we worked around this by manually defining these types in This would have required a big lift for this PR since all nested types uses The SolutionAdded It replaces Usage: Runs automatically via What Changed
|
Implement dual-format support for creating program interaction policies:
Changes:
AccountConstraintIndexed, AccountConstraintTypeIndexed)
future builtin programs)
ProgramInteractionTooManyUniquePubkeys errors
ProgramInteraction variants
Benefits: