Skip to content

Commit d3b97d3

Browse files
committed
safe math
1 parent 7b68b1f commit d3b97d3

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

runtime/src/precompiles/neuron.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ impl NeuronPrecompile {
145145
handle.context().caller,
146146
);
147147

148-
// Dispatch the register_network call
149148
try_dispatch_runtime_call(handle, call, RawOrigin::Signed(account_id))
150149
}
151150

@@ -167,7 +166,6 @@ impl NeuronPrecompile {
167166
handle.context().caller,
168167
);
169168

170-
// Dispatch the register_network call
171169
try_dispatch_runtime_call(handle, call, RawOrigin::Signed(account_id))
172170
}
173171

@@ -191,7 +189,6 @@ impl NeuronPrecompile {
191189
handle.context().caller,
192190
);
193191

194-
// Dispatch the register_network call
195192
try_dispatch_runtime_call(handle, call, RawOrigin::Signed(account_id))
196193
}
197194

@@ -504,9 +501,8 @@ impl NeuronPrecompile {
504501
exit_status: ExitError::InvalidRange,
505502
});
506503
}
507-
let mut netuid_vec = [0u8; 2];
508-
netuid_vec.copy_from_slice(get_slice(data, 30, 32)?);
509-
let netuid = u16::from_be_bytes(netuid_vec);
504+
505+
let netuid = parse_netuid(data, 30)?;
510506

511507
let mut version_vec = [0u8; 4];
512508
version_vec.copy_from_slice(get_slice(data, 60, 64)?);
@@ -584,7 +580,12 @@ impl NeuronPrecompile {
584580
len_vec.copy_from_slice(get_slice(data, len_position + 30, len_position + 32)?);
585581
let vec_len = u16::from_be_bytes(len_vec) as usize;
586582

587-
let vec_result = get_slice(data, len_position + 32, len_position + 32 + vec_len)?.to_vec();
583+
let vec_result = get_slice(
584+
data,
585+
len_position + 32,
586+
len_position.saturating_add(32).saturating_add(vec_len),
587+
)?
588+
.to_vec();
588589

589590
Ok((
590591
netuid,
@@ -607,9 +608,8 @@ impl NeuronPrecompile {
607608
exit_status: ExitError::InvalidRange,
608609
});
609610
}
610-
let mut netuid_vec = [0u8; 2];
611-
netuid_vec.copy_from_slice(get_slice(data, 30, 32)?);
612-
let netuid = u16::from_be_bytes(netuid_vec);
611+
612+
let netuid = parse_netuid(data, 30)?;
613613

614614
let mut version_vec = [0u8; 4];
615615
version_vec.copy_from_slice(get_slice(data, 60, 64)?);

0 commit comments

Comments
 (0)