Skip to content

Commit

Permalink
feat: addressed ottersec audit comments (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
Foivos authored Oct 24, 2024
1 parent c92873e commit 579eda4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion move/its/sources/types/coin_management.move
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public(package) fun give_coin<T>(
amount = amount + self.dust;
self.dust = amount % self.scaling;
let sui_amount = (amount / self.scaling as u64);
self.flow_limit.add_flow_out(sui_amount, clock);
self.flow_limit.add_flow_in(sui_amount, clock);
if (has_capability(self)) {
self.mint(sui_amount, ctx)
} else {
Expand Down
12 changes: 6 additions & 6 deletions move/its/sources/types/flow_limit.move
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const EFlowLimitExceeded: u64 = 0;

public struct FlowLimit has store, copy, drop {
flow_limit: u64,
flow_in: u64,
flow_out: u64,
flow_in: u128,
flow_out: u128,
current_epoch: u64,
}

Expand Down Expand Up @@ -40,10 +40,10 @@ public(package) fun add_flow_in(

update_epoch(self, clock);
assert!(
self.flow_in + amount < self.flow_limit + self.flow_out,
self.flow_in + (amount as u128) < (self.flow_limit as u128) + self.flow_out,
EFlowLimitExceeded,
);
self.flow_in = self.flow_in + amount;
self.flow_in = self.flow_in + (amount as u128);
}

public(package) fun add_flow_out(
Expand All @@ -55,10 +55,10 @@ public(package) fun add_flow_out(

update_epoch(self, clock);
assert!(
self.flow_out + amount < self.flow_limit + self.flow_in,
self.flow_out + (amount as u128) < (self.flow_limit as u128) + self.flow_in,
EFlowLimitExceeded,
);
self.flow_out = self.flow_out + amount;
self.flow_out = self.flow_out + (amount as u128);
}

public(package) fun set_flow_limit(self: &mut FlowLimit, flow_limit: u64) {
Expand Down
3 changes: 3 additions & 0 deletions move/its/sources/types/token_id.move
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public fun from_info<T>(
name: &String,
symbol: &ascii::String,
decimals: &u8,
remote_decimals: &u8,
has_metadata: &bool,
has_treasury: &bool,
): TokenId {
Expand All @@ -45,6 +46,7 @@ public fun from_info<T>(
vec.append(bcs::to_bytes(name));
vec.append(bcs::to_bytes(symbol));
vec.append(bcs::to_bytes(decimals));
vec.append(bcs::to_bytes(remote_decimals));
vec.append(bcs::to_bytes(has_metadata));
vec.append(bcs::to_bytes(has_treasury));
TokenId { id: address::from_bytes(keccak256(&vec)) }
Expand All @@ -58,6 +60,7 @@ public(package) fun from_coin_data<T>(
&coin_info.name(),
&coin_info.symbol(),
&coin_info.decimals(),
&coin_info.remote_decimals(),
&option::is_some(coin_info.metadata()),
&coin_management.has_capability(),
)
Expand Down
4 changes: 2 additions & 2 deletions test/testdata/interface_its_flow_limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
},
{
"name": "flow_in",
"type": "u64"
"type": "u128"
},
{
"name": "flow_out",
"type": "u64"
"type": "u128"
},
{
"name": "current_epoch",
Expand Down
1 change: 1 addition & 0 deletions test/testdata/interface_its_token_id.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"name#0#0": "&String",
"symbol#0#0": "&String",
"decimals#0#0": "&u8",
"remote_decimals#0#0": "&u8",
"has_metadata#0#0": "&bool",
"has_treasury#0#0": "&bool"
},
Expand Down

0 comments on commit 579eda4

Please sign in to comment.