stellar / rs-soroban-env

Rust environment for Soroban contracts.
Apache License 2.0
60 stars 40 forks source link

Fix auth entry charge #1297

Closed jayz22 closed 7 months ago

jayz22 commented 9 months ago

https://github.com/stellar/rs-soroban-env/blob/9c5394083725bacf32a56107d7fa2adf643dc7b5/soroban-env-host/src/auth.rs#L855-L856

- Vec::<Val>::charge_bulk_init_cpy(auth_entries.len() as u64, host)?;
+ Vec::<InvokerContractAuthorizationTracker>::charge_bulk_init_cpy(auth_entries.len() as u64, host)?;
jayz22 commented 7 months ago

Using this to track a couple of other issue surfaced during the same review:

On line 1018 in auth.rs in function snapshot you seem to allocate a vector to store authorization snapshots but then charge for the allocation afterwards. Can you confirm that the charge should happen before the allocation?

and

On lines 694-700 in auth.rs in the function new_enforcing (for AuthorizationManager) I noticed that you allocate a vector of AccountAuthorizationTrackers of size num_entries. However, the vector you allocate is of type Vec<RefCell> so the amount of memory allocated is actually num_entries(sizeof(RefCell)). The difference in memory allocated is n(sizeof(RefCell) - sizeof(AccountAuthorizationTracker)). Why not try and account for the difference when charging?

jayz22 commented 7 months ago

resolved by https://github.com/stellar/rs-soroban-env/pull/1340