Skip to content

Commit ef3af14

Browse files
committed
commit Cargo.lock
1 parent 3fd2c83 commit ef3af14

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

runtime/src/precompiles/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,14 @@ fn dispatch(
232232
}),
233233
}
234234
}
235+
236+
pub fn get_single_u8(data: &[u8], index: usize) -> Result<u8, PrecompileFailure> {
237+
if let Some(result) = data.get(index) {
238+
Ok(*result)
239+
} else {
240+
log::error!("fail to get data from data, {:?}, at {}", &data, index);
241+
Err(PrecompileFailure::Error {
242+
exit_status: ExitError::InvalidRange,
243+
})
244+
}
245+
}

runtime/src/precompiles/neuron.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use pallet_evm::{ExitError, PrecompileFailure, PrecompileHandle, PrecompileResult};
22

3-
use crate::precompiles::{dispatch, get_method_id, get_slice};
3+
use crate::precompiles::{dispatch, get_method_id, get_single_u8, get_slice};
44
use sp_std::vec;
55

66
use crate::{Runtime, RuntimeCall};
@@ -144,10 +144,10 @@ impl NeuronPrecompile {
144144
port_vec.copy_from_slice(get_slice(data, 126, 128)?);
145145
let port = u16::from_be_bytes(port_vec);
146146

147-
let ip_type = data[159];
148-
let protocol = data[191];
149-
let placeholder1 = data[223];
150-
let placeholder2 = data[255];
147+
let ip_type = get_single_u8(data, 159)?;
148+
let protocol = get_single_u8(data, 191)?;
149+
let placeholder1 = get_single_u8(data, 223)?;
150+
let placeholder2 = get_single_u8(data, 255)?;
151151
Ok((
152152
netuid,
153153
version,
@@ -184,10 +184,10 @@ impl NeuronPrecompile {
184184
port_vec.copy_from_slice(get_slice(data, 126, 128)?);
185185
let port = u16::from_be_bytes(port_vec);
186186

187-
let ip_type = data[159];
188-
let protocol = data[191];
189-
let placeholder1 = data[223];
190-
let placeholder2 = data[255];
187+
let ip_type = get_single_u8(data, 159)?;
188+
let protocol = get_single_u8(data, 191)?;
189+
let placeholder1 = get_single_u8(data, 223)?;
190+
let placeholder2 = get_single_u8(data, 255)?;
191191

192192
let mut len_position_vec = [0u8; 2];
193193
len_position_vec.copy_from_slice(get_slice(data, 286, 288)?);
@@ -236,7 +236,7 @@ impl NeuronPrecompile {
236236
port_vec.copy_from_slice(get_slice(data, 126, 128)?);
237237
let port = u16::from_be_bytes(port_vec);
238238

239-
let ip_type = data[159];
239+
let ip_type = get_single_u8(data, 159)?;
240240
Ok((netuid, version, ip, port, ip_type))
241241
}
242242
}

0 commit comments

Comments
 (0)