You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
load* methods check the discriminator of the account each time they're called. This results in unnecessary performance penalty, especially when used in account constraints.
Given this, the discriminator is already checked when it should be (using try_from), and if it shouldn't get checked (like when using init), it's not checked.
This also means load_init method is fully redundant.
Solution
If the above assumptions are correct, it should be safe to remove them:
Remove the discriminator checks from the load and load_mut methods
Remove the load_init method completely
But before doing so, we must be certain that those methods are indeed redundant, and this change would not affect the security of programs in any way.
The text was updated successfully, but these errors were encountered:
Problem
load*
methods check the discriminator of the account each time they're called. This results in unnecessary performance penalty, especially when used in account constraints.The new custom discriminator support also added a bit of additional overhead when comparing the discriminators.
It looks like these checks are all redundant because the only way to create an
AccountLoader
instance is to useAccountLoader::try_from
orAccountLoader::try_from_unchecked
.try_from
:Used when the account already exists
Checks both the owner and the discriminator:
anchor/lang/src/accounts/account_loader.rs
Lines 121 to 135 in 48c732d
try_from_unchecked
:Used when the account doesn't exist or the
zero
constraint is used constraintsChecks only the owner:
anchor/lang/src/accounts/account_loader.rs
Lines 146 to 149 in 48c732d
Given this, the discriminator is already checked when it should be (using
try_from
), and if it shouldn't get checked (like when usinginit
), it's not checked.This also means
load_init
method is fully redundant.Solution
If the above assumptions are correct, it should be safe to remove them:
load
andload_mut
methodsload_init
method completelyBut before doing so, we must be certain that those methods are indeed redundant, and this change would not affect the security of programs in any way.
The text was updated successfully, but these errors were encountered: