s/field/word

Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
xermicus
2024-05-07 13:37:17 +02:00
parent 9f8a8a782d
commit c0dd845b39
48 changed files with 291 additions and 282 deletions
+3 -3
View File
@@ -9,10 +9,10 @@ pub static DEFAULT_EXECUTABLE_NAME: &str = "zksolc";
pub const OFFSET_SCRATCH_SPACE: usize = 0;
/// The memory pointer offset.
pub const OFFSET_MEMORY_POINTER: usize = 2 * revive_common::BYTE_LENGTH_FIELD;
pub const OFFSET_MEMORY_POINTER: usize = 2 * revive_common::BYTE_LENGTH_WORD;
/// The empty slot offset.
pub const OFFSET_EMPTY_SLOT: usize = 3 * revive_common::BYTE_LENGTH_FIELD;
pub const OFFSET_EMPTY_SLOT: usize = 3 * revive_common::BYTE_LENGTH_WORD;
/// The non-reserved memory offset.
pub const OFFSET_NON_RESERVED: usize = 4 * revive_common::BYTE_LENGTH_FIELD;
pub const OFFSET_NON_RESERVED: usize = 4 * revive_common::BYTE_LENGTH_WORD;
@@ -11,9 +11,8 @@ where
{
let offset = context.builder().build_int_add(
offset,
context.field_const(
(revive_common::BYTE_LENGTH_X32 + revive_common::BYTE_LENGTH_FIELD) as u64,
),
context
.word_const((revive_common::BYTE_LENGTH_X32 + revive_common::BYTE_LENGTH_WORD) as u64),
"datacopy_contract_hash_offset",
)?;
@@ -33,8 +32,8 @@ where
{
revive_llvm_context::polkavm_evm_memory::store_byte(
context,
context.field_const(offset),
context.field_const(value),
context.word_const(offset),
context.word_const(value),
)?;
Ok(())
@@ -53,21 +52,21 @@ where
for (index, chunk) in source
.chars()
.collect::<Vec<char>>()
.chunks(revive_common::BYTE_LENGTH_FIELD * 2)
.chunks(revive_common::BYTE_LENGTH_WORD * 2)
.enumerate()
{
let mut value_string = chunk.iter().collect::<String>();
value_string.push_str(
"0".repeat((revive_common::BYTE_LENGTH_FIELD * 2) - chunk.len())
"0".repeat((revive_common::BYTE_LENGTH_WORD * 2) - chunk.len())
.as_str(),
);
let datacopy_destination = context.builder().build_int_add(
destination,
context.field_const(offset as u64),
context.word_const(offset as u64),
format!("datacopy_destination_index_{index}").as_str(),
)?;
let datacopy_value = context.field_const_str_hex(value_string.as_str());
let datacopy_value = context.word_const_str_hex(value_string.as_str());
revive_llvm_context::polkavm_evm_memory::store(
context,
datacopy_destination,
@@ -49,7 +49,7 @@ where
let condition = context.builder().build_int_compare(
inkwell::IntPredicate::NE,
condition.into_int_value(),
context.field_const(0),
context.word_const(0),
format!("conditional_{block_key}_condition_compared").as_str(),
)?;
@@ -299,7 +299,7 @@ impl Instruction {
..
} => {
let mut key_extended =
"0".repeat(revive_common::BYTE_LENGTH_FIELD * 2 - value.len());
"0".repeat(revive_common::BYTE_LENGTH_WORD * 2 - value.len());
key_extended.push_str(value.as_str());
*value = mapping.get(key_extended.as_str()).cloned().ok_or_else(|| {
@@ -11,7 +11,7 @@ where
D: revive_llvm_context::PolkaVMDependency + Clone,
{
let result = context
.field_type()
.word_type()
.const_int_from_string(
value.to_ascii_uppercase().as_str(),
inkwell::types::StringRadix::Hexadecimal,
@@ -30,7 +30,7 @@ where
D: revive_llvm_context::PolkaVMDependency + Clone,
{
let result = context
.field_type()
.word_type()
.const_int_from_string(value.as_str(), inkwell::types::StringRadix::Decimal)
.expect("Always valid");
Ok(result.as_basic_value_enum())
+4 -4
View File
@@ -88,7 +88,7 @@ impl Assembly {
hash_data_mapping: &BTreeMap<String, String>,
) -> anyhow::Result<BTreeMap<String, String>> {
let mut index_path_mapping = BTreeMap::new();
let index = "0".repeat(revive_common::BYTE_LENGTH_FIELD * 2);
let index = "0".repeat(revive_common::BYTE_LENGTH_WORD * 2);
index_path_mapping.insert(index, full_path.to_owned());
let dependencies = match self.data.as_mut() {
@@ -100,7 +100,7 @@ impl Assembly {
continue;
}
let mut index_extended = "0".repeat(revive_common::BYTE_LENGTH_FIELD * 2 - index.len());
let mut index_extended = "0".repeat(revive_common::BYTE_LENGTH_WORD * 2 - index.len());
index_extended.push_str(index.as_str());
*data = match data {
@@ -136,7 +136,7 @@ impl Assembly {
hash_data_mapping: &BTreeMap<String, String>,
) -> anyhow::Result<BTreeMap<String, String>> {
let mut index_path_mapping = BTreeMap::new();
let index = "0".repeat(revive_common::BYTE_LENGTH_FIELD * 2);
let index = "0".repeat(revive_common::BYTE_LENGTH_WORD * 2);
index_path_mapping.insert(index, full_path.to_owned());
let dependencies = match self
@@ -150,7 +150,7 @@ impl Assembly {
None => return Ok(index_path_mapping),
};
for (index, data) in dependencies.iter_mut() {
let mut index_extended = "0".repeat(revive_common::BYTE_LENGTH_FIELD * 2 - index.len());
let mut index_extended = "0".repeat(revive_common::BYTE_LENGTH_WORD * 2 - index.len());
index_extended.push_str(index.as_str());
*data = match data {
@@ -162,8 +162,8 @@ where
.value
.ok_or_else(|| anyhow::anyhow!("Instruction value missing"))?;
if value.len() > revive_common::BYTE_LENGTH_FIELD * 2 {
Ok(Some(context.field_const(0).as_basic_value_enum()))
if value.len() > revive_common::BYTE_LENGTH_WORD * 2 {
Ok(Some(context.word_const(0).as_basic_value_enum()))
} else {
crate::evmla::assembly::instruction::stack::push(context, value).map(Some)
}
@@ -522,7 +522,7 @@ where
revive_llvm_context::polkavm_evm_comparison::compare(
context,
arguments[0].into_int_value(),
context.field_const(0),
context.word_const(0),
inkwell::IntPredicate::EQ,
)
.map(Some)
@@ -571,7 +571,7 @@ where
revive_llvm_context::polkavm_evm_bitwise::xor(
context,
arguments[0].into_int_value(),
context.field_type().const_all_ones(),
context.word_type().const_all_ones(),
)
.map(Some)
}
@@ -758,7 +758,7 @@ where
.solidity_mut()
.get_or_allocate_immutable(key.as_str());
let index = context.field_const(offset as u64);
let index = context.word_const(offset as u64);
revive_llvm_context::polkavm_evm_immutable::load(context, index).map(Some)
}
InstructionName::ASSIGNIMMUTABLE => {
@@ -771,7 +771,7 @@ where
let offset = context.solidity_mut().allocate_immutable(key.as_str());
let index = context.field_const(offset as u64);
let index = context.word_const(offset as u64);
let value = arguments.pop().expect("Always exists").into_int_value();
revive_llvm_context::polkavm_evm_immutable::store(context, index, value)
.map(|_| None)
@@ -783,7 +783,7 @@ where
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{
revive_llvm_context::PolkaVMCodeType::Deploy => {
Ok(Some(context.field_const(0).as_basic_value_enum()))
Ok(Some(context.word_const(0).as_basic_value_enum()))
}
revive_llvm_context::PolkaVMCodeType::Runtime => {
let arguments = self.pop_arguments_llvm(context);
@@ -801,7 +801,7 @@ where
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{
revive_llvm_context::PolkaVMCodeType::Deploy => {
Ok(Some(context.field_const(0).as_basic_value_enum()))
Ok(Some(context.word_const(0).as_basic_value_enum()))
}
revive_llvm_context::PolkaVMCodeType::Runtime => {
revive_llvm_context::polkavm_evm_calldata::size(context).map(Some)
@@ -902,7 +902,7 @@ where
}
.map(|_| None)
}
InstructionName::PUSHSIZE => Ok(Some(context.field_const(0).as_basic_value_enum())),
InstructionName::PUSHSIZE => Ok(Some(context.word_const(0).as_basic_value_enum())),
InstructionName::RETURNDATASIZE => {
revive_llvm_context::polkavm_evm_return_data::size(context).map(Some)
}
@@ -1259,7 +1259,7 @@ where
)
.expect("Always exists");
let pointer = revive_llvm_context::PolkaVMPointer::new(
context.field_type(),
context.word_type(),
revive_llvm_context::PolkaVMAddressSpace::Stack,
context.evmla().stack
[self.stack.elements.len() - output_size + index]
@@ -1299,11 +1299,11 @@ where
let element_pointer = context.build_gep(
pointer,
&[
context.field_const(0),
context.word_const(0),
context
.integer_const(revive_common::BIT_LENGTH_X32, index as u64),
],
context.field_type(),
context.word_type(),
format!("return_value_pointer_element_{}", index).as_str(),
);
context.build_store(element_pointer, argument)?;
@@ -766,7 +766,7 @@ impl Function {
let result = match (&operands[0], &operands[1]) {
(Element::Tag(tag), Element::Constant(offset)) => {
let offset = offset % revive_common::BIT_LENGTH_FIELD;
let offset = offset % revive_common::BIT_LENGTH_WORD;
let offset = offset.to_u64().expect("Always valid");
let result = tag << offset;
if Self::is_tag_value_valid(blocks, &result) {
@@ -776,7 +776,7 @@ impl Function {
}
}
(Element::Constant(constant), Element::Constant(offset)) => {
let offset = offset % revive_common::BIT_LENGTH_FIELD;
let offset = offset % revive_common::BIT_LENGTH_WORD;
let offset = offset.to_u64().expect("Always valid");
Element::Constant(constant << offset)
}
@@ -793,7 +793,7 @@ impl Function {
let result = match (&operands[0], &operands[1]) {
(Element::Tag(tag), Element::Constant(offset)) => {
let offset = offset % revive_common::BIT_LENGTH_FIELD;
let offset = offset % revive_common::BIT_LENGTH_WORD;
let offset = offset.to_u64().expect("Always valid");
let result = tag >> offset;
if Self::is_tag_value_valid(blocks, &result) {
@@ -803,7 +803,7 @@ impl Function {
}
}
(Element::Constant(constant), Element::Constant(offset)) => {
let offset = offset % revive_common::BIT_LENGTH_FIELD;
let offset = offset % revive_common::BIT_LENGTH_WORD;
let offset = offset.to_u64().expect("Always valid");
Element::Constant(constant >> offset)
}
@@ -1151,7 +1151,7 @@ where
let r#type = context.function_type(
vec![
context
.integer_type(revive_common::BIT_LENGTH_FIELD)
.integer_type(revive_common::BIT_LENGTH_WORD)
.as_basic_type_enum();
input_size
],
@@ -1200,7 +1200,7 @@ where
let mut stack_variables = Vec::with_capacity(self.stack_size);
for stack_index in 0..self.stack_size {
let pointer = context.build_alloca(
context.field_type(),
context.word_type(),
format!("stack_var_{stack_index:03}").as_str(),
);
let value = match self.r#type {
@@ -1215,7 +1215,7 @@ where
.get_nth_param((stack_index - 1) as u32)
.expect("Always valid")
}
_ => context.field_const(0).as_basic_value_enum(),
_ => context.word_const(0).as_basic_value_enum(),
};
context.build_store(pointer, value)?;
stack_variables.push(revive_llvm_context::PolkaVMArgument::new(
+2 -2
View File
@@ -33,7 +33,7 @@ impl Contract {
/// A shortcut constructor.
pub fn new(
path: String,
source_hash: [u8; revive_common::BYTE_LENGTH_FIELD],
source_hash: [u8; revive_common::BYTE_LENGTH_WORD],
source_version: SolcVersion,
ir: IR,
metadata_json: Option<serde_json::Value>,
@@ -98,7 +98,7 @@ impl Contract {
optimizer.settings().to_owned(),
);
let metadata_json = serde_json::to_value(&metadata).expect("Always valid");
let metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_FIELD]> = if include_metadata_hash
let metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_WORD]> = if include_metadata_hash
{
let metadata_string = serde_json::to_string(&metadata).expect("Always valid");
Some(sha3::Keccak256::digest(metadata_string.as_bytes()).into())
@@ -145,12 +145,12 @@ where
let field_pointer = context.build_gep(
tuple_pointer,
&[
context.field_const(0),
context.word_const(0),
context
.integer_type(revive_common::BIT_LENGTH_X32)
.const_int(index as u64, false),
],
context.field_type().as_basic_type_enum(),
context.word_type().as_basic_type_enum(),
format!("assignment_binding_{index}_gep_pointer").as_str(),
);
@@ -263,7 +263,7 @@ impl FunctionCall {
revive_llvm_context::polkavm_evm_comparison::compare(
context,
arguments[0].into_int_value(),
context.field_const(0),
context.word_const(0),
inkwell::IntPredicate::EQ,
)
.map(Some)
@@ -312,7 +312,7 @@ impl FunctionCall {
revive_llvm_context::polkavm_evm_bitwise::xor(
context,
arguments[0].into_int_value(),
context.field_type().const_all_ones(),
context.word_type().const_all_ones(),
)
.map(Some)
}
@@ -512,7 +512,7 @@ impl FunctionCall {
let offset = context.solidity_mut().allocate_immutable(key.as_str());
let index = context.field_const(offset as u64);
let index = context.word_const(offset as u64);
let value = arguments[2].value.into_int_value();
revive_llvm_context::polkavm_evm_immutable::store(context, index, value)
.map(|_| None)
@@ -526,7 +526,7 @@ impl FunctionCall {
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{
revive_llvm_context::PolkaVMCodeType::Deploy => {
Ok(Some(context.field_const(0).as_basic_value_enum()))
Ok(Some(context.word_const(0).as_basic_value_enum()))
}
revive_llvm_context::PolkaVMCodeType::Runtime => {
revive_llvm_context::polkavm_evm_calldata::load(
@@ -543,7 +543,7 @@ impl FunctionCall {
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{
revive_llvm_context::PolkaVMCodeType::Deploy => {
Ok(Some(context.field_const(0).as_basic_value_enum()))
Ok(Some(context.word_const(0).as_basic_value_enum()))
}
revive_llvm_context::PolkaVMCodeType::Runtime => {
revive_llvm_context::polkavm_evm_calldata::size(context).map(Some)
@@ -877,8 +877,8 @@ impl FunctionCall {
let arguments = self.pop_arguments_llvm::<D, 3>(context)?;
let offset = context.builder().build_int_add(
arguments[0].into_int_value(),
context.field_const(
(revive_common::BYTE_LENGTH_X32 + revive_common::BYTE_LENGTH_FIELD) as u64,
context.word_const(
(revive_common::BYTE_LENGTH_X32 + revive_common::BYTE_LENGTH_WORD) as u64,
),
"datacopy_contract_hash_offset",
)?;
@@ -138,8 +138,7 @@ impl Literal {
let mut hex_string = if inner.is_hexadecimal {
string.clone()
} else {
let mut hex_string =
String::with_capacity(revive_common::BYTE_LENGTH_FIELD * 2);
let mut hex_string = String::with_capacity(revive_common::BYTE_LENGTH_WORD * 2);
let mut index = 0;
loop {
if index >= string.len() {
@@ -200,16 +199,16 @@ impl Literal {
hex_string
};
if hex_string.len() > revive_common::BYTE_LENGTH_FIELD * 2 {
if hex_string.len() > revive_common::BYTE_LENGTH_WORD * 2 {
return Ok(revive_llvm_context::PolkaVMArgument::new_with_original(
r#type.const_zero().as_basic_value_enum(),
string,
));
}
if hex_string.len() < revive_common::BYTE_LENGTH_FIELD * 2 {
if hex_string.len() < revive_common::BYTE_LENGTH_WORD * 2 {
hex_string.push_str(
"0".repeat((revive_common::BYTE_LENGTH_FIELD * 2) - hex_string.len())
"0".repeat((revive_common::BYTE_LENGTH_WORD * 2) - hex_string.len())
.as_str(),
);
}
@@ -82,13 +82,13 @@ where
.into_int_value();
let condition = context.builder().build_int_z_extend_or_bit_cast(
condition,
context.field_type(),
context.word_type(),
"for_condition_extended",
)?;
let condition = context.builder().build_int_compare(
inkwell::IntPredicate::NE,
condition,
context.field_const(0),
context.word_const(0),
"for_condition_compared",
)?;
context.build_conditional_branch(condition, body_block, join_block)?;
@@ -285,12 +285,12 @@ where
let pointer = context.build_gep(
pointer,
&[
context.field_const(0),
context.word_const(0),
context
.integer_type(revive_common::BIT_LENGTH_X32)
.const_int(index as u64, false),
],
context.field_type(),
context.word_type(),
format!("return_{index}_gep_pointer").as_str(),
);
context.build_store(pointer, r#type.const_zero())?;
@@ -61,13 +61,13 @@ where
.into_int_value();
let condition = context.builder().build_int_z_extend_or_bit_cast(
condition,
context.field_type(),
context.word_type(),
"if_condition_extended",
)?;
let condition = context.builder().build_int_compare(
inkwell::IntPredicate::NE,
condition,
context.field_const(0),
context.word_const(0),
"if_condition_compared",
)?;
let main_block = context.append_basic_block("if_main");
@@ -185,7 +185,7 @@ where
let pointer = context.build_gep(
pointer,
&[
context.field_const(0),
context.word_const(0),
context
.integer_type(revive_common::BIT_LENGTH_X32)
.const_int(index as u64, false),
+2 -2
View File
@@ -26,7 +26,7 @@ pub enum Type {
impl Default for Type {
fn default() -> Self {
Self::UInt(revive_common::BIT_LENGTH_FIELD)
Self::UInt(revive_common::BIT_LENGTH_WORD)
}
}
@@ -73,7 +73,7 @@ impl Type {
Self::Bool => context.integer_type(revive_common::BIT_LENGTH_BOOLEAN),
Self::Int(bitlength) => context.integer_type(bitlength),
Self::UInt(bitlength) => context.integer_type(bitlength),
Self::Custom(_) => context.field_type(),
Self::Custom(_) => context.word_type(),
}
}
}