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
It was observed that add_attribute, update_attribute, read_attribute, and remove_attributeuse a static weight while some arguments provided are vectors. Incorrect weight calculation might lead to situations when a malicious actor can spam a network (this can cause performance degradation) by paying low fees while sending a tx, which causes longer calculation time (large vector).
Then, in benchmarking for add_attribute, you should generate an attribute name with a range between 1 -64 and the value between 1 - worst-case range you expect
Description
It was observed that
add_attribute
,update_attribute
,read_attribute
, andremove_attribute
use a static weight while some arguments provided are vectors. Incorrect weight calculation might lead to situations when a malicious actor can spam a network (this can cause performance degradation) by paying low fees while sending a tx, which causes longer calculation time (large vector).In addition to this, in benchmarking.rs worst case scenarios are not used. Hence, it won't reflect the performance under worst-case situations.
Recommendation
You should take into account the number of elements in the vector when calculating weight.
Example:
#[pallet::weight(T::WeightInfo::remove_attribute(name.len() as u32))]
In benchmarking.rs, follow your worst-case constraints, and you should update it to take into account a dynamic value.
For instance, in
add_attribute
, you have:Then, in benchmarking for
add_attribute
, you should generate an attribute name with a range between 1 -64 and the value between 1 - worst-case range you expectExample from another project: https://github.com/NodleCode/chain/blob/master/pallets/sponsorship/src/benchmarking.rs#L136C21-L136C27
The text was updated successfully, but these errors were encountered: