code-423n4 / 2021-08-gravitybridge-findings

1 stars 0 forks source link

Passing by ownership instead of borrowing #16

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

nascent

Vulnerability details

[I-00] Passing by ownership instead of borrowing

Severity: Low

Many functions take parameters by value instead of by reference, forcing the consumer to .clone() params. Borrowing wherever possible (and introducing lifetime parameters where necessary) avoids unnecessary copying of data. This can lead to substantial performance improvements.

Recommendation

Wherever possible, borrow instead of passing ownership. This reduces the overall memory footprint and can drastically improve performance (depending upon the size of the data being duplicated).

fn foo(b: Bar) {
    serialize(&b);
}
fn foo2(b: &Bar) {
    serialize(b);
}
let my_bar = Bar::default();
foo(my_bar.clone());
foo2(&my_bar);
jkilpatr commented 2 years ago

This is valid, right now the performance of the orchestrator is significantly faster than needed so it's not likely there will be a significant time investment made here.

loudoguno commented 2 years ago

reopening as per judges assessment as "primary issue" on findings sheet