Skip to content

Commit

Permalink
fix the vector borrow when index=size
Browse files Browse the repository at this point in the history
  • Loading branch information
sm86 committed Dec 8, 2023
1 parent 06ae8cb commit 6f32a59
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions framework/libra-framework/sources/ol_sources/tower_state.move
Original file line number Diff line number Diff line change
Expand Up @@ -585,14 +585,20 @@ module ol_framework::tower_state {
// pick the next miner
// make sure we get an n smaller than list of miners

let k = 0; // k keeps track of this loop, abort if loops too much
while (this_miner_index > count_miners) {
if (k > 1000) return 0;
this_miner_index = this_miner_index / count_miners;
k = k + 1;
};
// Current case: if miner_index = count_miners could lead to overflow

// let k = 0; // k keeps track of this loop, abort if loops too much
// while (this_miner_index >= count_miners) {
// if (k > 1000) return 0;
// this_miner_index = this_miner_index / count_miners;
// k = k + 1;
// };

// double check length of vector
if (this_miner_index >= count_miners ) return 0;
// if (this_miner_index >= count_miners ) return 0;

// We could use modulo arthemetic on integers
this_miner_index = this_miner_index % count_miners;

let miner_addr = vector::borrow<address>(&all_miners, this_miner_index);
let vec = if (exists<TowerProofHistory>(*miner_addr)) {
Expand Down

0 comments on commit 6f32a59

Please sign in to comment.