mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-15 17:21:09 +00:00
@@ -63,17 +63,17 @@ where
|
||||
let non_overflow_block = context.append_basic_block("shift_left_non_overflow");
|
||||
let join_block = context.append_basic_block("shift_left_join");
|
||||
|
||||
let result_pointer = context.build_alloca(context.field_type(), "shift_left_result_pointer");
|
||||
let result_pointer = context.build_alloca(context.word_type(), "shift_left_result_pointer");
|
||||
let condition_is_overflow = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::UGT,
|
||||
shift,
|
||||
context.field_const((revive_common::BIT_LENGTH_FIELD - 1) as u64),
|
||||
context.word_const((revive_common::BIT_LENGTH_WORD - 1) as u64),
|
||||
"shift_left_is_overflow",
|
||||
)?;
|
||||
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
|
||||
|
||||
context.set_basic_block(overflow_block);
|
||||
context.build_store(result_pointer, context.field_const(0))?;
|
||||
context.build_store(result_pointer, context.word_const(0))?;
|
||||
context.build_unconditional_branch(join_block);
|
||||
|
||||
context.set_basic_block(non_overflow_block);
|
||||
@@ -101,17 +101,17 @@ where
|
||||
let non_overflow_block = context.append_basic_block("shift_right_non_overflow");
|
||||
let join_block = context.append_basic_block("shift_right_join");
|
||||
|
||||
let result_pointer = context.build_alloca(context.field_type(), "shift_right_result_pointer");
|
||||
let result_pointer = context.build_alloca(context.word_type(), "shift_right_result_pointer");
|
||||
let condition_is_overflow = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::UGT,
|
||||
shift,
|
||||
context.field_const((revive_common::BIT_LENGTH_FIELD - 1) as u64),
|
||||
context.word_const((revive_common::BIT_LENGTH_WORD - 1) as u64),
|
||||
"shift_right_is_overflow",
|
||||
)?;
|
||||
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
|
||||
|
||||
context.set_basic_block(overflow_block);
|
||||
context.build_store(result_pointer, context.field_const(0))?;
|
||||
context.build_store(result_pointer, context.word_const(0))?;
|
||||
context.build_unconditional_branch(join_block);
|
||||
|
||||
context.set_basic_block(non_overflow_block);
|
||||
@@ -145,14 +145,12 @@ where
|
||||
let non_overflow_block = context.append_basic_block("shift_right_arithmetic_non_overflow");
|
||||
let join_block = context.append_basic_block("shift_right_arithmetic_join");
|
||||
|
||||
let result_pointer = context.build_alloca(
|
||||
context.field_type(),
|
||||
"shift_right_arithmetic_result_pointer",
|
||||
);
|
||||
let result_pointer =
|
||||
context.build_alloca(context.word_type(), "shift_right_arithmetic_result_pointer");
|
||||
let condition_is_overflow = context.builder().build_int_compare(
|
||||
inkwell::IntPredicate::UGT,
|
||||
shift,
|
||||
context.field_const((revive_common::BIT_LENGTH_FIELD - 1) as u64),
|
||||
context.word_const((revive_common::BIT_LENGTH_WORD - 1) as u64),
|
||||
"shift_right_arithmetic_is_overflow",
|
||||
)?;
|
||||
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
|
||||
@@ -160,7 +158,7 @@ where
|
||||
context.set_basic_block(overflow_block);
|
||||
let sign_bit = context.builder().build_right_shift(
|
||||
value,
|
||||
context.field_const((revive_common::BIT_LENGTH_FIELD - 1) as u64),
|
||||
context.word_const((revive_common::BIT_LENGTH_WORD - 1) as u64),
|
||||
false,
|
||||
"shift_right_arithmetic_sign_bit",
|
||||
)?;
|
||||
@@ -176,11 +174,11 @@ where
|
||||
)?;
|
||||
|
||||
context.set_basic_block(overflow_positive_block);
|
||||
context.build_store(result_pointer, context.field_const(0))?;
|
||||
context.build_store(result_pointer, context.word_const(0))?;
|
||||
context.build_unconditional_branch(join_block);
|
||||
|
||||
context.set_basic_block(overflow_negative_block);
|
||||
context.build_store(result_pointer, context.field_type().const_all_ones())?;
|
||||
context.build_store(result_pointer, context.word_type().const_all_ones())?;
|
||||
context.build_unconditional_branch(join_block);
|
||||
|
||||
context.set_basic_block(non_overflow_block);
|
||||
|
||||
@@ -21,7 +21,7 @@ where
|
||||
let offset = context.build_gep(
|
||||
Pointer::new(context.byte_type(), AddressSpace::Stack, calldata_pointer),
|
||||
&[offset],
|
||||
context.field_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
"calldata_pointer_with_offset",
|
||||
);
|
||||
context
|
||||
|
||||
@@ -24,7 +24,7 @@ where
|
||||
)?;
|
||||
let result = context.builder().build_int_z_extend_or_bit_cast(
|
||||
result,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
"comparison_result_extended",
|
||||
)?;
|
||||
Ok(result.as_basic_value_enum())
|
||||
|
||||
@@ -129,6 +129,6 @@ where
|
||||
)?;
|
||||
Ok(context
|
||||
.builder()
|
||||
.build_int_z_extend(heap_size, context.field_type(), "heap_size_extended")?
|
||||
.build_int_z_extend(heap_size, context.word_type(), "heap_size_extended")?
|
||||
.as_basic_value_enum())
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ where
|
||||
{
|
||||
let signature_hash_string =
|
||||
crate::polkavm::utils::keccak256(crate::polkavm::DEPLOYER_SIGNATURE_CREATE.as_bytes());
|
||||
let signature_hash = context.field_const_str_hex(signature_hash_string.as_str());
|
||||
let signature_hash = context.word_const_str_hex(signature_hash_string.as_str());
|
||||
|
||||
let salt = context.field_const(0);
|
||||
let salt = context.word_const(0);
|
||||
|
||||
let function = Runtime::deployer_call(context);
|
||||
let result = context
|
||||
@@ -58,9 +58,9 @@ where
|
||||
{
|
||||
let signature_hash_string =
|
||||
crate::polkavm::utils::keccak256(crate::polkavm::DEPLOYER_SIGNATURE_CREATE2.as_bytes());
|
||||
let signature_hash = context.field_const_str_hex(signature_hash_string.as_str());
|
||||
let signature_hash = context.word_const_str_hex(signature_hash_string.as_str());
|
||||
|
||||
let salt = salt.unwrap_or_else(|| context.field_const(0));
|
||||
let salt = salt.unwrap_or_else(|| context.word_const(0));
|
||||
|
||||
let function = Runtime::deployer_call(context);
|
||||
let result = context
|
||||
@@ -107,7 +107,7 @@ where
|
||||
})?;
|
||||
if contract_path.as_str() == parent {
|
||||
return Ok(Argument::new_with_constant(
|
||||
context.field_const(0).as_basic_value_enum(),
|
||||
context.word_const(0).as_basic_value_enum(),
|
||||
num::BigUint::zero(),
|
||||
));
|
||||
} else if identifier.ends_with("_deployed") && code_type == CodeType::Runtime {
|
||||
@@ -116,7 +116,7 @@ where
|
||||
|
||||
let hash_string = context.compile_dependency(identifier.as_str())?;
|
||||
let hash_value = context
|
||||
.field_const_str_hex(hash_string.as_str())
|
||||
.word_const_str_hex(hash_string.as_str())
|
||||
.as_basic_value_enum();
|
||||
Ok(Argument::new_with_original(hash_value, hash_string))
|
||||
}
|
||||
@@ -155,7 +155,7 @@ where
|
||||
})?;
|
||||
if contract_path.as_str() == parent {
|
||||
return Ok(Argument::new_with_constant(
|
||||
context.field_const(0).as_basic_value_enum(),
|
||||
context.word_const(0).as_basic_value_enum(),
|
||||
num::BigUint::zero(),
|
||||
));
|
||||
} else if identifier.ends_with("_deployed") && code_type == CodeType::Runtime {
|
||||
@@ -164,7 +164,7 @@ where
|
||||
|
||||
let size_bigint = num::BigUint::from(crate::polkavm::DEPLOYER_CALL_HEADER_SIZE);
|
||||
let size_value = context
|
||||
.field_const(crate::polkavm::DEPLOYER_CALL_HEADER_SIZE as u64)
|
||||
.word_const(crate::polkavm::DEPLOYER_CALL_HEADER_SIZE as u64)
|
||||
.as_basic_value_enum();
|
||||
Ok(Argument::new_with_constant(size_value, size_bigint))
|
||||
}
|
||||
|
||||
@@ -16,25 +16,14 @@ where
|
||||
let offset_casted = context.safe_truncate_int_to_xlen(offset)?;
|
||||
let length_casted = context.safe_truncate_int_to_xlen(length)?;
|
||||
let input_pointer = context.build_heap_gep(offset_casted, length_casted)?;
|
||||
let input_pointer_casted = context.builder().build_ptr_to_int(
|
||||
input_pointer.value,
|
||||
context.xlen_type(),
|
||||
"input_pointer_casted",
|
||||
)?;
|
||||
|
||||
let output_pointer = context.build_alloca(context.field_type(), "output_pointer");
|
||||
let output_pointer_casted = context.builder().build_ptr_to_int(
|
||||
output_pointer.value,
|
||||
context.xlen_type(),
|
||||
"output_pointer_casted",
|
||||
)?;
|
||||
let output_pointer = context.build_alloca(context.word_type(), "output_pointer");
|
||||
|
||||
context.build_runtime_call(
|
||||
runtime_api::HASH_KECCAK_256,
|
||||
&[
|
||||
input_pointer_casted.into(),
|
||||
input_pointer.to_int(context).into(),
|
||||
length_casted.into(),
|
||||
output_pointer_casted.into(),
|
||||
output_pointer.to_int(context).into(),
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ where
|
||||
let value = context.build_load(output_pointer, "transferred_value")?;
|
||||
let value_extended = context.builder().build_int_z_extend(
|
||||
value.into_int_value(),
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
"transferred_value_extended",
|
||||
)?;
|
||||
Ok(value_extended.as_basic_value_enum())
|
||||
|
||||
@@ -23,21 +23,21 @@ where
|
||||
Some(CodeType::Deploy) => {
|
||||
let index_double = context.builder().build_int_mul(
|
||||
index,
|
||||
context.field_const(2),
|
||||
context.word_const(2),
|
||||
"immutable_load_index_double",
|
||||
)?;
|
||||
let offset_absolute = context.builder().build_int_add(
|
||||
index_double,
|
||||
context.field_const(
|
||||
context.word_const(
|
||||
crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA
|
||||
+ (3 * revive_common::BYTE_LENGTH_FIELD) as u64,
|
||||
+ (3 * revive_common::BYTE_LENGTH_WORD) as u64,
|
||||
),
|
||||
"immutable_offset_absolute",
|
||||
)?;
|
||||
let immutable_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::HeapAuxiliary,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
offset_absolute,
|
||||
"immutable_pointer",
|
||||
);
|
||||
@@ -68,21 +68,21 @@ where
|
||||
Some(CodeType::Deploy) => {
|
||||
let index_double = context.builder().build_int_mul(
|
||||
index,
|
||||
context.field_const(2),
|
||||
context.word_const(2),
|
||||
"immutable_load_index_double",
|
||||
)?;
|
||||
let index_offset_absolute = context.builder().build_int_add(
|
||||
index_double,
|
||||
context.field_const(
|
||||
context.word_const(
|
||||
crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA
|
||||
+ (2 * revive_common::BYTE_LENGTH_FIELD) as u64,
|
||||
+ (2 * revive_common::BYTE_LENGTH_WORD) as u64,
|
||||
),
|
||||
"index_offset_absolute",
|
||||
)?;
|
||||
let index_offset_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::HeapAuxiliary,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
index_offset_absolute,
|
||||
"immutable_index_pointer",
|
||||
);
|
||||
@@ -90,13 +90,13 @@ where
|
||||
|
||||
let value_offset_absolute = context.builder().build_int_add(
|
||||
index_offset_absolute,
|
||||
context.field_const(revive_common::BYTE_LENGTH_FIELD as u64),
|
||||
context.word_const(revive_common::BYTE_LENGTH_WORD as u64),
|
||||
"value_offset_absolute",
|
||||
)?;
|
||||
let value_offset_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::HeapAuxiliary,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
value_offset_absolute,
|
||||
"immutable_value_pointer",
|
||||
);
|
||||
|
||||
@@ -17,7 +17,7 @@ where
|
||||
let pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::Heap,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
offset,
|
||||
"memory_load_pointer",
|
||||
);
|
||||
@@ -37,7 +37,7 @@ where
|
||||
let pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::Heap,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
offset,
|
||||
"memory_store_pointer",
|
||||
);
|
||||
|
||||
@@ -24,22 +24,22 @@ where
|
||||
let immutables_offset_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::HeapAuxiliary,
|
||||
context.field_type(),
|
||||
context.field_const(crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA),
|
||||
context.word_type(),
|
||||
context.word_const(crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA),
|
||||
"immutables_offset_pointer",
|
||||
);
|
||||
context.build_store(
|
||||
immutables_offset_pointer,
|
||||
context.field_const(revive_common::BYTE_LENGTH_FIELD as u64),
|
||||
context.word_const(revive_common::BYTE_LENGTH_WORD as u64),
|
||||
)?;
|
||||
|
||||
let immutables_number_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::HeapAuxiliary,
|
||||
context.field_type(),
|
||||
context.field_const(
|
||||
context.word_type(),
|
||||
context.word_const(
|
||||
crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA
|
||||
+ (revive_common::BYTE_LENGTH_FIELD as u64),
|
||||
+ (revive_common::BYTE_LENGTH_WORD as u64),
|
||||
),
|
||||
"immutables_number_pointer",
|
||||
);
|
||||
@@ -47,22 +47,22 @@ where
|
||||
context.build_store(
|
||||
immutables_number_pointer,
|
||||
context
|
||||
.field_const((immutable_values_size / revive_common::BYTE_LENGTH_FIELD) as u64),
|
||||
.word_const((immutable_values_size / revive_common::BYTE_LENGTH_WORD) as u64),
|
||||
)?;
|
||||
let immutables_size = context.builder().build_int_mul(
|
||||
context.field_const(immutable_values_size as u64),
|
||||
context.field_const(2),
|
||||
context.word_const(immutable_values_size as u64),
|
||||
context.word_const(2),
|
||||
"immutables_size",
|
||||
)?;
|
||||
let return_data_length = context.builder().build_int_add(
|
||||
immutables_size,
|
||||
context.field_const((revive_common::BYTE_LENGTH_FIELD * 2) as u64),
|
||||
context.word_const((revive_common::BYTE_LENGTH_WORD * 2) as u64),
|
||||
"return_data_length",
|
||||
)?;
|
||||
|
||||
context.build_exit(
|
||||
context.integer_const(crate::polkavm::XLEN, 0),
|
||||
context.field_const(crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA),
|
||||
context.word_const(crate::polkavm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA),
|
||||
return_data_length,
|
||||
)?;
|
||||
}
|
||||
@@ -115,8 +115,8 @@ where
|
||||
{
|
||||
crate::polkavm::evm::memory::store(
|
||||
context,
|
||||
context.field_type().const_all_ones(),
|
||||
context.field_const(0),
|
||||
context.word_type().const_all_ones(),
|
||||
context.word_const(0),
|
||||
)?;
|
||||
context.build_call(context.intrinsics().trap, &[], "invalid_trap");
|
||||
Ok(())
|
||||
|
||||
@@ -17,7 +17,7 @@ where
|
||||
{
|
||||
match context.get_global_value(crate::polkavm::GLOBAL_RETURN_DATA_SIZE) {
|
||||
Ok(global) => Ok(global),
|
||||
Err(_error) => Ok(context.field_const(0).as_basic_value_enum()),
|
||||
Err(_error) => Ok(context.word_const(0).as_basic_value_enum()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ where
|
||||
context.build_conditional_branch(is_copy_out_of_bounds, error_block, join_block)?;
|
||||
|
||||
context.set_basic_block(error_block);
|
||||
crate::polkavm::evm::r#return::revert(context, context.field_const(0), context.field_const(0))?;
|
||||
crate::polkavm::evm::r#return::revert(context, context.word_const(0), context.word_const(0))?;
|
||||
|
||||
context.set_basic_block(join_block);
|
||||
let destination = Pointer::new_with_offset(
|
||||
|
||||
@@ -16,7 +16,7 @@ where
|
||||
let position_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::Storage,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
position,
|
||||
"storage_load_position_pointer",
|
||||
);
|
||||
@@ -35,7 +35,7 @@ where
|
||||
let position_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::Storage,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
position,
|
||||
"storage_store_position_pointer",
|
||||
);
|
||||
@@ -54,7 +54,7 @@ where
|
||||
let position_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::TransientStorage,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
position,
|
||||
"transient_storage_load_position_pointer",
|
||||
);
|
||||
@@ -73,7 +73,7 @@ where
|
||||
let position_pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::TransientStorage,
|
||||
context.field_type(),
|
||||
context.word_type(),
|
||||
position,
|
||||
"transient_storage_store_position_pointer",
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user