Skip to content

Commit ed62a5d

Browse files
sh-chabeer-1
andauthored
Fix/audit (#188)
* get slice data pointer from unsafe.sliceData * follow aptos prod config * use deserialize_with_config instead of deserialize * disable resource access control * remove unused poiter --------- Co-authored-by: beer-1 <[email protected]>
1 parent 155dd4c commit ed62a5d

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

api/memory.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ package api
55
*/
66
import "C"
77

8-
import "unsafe"
8+
import (
9+
"unsafe"
10+
)
911

1012
// makeView creates a view into the given byte slice what allows Rust code to read it.
1113
// The byte slice is managed by Go and will be garbage collected. Use runtime.KeepAlive
@@ -15,16 +17,9 @@ func makeView(s []byte) C.ByteSliceView {
1517
return C.ByteSliceView{is_nil: true, ptr: cu8_ptr(nil), len: cusize(0)}
1618
}
1719

18-
// In Go, accessing the 0-th element of an empty array triggers a panic. That is why in the case
19-
// of an empty `[]byte` we can't get the internal heap pointer to the underlying array as we do
20-
// below with `&data[0]`. https://play.golang.org/p/xvDY3g9OqUk
21-
if len(s) == 0 {
22-
return C.ByteSliceView{is_nil: false, ptr: cu8_ptr(nil), len: cusize(0)}
23-
}
24-
2520
return C.ByteSliceView{
2621
is_nil: false,
27-
ptr: cu8_ptr(unsafe.Pointer(&s[0])),
22+
ptr: cu8_ptr(unsafe.SliceData(s)),
2823
len: cusize(len(s)),
2924
}
3025
}

crates/storage/src/state_view_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<'s, S: StateView> CompiledModuleView for StateViewImpl<'s, S> {
146146
let bytes = self.get_module(id)?;
147147
let module = match bytes {
148148
Some(bytes) => {
149-
CompiledModule::deserialize(&bytes).map_err(|e| anyhow::anyhow!(e.to_string()))?
149+
CompiledModule::deserialize_with_config(&bytes, &self.deserialize_config).map_err(|e| anyhow::anyhow!(e.to_string()))?
150150
}
151151
None => return Ok(None),
152152
};

crates/vm/src/initia_vm.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,13 @@ impl InitiaVM {
8787
pub fn new(initia_vm_config: InitiaVMConfig) -> Self {
8888
let gas_params = NativeGasParameters::initial();
8989
let misc_params = MiscGasParameters::initial();
90+
9091
let vm_config = VMConfig {
9192
verifier_config: verifier_config(),
9293
use_loader_v2: true,
94+
type_max_cost: 5000,
95+
type_base_cost: 100,
96+
type_byte_cost: 1,
9397
..Default::default()
9498
};
9599
let runtime_environment = Arc::new(RuntimeEnvironment::new_with_config(

crates/vm/src/verifier/config.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ pub fn verifier_config() -> VerifierConfig {
1010
max_value_stack_size: 1024,
1111
max_type_nodes: Some(256),
1212
max_push_size: Some(10000),
13-
max_struct_definitions: Some(200),
14-
max_fields_in_struct: Some(30),
15-
max_struct_variants: Some(90),
16-
max_function_definitions: Some(1000),
13+
max_struct_definitions: None,
14+
max_fields_in_struct: None,
15+
max_struct_variants: None,
16+
max_function_definitions: None,
1717

1818
// Do not use back edge constraints as they are superseded by metering
1919
max_back_edges_per_function: None,
2020
max_back_edges_per_module: None,
2121

2222
// Same as the default.
23-
max_per_fun_meter_units: Some(1000 * 8000),
24-
max_per_mod_meter_units: Some(1000 * 8000),
23+
max_per_fun_meter_units: Some(1000 * 80000),
24+
max_per_mod_meter_units: Some(1000 * 80000),
2525

2626
use_signature_checker_v2: true,
2727

2828
sig_checker_v2_fix_script_ty_param_count: true,
2929

3030
enable_enum_types: true,
31-
enable_resource_access_control: true,
31+
enable_resource_access_control: false,
3232
}
3333
}

0 commit comments

Comments
 (0)