-
Notifications
You must be signed in to change notification settings - Fork 653
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
feat: Improve add fn key estimation #6794
Conversation
Test short and long method names in the gas cost estimation for adding a function call access. Also subtract the receipt creation cost.
Step one for #6716. I need to run also on gcloud, but the icount metric so far suggests that we might not have to change anything at all. Will update on the linked issue once I have all data points. |
let base_cost = action_add_function_access_key_base(ctx) + action_sir_receipt_creation(ctx); | ||
|
||
// Set up estimation with varying method length and total bytes. | ||
let mut estimate = |method_len: usize, total_len: usize| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a suggestion, but I generally try to avoid longer lambdas -- they make the code harder to read, because it's not clear what exactly are they closing over. So, I have a preference for declaring a local function and passing params explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otoh, I'd just write this as a loop, which has exactly the same problem :)
let cases = [(max_method_len, max_bytes), ]
let mut estimations = Vec::with_capacity(cases.len());
for (m_len, n_methods) {
....
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same thought. Almost made it a loop, almost put it in a separate function. So I definitely see where you are coming form.
But IMO in this specific case it is just more readable this way. (For programmers that are not spooked by closures, that is.)
// Nothing prevents a key to list the same method many times. Performance should not be affected. | ||
let method_name = "x".repeat(method_len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd maybe still made names different, just in case something does change in the future impl.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, if we make names different, names need to be longer than one character.
But an attacker is not restricted to that today, so it is totally feasible to submit 1000x "x". And we estimate that case as slightly more gas heavy than fewer methods with longer names.
Test short and long method names in the gas cost estimation for adding a
function call access. Also subtract the receipt creation cost.