add common crate

Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
xermicus
2024-03-22 16:19:18 +01:00
parent 50f2dd9b74
commit c52a8d0f20
65 changed files with 839 additions and 271 deletions
Generated
+12 -13
View File
@@ -560,23 +560,11 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "era-compiler-common"
version = "1.5.0"
source = "git+https://github.com/matter-labs/era-compiler-common?branch=main#6781681145a37d9809057cf6fc3fa667abd545af"
dependencies = [
"anyhow",
"serde",
"serde_json",
"serde_stacker",
]
[[package]]
name = "era-compiler-llvm-context"
version = "1.4.1"
dependencies = [
"anyhow",
"era-compiler-common",
"hex",
"inkwell",
"itertools 0.12.1",
@@ -586,6 +574,7 @@ dependencies = [
"pallet-contracts-pvm-llapi",
"regex",
"revive-builtins",
"revive-common",
"revive-linker",
"revive-stdlib",
"semver 1.0.22",
@@ -1424,6 +1413,16 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
name = "revive-builtins"
version = "0.1.0"
[[package]]
name = "revive-common"
version = "0.1.0"
dependencies = [
"anyhow",
"serde",
"serde_json",
"serde_stacker",
]
[[package]]
name = "revive-extensions"
version = "0.1.0"
@@ -1465,7 +1464,6 @@ version = "1.4.0"
dependencies = [
"anyhow",
"colored",
"era-compiler-common",
"era-compiler-llvm-context",
"hex",
"inkwell",
@@ -1477,6 +1475,7 @@ dependencies = [
"rand",
"rayon",
"regex",
"revive-common",
"semver 1.0.22",
"serde",
"serde_json",
+1
View File
@@ -33,6 +33,7 @@ parity-scale-codec = "3.6"
alloy-primitives = "0.6"
alloy-sol-types = "0.6"
env_logger = { version = "0.10.0", default-features = false }
serde_stacker = "0.1"
[workspace.dependencies.inkwell]
git = "https://github.com/TheDan64/inkwell.git"
+39
View File
@@ -0,0 +1,39 @@
---
name: Bug report
about: Use this template for reporting issues
title: ''
labels: bug
assignees: ''
---
### 🐛 Bug Report
#### 📝 Description
Provide a clear and concise description of the bug.
#### 🔄 Reproduction Steps
Steps to reproduce the behaviour
#### 🤔 Expected Behavior
Describe what you expected to happen.
#### 😯 Current Behavior
Describe what actually happened.
#### 🖥️ Environment
Any relevant environment details.
#### 📋 Additional Context
Add any other context about the problem here. If applicable, add screenshots to help explain.
#### 📎 Log Output
```
Paste any relevant log output here.
```
+21
View File
@@ -0,0 +1,21 @@
---
name: Feature request
about: Use this template for requesting features
title: ''
labels: feat
assignees: ''
---
### 🌟 Feature Request
#### 📝 Description
Provide a clear and concise description of the feature you'd like to see.
#### 🤔 Rationale
Explain why this feature is important and how it benefits the project.
#### 📋 Additional Context
Add any other context or information about the feature request here.
+20
View File
@@ -0,0 +1,20 @@
# What ❔
<!-- What are the changes this PR brings about? -->
<!-- Example: This PR adds a PR template to the repo. -->
<!-- (For bigger PRs adding more context is appreciated) -->
## Why ❔
<!-- Why are these changes done? What goal do they contribute to? What are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future iterators are in context about the evolution of repos. -->
## Checklist
<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->
- [ ] PR title corresponds to the body of PR.
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `cargo fmt` and checked with `cargo clippy`.
+9
View File
@@ -0,0 +1,9 @@
name: Cargo license check
on: pull_request
jobs:
cargo-deny:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v1
+23
View File
@@ -0,0 +1,23 @@
name: "Rust CI"
on:
pull_request:
jobs:
build:
name: cargo build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: cargo build --verbose
formatting:
name: cargo fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: rustfmt
- name: Rustfmt Check
uses: actions-rust-lang/rustfmt@v1
+17
View File
@@ -0,0 +1,17 @@
name: Leaked Secrets Scan
on: [pull_request]
jobs:
TruffleHog:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
with:
fetch-depth: 0
- name: TruffleHog OSS
uses: trufflesecurity/trufflehog@0c66d30c1f4075cee1aada2e1ab46dabb1b0071a
with:
path: ./
base: ${{ github.event.repository.default_branch }}
head: HEAD
extra_args: --debug --only-verified
+14
View File
@@ -0,0 +1,14 @@
# Generated by Cargo
# will have compiled files and executables
/target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# IDE
/.idea/
/.vscode/
+19
View File
@@ -0,0 +1,19 @@
[package]
name = "revive-common"
version = "0.1.0"
authors = [
"Cyrill Leutwiler <cyrill@parity.io>",
"Oleksandr Zarudnyi <a.zarudnyy@matterlabs.dev>",
]
license = "MIT OR Apache-2.0"
edition = "2021"
description = "Shared constants of the revive compiler"
[lib]
doctest = false
[dependencies]
anyhow = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = [ "arbitrary_precision", "unbounded_depth" ] }
serde_stacker = { workspace = true }
+35
View File
@@ -0,0 +1,35 @@
# zkSync Era: Compiler Common
[![Logo](eraLogo.svg)](https://zksync.io/)
zkSync Era is a layer 2 rollup that uses zero-knowledge proofs to scale Ethereum without compromising on security
or decentralization. As it's EVM-compatible (with Solidity/Vyper), 99% of Ethereum projects can redeploy without
needing to refactor or re-audit any code. zkSync Era also uses an LLVM-based compiler that will eventually enable
developers to write smart contracts in popular languages such as C++ and Rust.
This repository contains the common compiler constants.
## License
This library is distributed under the terms of either
- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
at your option.
## Official Links
- [Website](https://zksync.io/)
- [GitHub](https://github.com/matter-labs)
- [Twitter](https://twitter.com/zksync)
- [Twitter for Devs](https://twitter.com/zkSyncDevs)
- [Discord](https://join.zksync.dev/)
## Disclaimer
zkSync Era has been through extensive testing and audits, and although it is live, it is still in alpha state and
will undergo further audits and bug bounty programs. We would love to hear our community's thoughts and suggestions
about it!
It's important to note that forking it now could potentially lead to missing important
security updates, critical features, and performance improvements.
+15
View File
@@ -0,0 +1,15 @@
//!
//! The number base constants.
//!
/// The binary number base.
pub const BASE_BINARY: u32 = 2;
/// The octal number base.
pub const BASE_OCTAL: u32 = 8;
/// The decimal number base.
pub const BASE_DECIMAL: u32 = 10;
/// The hexadecimal number base.
pub const BASE_HEXADECIMAL: u32 = 16;
+22
View File
@@ -0,0 +1,22 @@
//!
//! The common sizes in bits.
//!
/// The `bool` type bit-length.
pub const BIT_LENGTH_BOOLEAN: usize = 1;
/// The `u8` type or byte bit-length.
pub const BIT_LENGTH_BYTE: usize = 8;
/// The x86 word type (usually `u32`) bit-length.
pub const BIT_LENGTH_X32: usize = crate::byte_length::BYTE_LENGTH_X32 * BIT_LENGTH_BYTE;
/// The x86_64 word type (usually `u64`) bit-length.
pub const BIT_LENGTH_X64: usize = crate::byte_length::BYTE_LENGTH_X64 * BIT_LENGTH_BYTE;
/// The ETH address (usually `u160`) bit-length.
pub const BIT_LENGTH_ETH_ADDRESS: usize =
crate::byte_length::BYTE_LENGTH_ETH_ADDRESS * BIT_LENGTH_BYTE;
/// The field (usually `u256` or `i256`) bit-length.
pub const BIT_LENGTH_FIELD: usize = crate::byte_length::BYTE_LENGTH_FIELD * BIT_LENGTH_BYTE;
+18
View File
@@ -0,0 +1,18 @@
//!
//! The common sizes in bytes.
//!
/// The byte-length.
pub const BYTE_LENGTH_BYTE: usize = 1;
/// The x86 word byte-length.
pub const BYTE_LENGTH_X32: usize = 4;
/// The x86_64 word byte-length.
pub const BYTE_LENGTH_X64: usize = 8;
/// The ETH address byte-length.
pub const BYTE_LENGTH_ETH_ADDRESS: usize = 20;
/// The field byte-length.
pub const BYTE_LENGTH_FIELD: usize = 32;
+120
View File
@@ -0,0 +1,120 @@
//!
//! The EraVM address constants.
//!
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_TO_L1: u16 = 0xFFFF;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_CODE_ADDRESS: u16 = 0xFFFE;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_PRECOMPILE: u16 = 0xFFFD;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_META: u16 = 0xFFFC;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_MIMIC_CALL: u16 = 0xFFFB;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_SYSTEM_MIMIC_CALL: u16 = 0xFFFA;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_MIMIC_CALL_BYREF: u16 = 0xFFF9;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_SYSTEM_MIMIC_CALL_BYREF: u16 = 0xFFF8;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_RAW_FAR_CALL: u16 = 0xFFF7;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_RAW_FAR_CALL_BYREF: u16 = 0xFFF6;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_SYSTEM_CALL: u16 = 0xFFF5;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_SYSTEM_CALL_BYREF: u16 = 0xFFF4;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_SET_CONTEXT_VALUE_CALL: u16 = 0xFFF3;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_SET_PUBDATA_PRICE: u16 = 0xFFF2;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_INCREMENT_TX_COUNTER: u16 = 0xFFF1;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_GET_GLOBAL_PTR_CALLDATA: u16 = 0xFFF0;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_GET_GLOBAL_CALL_FLAGS: u16 = 0xFFEF;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_GET_GLOBAL_PTR_RETURN_DATA: u16 = 0xFFEE;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_EVENT_INITIALIZE: u16 = 0xFFED;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_EVENT_WRITE: u16 = 0xFFEC;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_ACTIVE_PTR_LOAD_CALLDATA: u16 = 0xFFEB;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_ACTIVE_PTR_LOAD_RETURN_DATA: u16 = 0xFFEA;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_ACTIVE_PTR_ADD: u16 = 0xFFE9;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_ACTIVE_PTR_SHRINK: u16 = 0xFFE8;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_ACTIVE_PTR_PACK: u16 = 0xFFE7;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_MULTIPLICATION_HIGH_REGISTER: u16 = 0xFFE6;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_GET_GLOBAL_EXTRA_ABI_DATA: u16 = 0xFFE5;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_ACTIVE_PTR_DATA_LOAD: u16 = 0xFFE4;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_ACTIVE_PTR_DATA_COPY: u16 = 0xFFE3;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_ACTIVE_PTR_DATA_SIZE: u16 = 0xFFE2;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_CONST_ARRAY_DECLARE: u16 = 0xFFE1;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_CONST_ARRAY_SET: u16 = 0xFFE0;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_CONST_ARRAY_FINALIZE: u16 = 0xFFDF;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_CONST_ARRAY_GET: u16 = 0xFFDE;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_DECOMMIT: u16 = 0xFFDD;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_ACTIVE_PTR_LOAD_DECOMMIT: u16 = 0xFFDC;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_RETURN_FORWARD: u16 = 0xFFDB;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_REVERT_FORWARD: u16 = 0xFFDA;
/// The corresponding simulation predefined address.
pub const ERAVM_ADDRESS_ACTIVE_PTR_SWAP: u16 = 0xFFD9;
+5
View File
@@ -0,0 +1,5 @@
//!
//! The EraVM constants.
//!
pub mod address;
+91
View File
@@ -0,0 +1,91 @@
//!
//! The EVM version.
//!
use serde::Deserialize;
use serde::Serialize;
///
/// The EVM version.
///
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[serde(rename_all = "camelCase")]
pub enum EVMVersion {
/// The corresponding EVM version.
#[serde(rename = "homestead")]
Homestead,
/// The corresponding EVM version.
#[serde(rename = "tangerineWhistle")]
TangerineWhistle,
/// The corresponding EVM version.
#[serde(rename = "spuriousDragon")]
SpuriousDragon,
/// The corresponding EVM version.
#[serde(rename = "byzantium")]
Byzantium,
/// The corresponding EVM version.
#[serde(rename = "constantinople")]
Constantinople,
/// The corresponding EVM version.
#[serde(rename = "petersburg")]
Petersburg,
/// The corresponding EVM version.
#[serde(rename = "istanbul")]
Istanbul,
/// The corresponding EVM version.
#[serde(rename = "berlin")]
Berlin,
/// The corresponding EVM version.
#[serde(rename = "london")]
London,
/// The corresponding EVM version.
#[serde(rename = "paris")]
Paris,
/// The corresponding EVM version.
#[serde(rename = "shanghai")]
Shanghai,
/// The corresponding EVM version.
#[serde(rename = "cancun")]
Cancun,
}
impl TryFrom<&str> for EVMVersion {
type Error = anyhow::Error;
fn try_from(value: &str) -> Result<Self, Self::Error> {
Ok(match value {
"homestead" => Self::Homestead,
"tangerineWhistle" => Self::TangerineWhistle,
"spuriousDragon" => Self::SpuriousDragon,
"byzantium" => Self::Byzantium,
"constantinople" => Self::Constantinople,
"petersburg" => Self::Petersburg,
"istanbul" => Self::Istanbul,
"berlin" => Self::Berlin,
"london" => Self::London,
"paris" => Self::Paris,
"shanghai" => Self::Shanghai,
"cancun" => Self::Cancun,
_ => anyhow::bail!("Invalid EVM version: {}", value),
})
}
}
impl std::fmt::Display for EVMVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Homestead => write!(f, "homestead"),
Self::TangerineWhistle => write!(f, "tangerineWhistle"),
Self::SpuriousDragon => write!(f, "spuriousDragon"),
Self::Byzantium => write!(f, "byzantium"),
Self::Constantinople => write!(f, "constantinople"),
Self::Petersburg => write!(f, "petersburg"),
Self::Istanbul => write!(f, "istanbul"),
Self::Berlin => write!(f, "berlin"),
Self::London => write!(f, "london"),
Self::Paris => write!(f, "paris"),
Self::Shanghai => write!(f, "shanghai"),
Self::Cancun => write!(f, "cancun"),
}
}
}
+9
View File
@@ -0,0 +1,9 @@
//!
//! The exit code constants.
//!
/// The common application success exit code.
pub const EXIT_CODE_SUCCESS: i32 = 0;
/// The common application failure exit code.
pub const EXIT_CODE_FAILURE: i32 = 1;
+48
View File
@@ -0,0 +1,48 @@
//!
//! The file extensions.
//!
/// The manifest file extension.
pub static EXTENSION_MANIFEST: &str = "toml";
/// The JSON data file extension.
pub static EXTENSION_JSON: &str = "json";
/// The ABI file extension.
pub static EXTENSION_ABI: &str = "abi";
/// The Yul IR file extension.
pub static EXTENSION_YUL: &str = "yul";
/// The EVM legacy assembly IR file extension.
pub static EXTENSION_EVMLA: &str = "evmla";
/// The Ethereal IR file extension.
pub static EXTENSION_ETHIR: &str = "ethir";
/// The EVM file extension.
pub static EXTENSION_EVM: &str = "evm";
/// The EVM bytecode file extension.
pub static EXTENSION_EVM_BINARY: &str = "bin";
/// The Solidity file extension.
pub static EXTENSION_SOLIDITY: &str = "sol";
/// The LLL IR file extension.
pub static EXTENSION_LLL: &str = "lll";
/// The Vyper file extension.
pub static EXTENSION_VYPER: &str = "vy";
/// The LLVM source code file extension.
pub static EXTENSION_LLVM_SOURCE: &str = "ll";
/// The LLVM bitcode file extension.
pub static EXTENSION_LLVM_BINARY: &str = "bc";
/// The EraVM assembly file extension.
pub static EXTENSION_ERAVM_ASSEMBLY: &str = "zasm";
/// The EraVM bytecode file extension.
pub static EXTENSION_ERAVM_BINARY: &str = "zbin";
+21
View File
@@ -0,0 +1,21 @@
//!
//! The compiler common library.
//!
pub(crate) mod base;
pub(crate) mod bit_length;
pub(crate) mod byte_length;
pub(crate) mod eravm;
pub(crate) mod evm_version;
pub(crate) mod exit_code;
pub(crate) mod extension;
pub(crate) mod utils;
pub use self::base::*;
pub use self::bit_length::*;
pub use self::byte_length::*;
pub use self::eravm::address::*;
pub use self::evm_version::EVMVersion;
pub use self::exit_code::*;
pub use self::extension::*;
pub use self::utils::*;
+35
View File
@@ -0,0 +1,35 @@
//!
//! The compiler common utils.
//!
///
/// Deserializes a `serde_json` object from slice with the recursion limit disabled.
///
/// Must be used for all JSON I/O to avoid crashes due to the aforementioned limit.
///
pub fn deserialize_from_slice<O>(input: &[u8]) -> anyhow::Result<O>
where
O: serde::de::DeserializeOwned,
{
let mut deserializer = serde_json::Deserializer::from_slice(input);
deserializer.disable_recursion_limit();
let deserializer = serde_stacker::Deserializer::new(&mut deserializer);
let result = O::deserialize(deserializer)?;
Ok(result)
}
///
/// Deserializes a `serde_json` object from string with the recursion limit disabled.
///
/// Must be used for all JSON I/O to avoid crashes due to the aforementioned limit.
///
pub fn deserialize_from_str<O>(input: &str) -> anyhow::Result<O>
where
O: serde::de::DeserializeOwned,
{
let mut deserializer = serde_json::Deserializer::from_str(input);
deserializer.disable_recursion_limit();
let deserializer = serde_stacker::Deserializer::new(&mut deserializer);
let result = O::deserialize(deserializer)?;
Ok(result)
}
+1 -1
View File
@@ -27,7 +27,7 @@ md5 = { workspace = true }
inkwell = { workspace = true }
zkevm_opcode_defs = { git = "https://github.com/matter-labs/era-zkevm_opcode_defs", branch = "v1.4.1" }
era-compiler-common = { git = "https://github.com/matter-labs/era-compiler-common", branch = "main" }
revive-common = { path = "../common" }
pallet-contracts-pvm-llapi = { path = "../pallet-contracts-pvm-llapi" }
revive-linker = { path = "../linker" }
@@ -29,12 +29,12 @@ impl IRType {
///
pub fn file_extension(&self) -> &'static str {
match self {
Self::Yul => era_compiler_common::EXTENSION_YUL,
Self::EthIR => era_compiler_common::EXTENSION_ETHIR,
Self::EVMLA => era_compiler_common::EXTENSION_EVMLA,
Self::LLL => era_compiler_common::EXTENSION_LLL,
Self::LLVM => era_compiler_common::EXTENSION_LLVM_SOURCE,
Self::Assembly => era_compiler_common::EXTENSION_ERAVM_ASSEMBLY,
Self::Yul => revive_common::EXTENSION_YUL,
Self::EthIR => revive_common::EXTENSION_ETHIR,
Self::EVMLA => revive_common::EXTENSION_EVMLA,
Self::LLL => revive_common::EXTENSION_LLL,
Self::LLVM => revive_common::EXTENSION_LLVM_SOURCE,
Self::Assembly => revive_common::EXTENSION_ERAVM_ASSEMBLY,
}
}
}
+2 -2
View File
@@ -43,7 +43,7 @@ pub const HEAP_AUX_OFFSET_EXTERNAL_CALL: u64 = 0;
/// The constructor return data offset in the auxiliary heap.
pub const HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA: u64 =
8 * (era_compiler_common::BYTE_LENGTH_FIELD as u64);
8 * (revive_common::BYTE_LENGTH_FIELD as u64);
/// The number of the extra ABI data arguments.
pub const EXTRA_ABI_DATA_SIZE: usize = 0;
@@ -69,4 +69,4 @@ pub const SYSTEM_CALL_BIT: bool = true;
/// - constructor arguments length (32 bytes)
///
pub const DEPLOYER_CALL_HEADER_SIZE: usize =
era_compiler_common::BYTE_LENGTH_X32 + (era_compiler_common::BYTE_LENGTH_FIELD * 4);
revive_common::BYTE_LENGTH_X32 + (revive_common::BYTE_LENGTH_FIELD * 4);
@@ -15,7 +15,7 @@ pub struct Build {
/// The EraVM text assembly.
pub assembly_text: String,
/// The metadata hash.
pub metadata_hash: Option<[u8; era_compiler_common::BYTE_LENGTH_FIELD]>,
pub metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_FIELD]>,
/// The EraVM binary bytecode.
pub bytecode: Vec<u8>,
/// The EraVM bytecode hash.
@@ -30,7 +30,7 @@ impl Build {
///
pub fn new(
assembly_text: String,
metadata_hash: Option<[u8; era_compiler_common::BYTE_LENGTH_FIELD]>,
metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_FIELD]>,
bytecode: Vec<u8>,
bytecode_hash: String,
) -> Self {
@@ -46,8 +46,8 @@ impl<'ctx> Intrinsics<'ctx> {
) -> Self {
let void_type = llvm.void_type();
let bool_type = llvm.bool_type();
let byte_type = llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_BYTE as u32);
let field_type = llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32);
let byte_type = llvm.custom_width_int_type(revive_common::BIT_LENGTH_BYTE as u32);
let field_type = llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32);
let _stack_field_pointer_type = field_type.ptr_type(AddressSpace::Stack.into());
let heap_field_pointer_type = byte_type.ptr_type(AddressSpace::Heap.into());
let generic_byte_pointer_type = byte_type.ptr_type(AddressSpace::Generic.into());
@@ -126,7 +126,7 @@ impl<'ctx> Intrinsics<'ctx> {
llvm: &'ctx inkwell::context::Context,
name: &str,
) -> Vec<inkwell::types::BasicTypeEnum<'ctx>> {
let field_type = llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32);
let field_type = llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32);
match name {
name if name == Self::FUNCTION_MEMORY_COPY => vec![
@@ -202,10 +202,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
let div = Self::declare(
module,
Self::FUNCTION_DIV,
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.fn_type(
vec![
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into();
2
@@ -221,10 +221,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
let r#mod = Self::declare(
module,
Self::FUNCTION_MOD,
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.fn_type(
vec![
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into();
2
@@ -240,10 +240,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
let sdiv = Self::declare(
module,
Self::FUNCTION_SDIV,
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.fn_type(
vec![
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into();
2
@@ -259,10 +259,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
let smod = Self::declare(
module,
Self::FUNCTION_SMOD,
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.fn_type(
vec![
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into();
2
@@ -278,10 +278,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
let shl = Self::declare(
module,
Self::FUNCTION_SHL,
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.fn_type(
vec![
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into();
2
@@ -297,10 +297,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
let shr = Self::declare(
module,
Self::FUNCTION_SHR,
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.fn_type(
vec![
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into();
2
@@ -316,10 +316,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
let sar = Self::declare(
module,
Self::FUNCTION_SAR,
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.fn_type(
vec![
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into();
2
@@ -335,10 +335,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
let byte = Self::declare(
module,
Self::FUNCTION_BYTE,
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.fn_type(
vec![
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into();
2
@@ -354,10 +354,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
let add_mod = Self::declare(
module,
Self::FUNCTION_ADDMOD,
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.fn_type(
vec![
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into();
3
@@ -373,10 +373,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
let mul_mod = Self::declare(
module,
Self::FUNCTION_MULMOD,
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.fn_type(
vec![
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into();
3
@@ -392,10 +392,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
let exp = Self::declare(
module,
Self::FUNCTION_EXP,
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.fn_type(
vec![
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into();
2
@@ -409,10 +409,10 @@ impl<'ctx> LLVMRuntime<'ctx> {
Function::set_pure_function_attributes(llvm, exp);
let sign_extend = FunctionDeclaration::new(
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.fn_type(
vec![
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into();
2
@@ -432,11 +432,11 @@ impl<'ctx> LLVMRuntime<'ctx> {
Self::FUNCTION_MSTORE8,
llvm.void_type().fn_type(
vec![
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_BYTE as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_BYTE as u32)
.ptr_type(AddressSpace::Heap.into())
.as_basic_type_enum()
.into(),
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into(),
]
@@ -460,17 +460,17 @@ impl<'ctx> LLVMRuntime<'ctx> {
let sha3 = Self::declare(
module,
Self::FUNCTION_SHA3,
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.fn_type(
vec![
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_BYTE as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_BYTE as u32)
.ptr_type(AddressSpace::Heap.into())
.as_basic_type_enum()
.into(),
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into(),
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_BOOLEAN as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_BOOLEAN as u32)
.as_basic_type_enum()
.into(),
]
@@ -491,19 +491,19 @@ impl<'ctx> LLVMRuntime<'ctx> {
let system_request = Self::declare(
module,
Self::FUNCTION_SYSTEM_REQUEST,
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.fn_type(
vec![
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into(),
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into(),
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into(),
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.ptr_type(AddressSpace::Stack.into())
.as_basic_type_enum()
.into(),
@@ -523,7 +523,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
);
let external_call_arguments: Vec<inkwell::types::BasicMetadataTypeEnum> = vec![
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into();
crate::eravm::context::function::runtime::entry::Entry::MANDATORY_ARGUMENTS_COUNT
@@ -531,23 +531,23 @@ impl<'ctx> LLVMRuntime<'ctx> {
];
let mut mimic_call_arguments = external_call_arguments.clone();
mimic_call_arguments.push(
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into(),
);
let mut external_call_arguments_by_ref: Vec<inkwell::types::BasicMetadataTypeEnum> = vec![
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_BYTE as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_BYTE as u32)
.ptr_type(AddressSpace::Generic.into())
.as_basic_type_enum()
.into(),
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into(),
];
external_call_arguments_by_ref.extend::<Vec<inkwell::types::BasicMetadataTypeEnum>>(vec![
llvm.custom_width_int_type(
era_compiler_common::BIT_LENGTH_FIELD as u32
revive_common::BIT_LENGTH_FIELD as u32
)
.as_basic_type_enum()
.into();
@@ -555,7 +555,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
]);
let mut mimic_call_arguments_by_ref = external_call_arguments_by_ref.clone();
mimic_call_arguments_by_ref.push(
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into(),
);
@@ -563,7 +563,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
let external_call_result_type = llvm
.struct_type(
&[
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_BYTE as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_BYTE as u32)
.ptr_type(AddressSpace::Generic.into())
.as_basic_type_enum(),
llvm.bool_type().as_basic_type_enum(),
@@ -635,7 +635,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
Self::FUNCTION_RETURN,
llvm.void_type().fn_type(
vec![
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into();
3
@@ -651,7 +651,7 @@ impl<'ctx> LLVMRuntime<'ctx> {
Self::FUNCTION_REVERT,
llvm.void_type().fn_type(
vec![
llvm.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
llvm.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
.as_basic_type_enum()
.into();
3
@@ -63,7 +63,7 @@ impl<'ctx> Return<'ctx> {
/// Returns the return data size in bytes, based on the default stack alignment.
///
pub fn return_data_size(&self) -> usize {
era_compiler_common::BYTE_LENGTH_FIELD
revive_common::BYTE_LENGTH_FIELD
* match self {
Self::None => 0,
Self::Primitive { .. } => 1,
@@ -69,11 +69,11 @@ where
context.set_basic_block(context.current_function().borrow().entry_block());
context.set_code_type(CodeType::Deploy);
if let Some(vyper) = context.vyper_data.as_ref() {
for index in 0..vyper.immutables_size() / era_compiler_common::BYTE_LENGTH_FIELD {
for index in 0..vyper.immutables_size() / revive_common::BYTE_LENGTH_FIELD {
let offset = (crate::eravm::r#const::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA
as usize)
+ (1 + index) * 2 * era_compiler_common::BYTE_LENGTH_FIELD;
let value = index * era_compiler_common::BYTE_LENGTH_FIELD;
+ (1 + index) * 2 * revive_common::BYTE_LENGTH_FIELD;
let value = index * revive_common::BYTE_LENGTH_FIELD;
let pointer = Pointer::new_with_offset(
context,
AddressSpace::HeapAuxiliary,
@@ -140,7 +140,7 @@ where
let salt_offset = context.builder().build_int_add(
input_offset,
context.field_const(era_compiler_common::BYTE_LENGTH_X32 as u64),
context.field_const(revive_common::BYTE_LENGTH_X32 as u64),
"deployer_call_salt_offset",
)?;
let salt_pointer = Pointer::new_with_offset(
@@ -154,7 +154,7 @@ where
let arguments_offset_offset = context.builder().build_int_add(
salt_offset,
context.field_const((era_compiler_common::BYTE_LENGTH_FIELD * 2) as u64),
context.field_const((revive_common::BYTE_LENGTH_FIELD * 2) as u64),
"deployer_call_arguments_offset_offset",
)?;
let arguments_offset_pointer = Pointer::new_with_offset(
@@ -168,14 +168,14 @@ where
arguments_offset_pointer,
context.field_const(
(crate::eravm::DEPLOYER_CALL_HEADER_SIZE
- (era_compiler_common::BYTE_LENGTH_X32
+ era_compiler_common::BYTE_LENGTH_FIELD)) as u64,
- (revive_common::BYTE_LENGTH_X32 + revive_common::BYTE_LENGTH_FIELD))
as u64,
),
)?;
let arguments_length_offset = context.builder().build_int_add(
arguments_offset_offset,
context.field_const(era_compiler_common::BYTE_LENGTH_FIELD as u64),
context.field_const(revive_common::BYTE_LENGTH_FIELD as u64),
"deployer_call_arguments_length_offset",
)?;
let arguments_length_pointer = Pointer::new_with_offset(
@@ -262,7 +262,7 @@ where
&[
context.field_const(0),
context
.integer_type(era_compiler_common::BIT_LENGTH_X32)
.integer_type(revive_common::BIT_LENGTH_X32)
.const_zero(),
],
context
@@ -279,7 +279,7 @@ where
&[
context.field_const(0),
context
.integer_type(era_compiler_common::BIT_LENGTH_X32)
.integer_type(revive_common::BIT_LENGTH_X32)
.const_int(1, false),
],
context.bool_type().as_basic_type_enum(),
+22 -16
View File
@@ -222,7 +222,7 @@ where
pub fn build(
mut self,
contract_path: &str,
metadata_hash: Option<[u8; era_compiler_common::BYTE_LENGTH_FIELD]>,
metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_FIELD]>,
) -> anyhow::Result<Build> {
let module_clone = self.module.clone();
@@ -645,7 +645,7 @@ where
self.basic_block()
.get_last_instruction()
.expect("Always exists")
.set_alignment(era_compiler_common::BYTE_LENGTH_FIELD as u32)
.set_alignment(revive_common::BYTE_LENGTH_FIELD as u32)
.expect("Alignment is valid");
Pointer::new(r#type, AddressSpace::Stack, pointer)
}
@@ -681,7 +681,7 @@ where
self.basic_block()
.get_last_instruction()
.expect("Always exists")
.set_alignment(era_compiler_common::BYTE_LENGTH_BYTE as u32)
.set_alignment(revive_common::BYTE_LENGTH_BYTE as u32)
.expect("Alignment is valid");
Ok(self.build_byte_swap(value))
@@ -720,7 +720,7 @@ where
.build_store(storage_key_pointer.value, storage_key_value)?;
self.builder().build_store(
storage_value_length_pointer.value,
self.integer_const(32, era_compiler_common::BIT_LENGTH_FIELD as u64),
self.integer_const(32, revive_common::BIT_LENGTH_FIELD as u64),
)?;
let runtime_api = self
@@ -757,7 +757,7 @@ where
self.basic_block()
.get_last_instruction()
.expect("Always exists")
.set_alignment(era_compiler_common::BYTE_LENGTH_FIELD as u32)
.set_alignment(revive_common::BYTE_LENGTH_FIELD as u32)
.expect("Alignment is valid");
Ok(value)
@@ -793,7 +793,7 @@ where
self.builder
.build_store(heap_pointer.value, value)?
.set_alignment(era_compiler_common::BYTE_LENGTH_BYTE as u32)
.set_alignment(revive_common::BYTE_LENGTH_BYTE as u32)
.expect("Alignment is valid");
}
AddressSpace::TransientStorage => todo!(),
@@ -851,7 +851,7 @@ where
AddressSpace::Stack => {
let instruction = self.builder.build_store(pointer.value, value).unwrap();
instruction
.set_alignment(era_compiler_common::BYTE_LENGTH_FIELD as u32)
.set_alignment(revive_common::BYTE_LENGTH_FIELD as u32)
.expect("Alignment is valid");
}
};
@@ -993,7 +993,7 @@ where
self.byte_type()
.ptr_type(AddressSpace::Stack.into())
.as_basic_type_enum(),
self.integer_type(era_compiler_common::BIT_LENGTH_X32)
self.integer_type(revive_common::BIT_LENGTH_X32)
.as_basic_type_enum(),
]);
self.builder
@@ -1104,7 +1104,7 @@ where
)?;
let return_data_size_shifted = self.builder.build_right_shift(
pointer_casted,
self.field_const((era_compiler_common::BIT_LENGTH_X32 * 3) as u64),
self.field_const((revive_common::BIT_LENGTH_X32 * 3) as u64),
false,
format!("{name}_return_data_size_shifted").as_str(),
)?;
@@ -1360,7 +1360,7 @@ where
.builder()
.build_right_shift(
abi_pointer_value,
self.field_const((era_compiler_common::BIT_LENGTH_X32 * 3) as u64),
self.field_const((revive_common::BIT_LENGTH_X32 * 3) as u64),
false,
"abi_pointer_value_shifted",
)
@@ -1450,7 +1450,7 @@ where
///
pub fn byte_type(&self) -> inkwell::types::IntType<'ctx> {
self.llvm
.custom_width_int_type(era_compiler_common::BIT_LENGTH_BYTE as u32)
.custom_width_int_type(revive_common::BIT_LENGTH_BYTE as u32)
}
///
@@ -1460,12 +1460,18 @@ where
self.llvm.custom_width_int_type(bit_length as u32)
}
/// Returns the register witdh sized type.
pub fn xlen_type(&self) -> inkwell::types::IntType<'ctx> {
self.llvm
.custom_width_int_type(revive_common::BIT_LENGTH_X32 as u32)
}
///
/// Returns the default field type.
///
pub fn field_type(&self) -> inkwell::types::IntType<'ctx> {
self.llvm
.custom_width_int_type(era_compiler_common::BIT_LENGTH_FIELD as u32)
.custom_width_int_type(revive_common::BIT_LENGTH_FIELD as u32)
}
///
@@ -1543,7 +1549,7 @@ where
if argument.is_pointer_value() {
call_site_value.set_alignment_attribute(
inkwell::attributes::AttributeLoc::Param(index as u32),
era_compiler_common::BYTE_LENGTH_FIELD as u32,
revive_common::BYTE_LENGTH_FIELD as u32,
);
call_site_value.add_attribute(
inkwell::attributes::AttributeLoc::Param(index as u32),
@@ -1593,14 +1599,14 @@ where
inkwell::attributes::AttributeLoc::Param(index as u32),
self.llvm.create_enum_attribute(
Attribute::Dereferenceable as u32,
(era_compiler_common::BIT_LENGTH_FIELD * 2) as u64,
(revive_common::BIT_LENGTH_FIELD * 2) as u64,
),
);
call_site_value.add_attribute(
inkwell::attributes::AttributeLoc::Return,
self.llvm.create_enum_attribute(
Attribute::Dereferenceable as u32,
(era_compiler_common::BIT_LENGTH_FIELD * 2) as u64,
(revive_common::BIT_LENGTH_FIELD * 2) as u64,
),
);
}
@@ -1625,7 +1631,7 @@ where
{
call_site_value.set_alignment_attribute(
inkwell::attributes::AttributeLoc::Return,
era_compiler_common::BYTE_LENGTH_FIELD as u32,
revive_common::BYTE_LENGTH_FIELD as u32,
);
call_site_value.add_attribute(
inkwell::attributes::AttributeLoc::Return,
@@ -28,7 +28,7 @@ impl SolidityData {
/// Returns the current number of immutables values in the contract.
///
pub fn immutables_size(&self) -> usize {
self.immutables.len() * era_compiler_common::BYTE_LENGTH_FIELD
self.immutables.len() * revive_common::BYTE_LENGTH_FIELD
}
///
@@ -38,7 +38,7 @@ impl SolidityData {
///
pub fn allocate_immutable(&mut self, identifier: &str) -> usize {
let number_of_elements = self.immutables.len();
let new_offset = number_of_elements * era_compiler_common::BYTE_LENGTH_FIELD;
let new_offset = number_of_elements * revive_common::BYTE_LENGTH_FIELD;
*self
.immutables
.entry(identifier.to_owned())
+4 -4
View File
@@ -77,7 +77,7 @@ where
let condition_is_overflow = context.builder().build_int_compare(
inkwell::IntPredicate::UGT,
shift,
context.field_const((era_compiler_common::BIT_LENGTH_FIELD - 1) as u64),
context.field_const((revive_common::BIT_LENGTH_FIELD - 1) as u64),
"shift_left_is_overflow",
)?;
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
@@ -117,7 +117,7 @@ where
let condition_is_overflow = context.builder().build_int_compare(
inkwell::IntPredicate::UGT,
shift,
context.field_const((era_compiler_common::BIT_LENGTH_FIELD - 1) as u64),
context.field_const((revive_common::BIT_LENGTH_FIELD - 1) as u64),
"shift_right_is_overflow",
)?;
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
@@ -166,7 +166,7 @@ where
let condition_is_overflow = context.builder().build_int_compare(
inkwell::IntPredicate::UGT,
shift,
context.field_const((era_compiler_common::BIT_LENGTH_FIELD - 1) as u64),
context.field_const((revive_common::BIT_LENGTH_FIELD - 1) as u64),
"shift_right_arithmetic_is_overflow",
)?;
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
@@ -174,7 +174,7 @@ where
context.set_basic_block(overflow_block);
let sign_bit = context.builder().build_right_shift(
value,
context.field_const((era_compiler_common::BIT_LENGTH_FIELD - 1) as u64),
context.field_const((revive_common::BIT_LENGTH_FIELD - 1) as u64),
false,
"shift_right_arithmetic_sign_bit",
)?;
+36 -36
View File
@@ -44,7 +44,7 @@ where
.and_then(|value| value.to_u16());
match simulation_address {
Some(era_compiler_common::ERAVM_ADDRESS_TO_L1) => {
Some(revive_common::ERAVM_ADDRESS_TO_L1) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().far_call,
function,
@@ -57,7 +57,7 @@ where
return crate::eravm::extensions::general::to_l1(context, is_first, in_0, in_1);
}
Some(era_compiler_common::ERAVM_ADDRESS_CODE_ADDRESS) => {
Some(revive_common::ERAVM_ADDRESS_CODE_ADDRESS) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().static_call,
function,
@@ -66,7 +66,7 @@ where
return crate::eravm::extensions::general::code_source(context);
}
Some(era_compiler_common::ERAVM_ADDRESS_PRECOMPILE) => {
Some(revive_common::ERAVM_ADDRESS_PRECOMPILE) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().static_call,
function,
@@ -78,7 +78,7 @@ where
return crate::eravm::extensions::general::precompile(context, in_0, gas_left);
}
Some(era_compiler_common::ERAVM_ADDRESS_META) => {
Some(revive_common::ERAVM_ADDRESS_META) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().static_call,
function,
@@ -87,7 +87,7 @@ where
return crate::eravm::extensions::general::meta(context);
}
Some(era_compiler_common::ERAVM_ADDRESS_MIMIC_CALL) => {
Some(revive_common::ERAVM_ADDRESS_MIMIC_CALL) => {
let address = gas;
let abi_data = input_offset;
let mimic = input_length;
@@ -101,7 +101,7 @@ where
vec![],
);
}
Some(era_compiler_common::ERAVM_ADDRESS_SYSTEM_MIMIC_CALL) => {
Some(revive_common::ERAVM_ADDRESS_SYSTEM_MIMIC_CALL) => {
let address = gas;
let abi_data = input_offset;
let mimic = input_length;
@@ -117,7 +117,7 @@ where
vec![extra_value_1, extra_value_2],
);
}
Some(era_compiler_common::ERAVM_ADDRESS_MIMIC_CALL_BYREF) => {
Some(revive_common::ERAVM_ADDRESS_MIMIC_CALL_BYREF) => {
let address = gas;
let mimic = input_length;
let abi_data = context.get_global_value(crate::eravm::GLOBAL_ACTIVE_POINTER)?;
@@ -131,7 +131,7 @@ where
vec![],
);
}
Some(era_compiler_common::ERAVM_ADDRESS_SYSTEM_MIMIC_CALL_BYREF) => {
Some(revive_common::ERAVM_ADDRESS_SYSTEM_MIMIC_CALL_BYREF) => {
let address = gas;
let mimic = input_length;
let abi_data = context.get_global_value(crate::eravm::GLOBAL_ACTIVE_POINTER)?;
@@ -147,7 +147,7 @@ where
vec![extra_value_1, extra_value_2],
);
}
Some(era_compiler_common::ERAVM_ADDRESS_RAW_FAR_CALL) => {
Some(revive_common::ERAVM_ADDRESS_RAW_FAR_CALL) => {
let address = gas;
let abi_data = input_length;
@@ -160,7 +160,7 @@ where
output_length,
);
}
Some(era_compiler_common::ERAVM_ADDRESS_RAW_FAR_CALL_BYREF) => {
Some(revive_common::ERAVM_ADDRESS_RAW_FAR_CALL_BYREF) => {
let address = gas;
let abi_data = context.get_global_value(crate::eravm::GLOBAL_ACTIVE_POINTER)?;
@@ -173,7 +173,7 @@ where
output_length,
);
}
Some(era_compiler_common::ERAVM_ADDRESS_SYSTEM_CALL) => {
Some(revive_common::ERAVM_ADDRESS_SYSTEM_CALL) => {
let address = gas;
let abi_data = input_length;
let extra_value_1 = value.expect("Always exists");
@@ -191,7 +191,7 @@ where
vec![extra_value_1, extra_value_2, extra_value_3, extra_value_4],
);
}
Some(era_compiler_common::ERAVM_ADDRESS_SYSTEM_CALL_BYREF) => {
Some(revive_common::ERAVM_ADDRESS_SYSTEM_CALL_BYREF) => {
let address = gas;
let abi_data = context.get_global_value(crate::eravm::GLOBAL_ACTIVE_POINTER)?;
let extra_value_1 = value.expect("Always exists");
@@ -209,7 +209,7 @@ where
vec![extra_value_1, extra_value_2, extra_value_3, extra_value_4],
);
}
Some(era_compiler_common::ERAVM_ADDRESS_SET_CONTEXT_VALUE_CALL) => {
Some(revive_common::ERAVM_ADDRESS_SET_CONTEXT_VALUE_CALL) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().far_call,
function,
@@ -220,7 +220,7 @@ where
return crate::eravm::extensions::general::set_context_value(context, value);
}
Some(era_compiler_common::ERAVM_ADDRESS_SET_PUBDATA_PRICE) => {
Some(revive_common::ERAVM_ADDRESS_SET_PUBDATA_PRICE) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().far_call,
function,
@@ -231,7 +231,7 @@ where
return crate::eravm::extensions::general::set_pubdata_price(context, price);
}
Some(era_compiler_common::ERAVM_ADDRESS_INCREMENT_TX_COUNTER) => {
Some(revive_common::ERAVM_ADDRESS_INCREMENT_TX_COUNTER) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().far_call,
function,
@@ -240,7 +240,7 @@ where
return crate::eravm::extensions::general::increment_tx_counter(context);
}
Some(era_compiler_common::ERAVM_ADDRESS_GET_GLOBAL_PTR_CALLDATA) => {
Some(revive_common::ERAVM_ADDRESS_GET_GLOBAL_PTR_CALLDATA) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().static_call,
function,
@@ -255,7 +255,7 @@ where
)?;
return Ok(value.as_basic_value_enum());
}
Some(era_compiler_common::ERAVM_ADDRESS_GET_GLOBAL_CALL_FLAGS) => {
Some(revive_common::ERAVM_ADDRESS_GET_GLOBAL_CALL_FLAGS) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().static_call,
function,
@@ -264,7 +264,7 @@ where
return context.get_global_value(crate::eravm::GLOBAL_CALL_FLAGS);
}
Some(era_compiler_common::ERAVM_ADDRESS_GET_GLOBAL_PTR_RETURN_DATA) => {
Some(revive_common::ERAVM_ADDRESS_GET_GLOBAL_PTR_RETURN_DATA) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().static_call,
function,
@@ -279,7 +279,7 @@ where
)?;
return Ok(value.as_basic_value_enum());
}
Some(era_compiler_common::ERAVM_ADDRESS_EVENT_INITIALIZE) => {
Some(revive_common::ERAVM_ADDRESS_EVENT_INITIALIZE) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().far_call,
function,
@@ -293,7 +293,7 @@ where
context, operand_1, operand_2, true,
);
}
Some(era_compiler_common::ERAVM_ADDRESS_EVENT_WRITE) => {
Some(revive_common::ERAVM_ADDRESS_EVENT_WRITE) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().far_call,
function,
@@ -307,7 +307,7 @@ where
context, operand_1, operand_2, false,
);
}
Some(era_compiler_common::ERAVM_ADDRESS_ACTIVE_PTR_LOAD_CALLDATA) => {
Some(revive_common::ERAVM_ADDRESS_ACTIVE_PTR_LOAD_CALLDATA) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().static_call,
function,
@@ -316,7 +316,7 @@ where
return crate::eravm::extensions::abi::calldata_ptr_to_active(context);
}
Some(era_compiler_common::ERAVM_ADDRESS_ACTIVE_PTR_LOAD_RETURN_DATA) => {
Some(revive_common::ERAVM_ADDRESS_ACTIVE_PTR_LOAD_RETURN_DATA) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().static_call,
function,
@@ -325,7 +325,7 @@ where
return crate::eravm::extensions::abi::return_data_ptr_to_active(context);
}
Some(era_compiler_common::ERAVM_ADDRESS_ACTIVE_PTR_ADD) => {
Some(revive_common::ERAVM_ADDRESS_ACTIVE_PTR_ADD) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().static_call,
function,
@@ -336,7 +336,7 @@ where
return crate::eravm::extensions::abi::active_ptr_add_assign(context, offset);
}
Some(era_compiler_common::ERAVM_ADDRESS_ACTIVE_PTR_SHRINK) => {
Some(revive_common::ERAVM_ADDRESS_ACTIVE_PTR_SHRINK) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().static_call,
function,
@@ -347,7 +347,7 @@ where
return crate::eravm::extensions::abi::active_ptr_shrink_assign(context, offset);
}
Some(era_compiler_common::ERAVM_ADDRESS_ACTIVE_PTR_PACK) => {
Some(revive_common::ERAVM_ADDRESS_ACTIVE_PTR_PACK) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().static_call,
function,
@@ -358,7 +358,7 @@ where
return crate::eravm::extensions::abi::active_ptr_pack_assign(context, data);
}
Some(era_compiler_common::ERAVM_ADDRESS_MULTIPLICATION_HIGH_REGISTER) => {
Some(revive_common::ERAVM_ADDRESS_MULTIPLICATION_HIGH_REGISTER) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().static_call,
function,
@@ -372,7 +372,7 @@ where
context, operand_1, operand_2,
);
}
Some(era_compiler_common::ERAVM_ADDRESS_GET_GLOBAL_EXTRA_ABI_DATA) => {
Some(revive_common::ERAVM_ADDRESS_GET_GLOBAL_EXTRA_ABI_DATA) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().static_call,
function,
@@ -383,7 +383,7 @@ where
return crate::eravm::extensions::abi::get_extra_abi_data(context, index);
}
Some(era_compiler_common::ERAVM_ADDRESS_ACTIVE_PTR_DATA_LOAD) => {
Some(revive_common::ERAVM_ADDRESS_ACTIVE_PTR_DATA_LOAD) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().static_call,
function,
@@ -394,7 +394,7 @@ where
return crate::eravm::extensions::abi::active_ptr_data_load(context, offset);
}
Some(era_compiler_common::ERAVM_ADDRESS_ACTIVE_PTR_DATA_SIZE) => {
Some(revive_common::ERAVM_ADDRESS_ACTIVE_PTR_DATA_SIZE) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().static_call,
function,
@@ -403,7 +403,7 @@ where
return crate::eravm::extensions::abi::active_ptr_data_size(context);
}
Some(era_compiler_common::ERAVM_ADDRESS_ACTIVE_PTR_DATA_COPY) => {
Some(revive_common::ERAVM_ADDRESS_ACTIVE_PTR_DATA_COPY) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().static_call,
function,
@@ -421,7 +421,7 @@ where
size,
);
}
Some(era_compiler_common::ERAVM_ADDRESS_CONST_ARRAY_DECLARE) => {
Some(revive_common::ERAVM_ADDRESS_CONST_ARRAY_DECLARE) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().static_call,
function,
@@ -443,7 +443,7 @@ where
return crate::eravm::extensions::const_array::declare(context, index, size);
}
Some(era_compiler_common::ERAVM_ADDRESS_CONST_ARRAY_SET) => {
Some(revive_common::ERAVM_ADDRESS_CONST_ARRAY_SET) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().static_call,
function,
@@ -469,7 +469,7 @@ where
return crate::eravm::extensions::const_array::set(context, index, offset, value);
}
Some(era_compiler_common::ERAVM_ADDRESS_CONST_ARRAY_FINALIZE) => {
Some(revive_common::ERAVM_ADDRESS_CONST_ARRAY_FINALIZE) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().static_call,
function,
@@ -485,7 +485,7 @@ where
return crate::eravm::extensions::const_array::finalize(context, index);
}
Some(era_compiler_common::ERAVM_ADDRESS_CONST_ARRAY_GET) => {
Some(revive_common::ERAVM_ADDRESS_CONST_ARRAY_GET) => {
crate::eravm::extensions::call::validate_call_type(
context.llvm_runtime().static_call,
function,
@@ -604,8 +604,8 @@ where
let signature_value = context.field_const_str_hex(signature_hash.as_str());
let calldata_size = context.field_const(
(era_compiler_common::BYTE_LENGTH_X32
+ (era_compiler_common::BYTE_LENGTH_FIELD * arguments.len())) as u64,
(revive_common::BYTE_LENGTH_X32 + (revive_common::BYTE_LENGTH_FIELD * arguments.len()))
as u64,
);
let calldata_array_pointer = context.build_alloca(
@@ -35,7 +35,7 @@ where
index_double,
context.field_const(
crate::eravm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA
+ (3 * era_compiler_common::BYTE_LENGTH_FIELD) as u64,
+ (3 * revive_common::BYTE_LENGTH_FIELD) as u64,
),
"immutable_offset_absolute",
)?;
@@ -84,7 +84,7 @@ where
index_double,
context.field_const(
crate::eravm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA
+ (2 * era_compiler_common::BYTE_LENGTH_FIELD) as u64,
+ (2 * revive_common::BYTE_LENGTH_FIELD) as u64,
),
"index_offset_absolute",
)?;
@@ -99,7 +99,7 @@ where
let value_offset_absolute = context.builder().build_int_add(
index_offset_absolute,
context.field_const(era_compiler_common::BYTE_LENGTH_FIELD as u64),
context.field_const(revive_common::BYTE_LENGTH_FIELD as u64),
"value_offset_absolute",
)?;
let value_offset_pointer = Pointer::new_with_offset(
+5 -6
View File
@@ -35,7 +35,7 @@ where
);
context.build_store(
immutables_offset_pointer,
context.field_const(era_compiler_common::BYTE_LENGTH_FIELD as u64),
context.field_const(revive_common::BYTE_LENGTH_FIELD as u64),
)?;
let immutables_number_pointer = Pointer::new_with_offset(
@@ -44,16 +44,15 @@ where
context.field_type(),
context.field_const(
crate::eravm::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA
+ (era_compiler_common::BYTE_LENGTH_FIELD as u64),
+ (revive_common::BYTE_LENGTH_FIELD as u64),
),
"immutables_number_pointer",
);
let immutable_values_size = context.immutables_size()?;
context.build_store(
immutables_number_pointer,
context.field_const(
(immutable_values_size / era_compiler_common::BYTE_LENGTH_FIELD) as u64,
),
context
.field_const((immutable_values_size / revive_common::BYTE_LENGTH_FIELD) as u64),
)?;
let immutables_size = context.builder().build_int_mul(
context.field_const(immutable_values_size as u64),
@@ -62,7 +61,7 @@ where
)?;
let return_data_length = context.builder().build_int_add(
immutables_size,
context.field_const((era_compiler_common::BYTE_LENGTH_FIELD * 2) as u64),
context.field_const((revive_common::BYTE_LENGTH_FIELD * 2) as u64),
"return_data_length",
)?;
@@ -169,7 +169,7 @@ where
)?;
let active_pointer_value_shifted = context.builder().build_right_shift(
active_pointer_value,
context.field_const((era_compiler_common::BIT_LENGTH_X32 * 3) as u64),
context.field_const((revive_common::BIT_LENGTH_X32 * 3) as u64),
false,
"active_pointer_value_shifted",
)?;
@@ -20,12 +20,12 @@ where
{
let operand_1_extended = context.builder().build_int_z_extend_or_bit_cast(
operand_1,
context.integer_type(era_compiler_common::BIT_LENGTH_FIELD * 2),
context.integer_type(revive_common::BIT_LENGTH_FIELD * 2),
"multiplication_512_operand_1_extended",
)?;
let operand_2_extended = context.builder().build_int_z_extend_or_bit_cast(
operand_2,
context.integer_type(era_compiler_common::BIT_LENGTH_FIELD * 2),
context.integer_type(revive_common::BIT_LENGTH_FIELD * 2),
"multiplication_512_operand_2_extended",
)?;
let result_extended = context.builder().build_int_mul(
@@ -36,8 +36,8 @@ where
let result_shifted = context.builder().build_right_shift(
result_extended,
context.integer_const(
era_compiler_common::BIT_LENGTH_FIELD * 2,
era_compiler_common::BIT_LENGTH_FIELD as u64,
revive_common::BIT_LENGTH_FIELD * 2,
revive_common::BIT_LENGTH_FIELD as u64,
),
false,
"multiplication_512_result_shifted",
+1 -1
View File
@@ -30,7 +30,7 @@ pub fn initialize_target() {
pub fn build_assembly_text(
contract_path: &str,
assembly_text: &str,
_metadata_hash: Option<[u8; era_compiler_common::BYTE_LENGTH_FIELD]>,
_metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_FIELD]>,
debug_config: Option<&DebugConfig>,
) -> anyhow::Result<Build> {
if let Some(debug_config) = debug_config {
+5 -6
View File
@@ -138,17 +138,17 @@ where
let input_offset_shifted = context.builder().build_left_shift(
input_offset,
context.field_const((era_compiler_common::BIT_LENGTH_X32 * 2) as u64),
context.field_const((revive_common::BIT_LENGTH_X32 * 2) as u64),
"abi_data_input_offset_shifted",
)?;
let input_length_shifted = context.builder().build_left_shift(
input_length,
context.field_const((era_compiler_common::BIT_LENGTH_X32 * 3) as u64),
context.field_const((revive_common::BIT_LENGTH_X32 * 3) as u64),
"abi_data_input_length_shifted",
)?;
let gas_shifted = context.builder().build_left_shift(
gas,
context.field_const((era_compiler_common::BIT_LENGTH_X32 * 6) as u64),
context.field_const((revive_common::BIT_LENGTH_X32 * 6) as u64),
"abi_data_gas_shifted",
)?;
@@ -163,7 +163,7 @@ where
if let AddressSpace::HeapAuxiliary = address_space {
let auxiliary_heap_marker_shifted = context.builder().build_left_shift(
context.field_const(zkevm_opcode_defs::FarCallForwardPageType::UseAuxHeap as u64),
context.field_const((era_compiler_common::BIT_LENGTH_X32 * 7) as u64),
context.field_const((revive_common::BIT_LENGTH_X32 * 7) as u64),
"abi_data_auxiliary_heap_marker_shifted",
)?;
abi_data = context.builder().build_int_add(
@@ -176,8 +176,7 @@ where
let auxiliary_heap_marker_shifted = context.builder().build_left_shift(
context.field_const(zkevm_opcode_defs::FarCallForwardPageType::UseAuxHeap as u64),
context.field_const(
((era_compiler_common::BIT_LENGTH_X32 * 7)
+ (era_compiler_common::BIT_LENGTH_BYTE * 3)) as u64,
((revive_common::BIT_LENGTH_X32 * 7) + (revive_common::BIT_LENGTH_BYTE * 3)) as u64,
),
"abi_data_system_call_marker_shifted",
)?;
+1 -1
View File
@@ -37,7 +37,7 @@ sha3 = { workspace = true }
md5 = { workspace = true }
inkwell = { workspace = true }
era-compiler-common = { git = "https://github.com/matter-labs/era-compiler-common", branch = "main" }
revive-common = { path = "../common" }
era-compiler-llvm-context = { path = "../llvm-context" }
+2 -10
View File
@@ -63,11 +63,7 @@ impl Contract {
let file_name = Self::short_path(self.path.as_str());
if output_assembly {
let file_name = format!(
"{}.{}",
file_name,
era_compiler_common::EXTENSION_ERAVM_ASSEMBLY
);
let file_name = format!("{}.{}", file_name, revive_common::EXTENSION_ERAVM_ASSEMBLY);
let mut file_path = path.to_owned();
file_path.push(file_name);
@@ -88,11 +84,7 @@ impl Contract {
}
if output_binary {
let file_name = format!(
"{}.{}",
file_name,
era_compiler_common::EXTENSION_ERAVM_BINARY
);
let file_name = format!("{}.{}", file_name, revive_common::EXTENSION_ERAVM_BINARY);
let mut file_path = path.to_owned();
file_path.push(file_name);
+3 -3
View File
@@ -11,10 +11,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 * era_compiler_common::BYTE_LENGTH_FIELD;
pub const OFFSET_MEMORY_POINTER: usize = 2 * revive_common::BYTE_LENGTH_FIELD;
/// The empty slot offset.
pub const OFFSET_EMPTY_SLOT: usize = 3 * era_compiler_common::BYTE_LENGTH_FIELD;
pub const OFFSET_EMPTY_SLOT: usize = 3 * revive_common::BYTE_LENGTH_FIELD;
/// The non-reserved memory offset.
pub const OFFSET_NON_RESERVED: usize = 4 * era_compiler_common::BYTE_LENGTH_FIELD;
pub const OFFSET_NON_RESERVED: usize = 4 * revive_common::BYTE_LENGTH_FIELD;
@@ -16,7 +16,7 @@ where
let offset = context.builder().build_int_add(
offset,
context.field_const(
(era_compiler_common::BYTE_LENGTH_X32 + era_compiler_common::BYTE_LENGTH_FIELD) as u64,
(revive_common::BYTE_LENGTH_X32 + revive_common::BYTE_LENGTH_FIELD) as u64,
),
"datacopy_contract_hash_offset",
)?;
@@ -61,12 +61,12 @@ where
for (index, chunk) in source
.chars()
.collect::<Vec<char>>()
.chunks(era_compiler_common::BYTE_LENGTH_FIELD * 2)
.chunks(revive_common::BYTE_LENGTH_FIELD * 2)
.enumerate()
{
let mut value_string = chunk.iter().collect::<String>();
value_string.push_str(
"0".repeat((era_compiler_common::BYTE_LENGTH_FIELD * 2) - chunk.len())
"0".repeat((revive_common::BYTE_LENGTH_FIELD * 2) - chunk.len())
.as_str(),
);
@@ -309,7 +309,7 @@ impl Instruction {
..
} => {
let mut key_extended =
"0".repeat(era_compiler_common::BYTE_LENGTH_FIELD * 2 - value.len());
"0".repeat(revive_common::BYTE_LENGTH_FIELD * 2 - value.len());
key_extended.push_str(value.as_str());
*value = mapping.get(key_extended.as_str()).cloned().ok_or_else(|| {
+4 -6
View File
@@ -103,7 +103,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(era_compiler_common::BYTE_LENGTH_FIELD * 2);
let index = "0".repeat(revive_common::BYTE_LENGTH_FIELD * 2);
index_path_mapping.insert(index, full_path.to_owned());
let dependencies = match self.data.as_mut() {
@@ -115,8 +115,7 @@ impl Assembly {
continue;
}
let mut index_extended =
"0".repeat(era_compiler_common::BYTE_LENGTH_FIELD * 2 - index.len());
let mut index_extended = "0".repeat(revive_common::BYTE_LENGTH_FIELD * 2 - index.len());
index_extended.push_str(index.as_str());
*data = match data {
@@ -154,7 +153,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(era_compiler_common::BYTE_LENGTH_FIELD * 2);
let index = "0".repeat(revive_common::BYTE_LENGTH_FIELD * 2);
index_path_mapping.insert(index, full_path.to_owned());
let dependencies = match self
@@ -168,8 +167,7 @@ impl Assembly {
None => return Ok(index_path_mapping),
};
for (index, data) in dependencies.iter_mut() {
let mut index_extended =
"0".repeat(era_compiler_common::BYTE_LENGTH_FIELD * 2 - index.len());
let mut index_extended = "0".repeat(revive_common::BYTE_LENGTH_FIELD * 2 - index.len());
index_extended.push_str(index.as_str());
*data = match data {
@@ -41,10 +41,10 @@ where
.declaration();
let is_deploy_code = match self.code_type {
era_compiler_llvm_context::EraVMCodeType::Deploy => context
.integer_type(era_compiler_common::BIT_LENGTH_BOOLEAN)
.integer_type(revive_common::BIT_LENGTH_BOOLEAN)
.const_int(1, false),
era_compiler_llvm_context::EraVMCodeType::Runtime => context
.integer_type(era_compiler_common::BIT_LENGTH_BOOLEAN)
.integer_type(revive_common::BIT_LENGTH_BOOLEAN)
.const_int(0, false),
};
context.build_invoke(
@@ -170,7 +170,7 @@ where
.value
.ok_or_else(|| anyhow::anyhow!("Instruction value missing"))?;
if value.len() > era_compiler_common::BYTE_LENGTH_FIELD * 2 {
if value.len() > revive_common::BYTE_LENGTH_FIELD * 2 {
Ok(Some(context.field_const(0).as_basic_value_enum()))
} else {
crate::evmla::assembly::instruction::stack::push(context, value).map(Some)
@@ -1319,10 +1319,8 @@ where
pointer,
&[
context.field_const(0),
context.integer_const(
era_compiler_common::BIT_LENGTH_X32,
index as u64,
),
context
.integer_const(revive_common::BIT_LENGTH_X32, index as u64),
],
context.field_type(),
format!("return_value_pointer_element_{}", index).as_str(),
@@ -593,7 +593,7 @@ impl Function {
} => (
vec![num::BigUint::from_str_radix(
constant.as_str(),
era_compiler_common::BASE_HEXADECIMAL,
revive_common::BASE_HEXADECIMAL,
)
.map(StackElement::Constant)?],
None,
@@ -784,7 +784,7 @@ impl Function {
let result = match (&operands[0], &operands[1]) {
(Element::Tag(tag), Element::Constant(offset)) => {
let offset = offset % era_compiler_common::BIT_LENGTH_FIELD;
let offset = offset % revive_common::BIT_LENGTH_FIELD;
let offset = offset.to_u64().expect("Always valid");
let result = tag << offset;
if Self::is_tag_value_valid(blocks, &result) {
@@ -794,7 +794,7 @@ impl Function {
}
}
(Element::Constant(constant), Element::Constant(offset)) => {
let offset = offset % era_compiler_common::BIT_LENGTH_FIELD;
let offset = offset % revive_common::BIT_LENGTH_FIELD;
let offset = offset.to_u64().expect("Always valid");
Element::Constant(constant << offset)
}
@@ -811,7 +811,7 @@ impl Function {
let result = match (&operands[0], &operands[1]) {
(Element::Tag(tag), Element::Constant(offset)) => {
let offset = offset % era_compiler_common::BIT_LENGTH_FIELD;
let offset = offset % revive_common::BIT_LENGTH_FIELD;
let offset = offset.to_u64().expect("Always valid");
let result = tag >> offset;
if Self::is_tag_value_valid(blocks, &result) {
@@ -821,7 +821,7 @@ impl Function {
}
}
(Element::Constant(constant), Element::Constant(offset)) => {
let offset = offset % era_compiler_common::BIT_LENGTH_FIELD;
let offset = offset % revive_common::BIT_LENGTH_FIELD;
let offset = offset.to_u64().expect("Always valid");
Element::Constant(constant >> offset)
}
@@ -1170,7 +1170,7 @@ where
let output_size = 0;
let r#type = context.function_type(
vec![context
.integer_type(era_compiler_common::BIT_LENGTH_BOOLEAN)
.integer_type(revive_common::BIT_LENGTH_BOOLEAN)
.as_basic_type_enum()],
output_size,
false,
@@ -1185,7 +1185,7 @@ where
let r#type = context.function_type(
vec![
context
.integer_type(era_compiler_common::BIT_LENGTH_FIELD)
.integer_type(revive_common::BIT_LENGTH_FIELD)
.as_basic_type_enum();
input_size
],
+2 -2
View File
@@ -165,7 +165,7 @@ pub fn standard_output(
input_files: &[PathBuf],
libraries: Vec<String>,
solc: &mut SolcCompiler,
evm_version: Option<era_compiler_common::EVMVersion>,
evm_version: Option<revive_common::EVMVersion>,
solc_optimizer_enabled: bool,
optimizer_settings: era_compiler_llvm_context::OptimizerSettings,
force_evmla: bool,
@@ -341,7 +341,7 @@ pub fn combined_json(
input_files: &[PathBuf],
libraries: Vec<String>,
solc: &mut SolcCompiler,
evm_version: Option<era_compiler_common::EVMVersion>,
evm_version: Option<revive_common::EVMVersion>,
solc_optimizer_enabled: bool,
optimizer_settings: era_compiler_llvm_context::OptimizerSettings,
force_evmla: bool,
+3 -3
View File
@@ -29,7 +29,7 @@ pub fn run() -> anyhow::Result<()> {
let mut buffer = Vec::with_capacity(16384);
stdin.read_to_end(&mut buffer).expect("Stdin reading error");
let input: Input = era_compiler_common::deserialize_from_slice(buffer.as_slice())?;
let input: Input = revive_common::deserialize_from_slice(buffer.as_slice())?;
if input.enable_test_encoding {
todo!()
}
@@ -96,8 +96,8 @@ pub fn call(input: Input) -> anyhow::Result<Output> {
);
}
let output: Output = era_compiler_common::deserialize_from_slice(output.stdout.as_slice())
.map_err(|error| {
let output: Output =
revive_common::deserialize_from_slice(output.stdout.as_slice()).map_err(|error| {
anyhow::anyhow!(
"{:?} subprocess output parsing error: {}",
executable,
+8 -8
View File
@@ -39,7 +39,7 @@ impl Contract {
///
pub fn new(
path: String,
source_hash: [u8; era_compiler_common::BYTE_LENGTH_FIELD],
source_hash: [u8; revive_common::BYTE_LENGTH_FIELD],
source_version: SolcVersion,
ir: IR,
metadata_json: Option<serde_json::Value>,
@@ -110,13 +110,13 @@ impl Contract {
optimizer.settings().to_owned(),
);
let metadata_json = serde_json::to_value(&metadata).expect("Always valid");
let metadata_hash: Option<[u8; era_compiler_common::BYTE_LENGTH_FIELD]> =
if include_metadata_hash {
let metadata_string = serde_json::to_string(&metadata).expect("Always valid");
Some(sha3::Keccak256::digest(metadata_string.as_bytes()).into())
} else {
None
};
let metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_FIELD]> = if include_metadata_hash
{
let metadata_string = serde_json::to_string(&metadata).expect("Always valid");
Some(sha3::Keccak256::digest(metadata_string.as_bytes()).into())
} else {
None
};
let module = match self.ir {
IR::LLVMIR(ref llvm_ir) => {
@@ -67,7 +67,7 @@ impl Contract {
.find_map(|(contract_entry, hash)| {
if contract_entry.starts_with(entry) {
Some(
u32::from_str_radix(hash.as_str(), era_compiler_common::BASE_HEXADECIMAL)
u32::from_str_radix(hash.as_str(), revive_common::BASE_HEXADECIMAL)
.expect("Test hash is always valid"),
)
} else {
@@ -89,7 +89,7 @@ impl CombinedJson {
overwrite: bool,
) -> anyhow::Result<()> {
let mut file_path = output_directory.to_owned();
file_path.push(format!("combined.{}", era_compiler_common::EXTENSION_JSON));
file_path.push(format!("combined.{}", revive_common::EXTENSION_JSON));
if file_path.exists() && !overwrite {
eprintln!(
+28 -28
View File
@@ -122,21 +122,21 @@ impl Compiler {
);
}
let mut output: StandardJsonOutput = era_compiler_common::deserialize_from_slice(
output.stdout.as_slice(),
)
.map_err(|error| {
anyhow::anyhow!(
"{} subprocess output parsing error: {}\n{}",
self.executable,
error,
era_compiler_common::deserialize_from_slice::<serde_json::Value>(
output.stdout.as_slice()
let mut output: StandardJsonOutput =
revive_common::deserialize_from_slice(output.stdout.as_slice()).map_err(|error| {
anyhow::anyhow!(
"{} subprocess output parsing error: {}\n{}",
self.executable,
error,
revive_common::deserialize_from_slice::<serde_json::Value>(
output.stdout.as_slice()
)
.map(|json| serde_json::to_string_pretty(&json).expect("Always valid"))
.unwrap_or_else(
|_| String::from_utf8_lossy(output.stdout.as_slice()).to_string()
),
)
.map(|json| serde_json::to_string_pretty(&json).expect("Always valid"))
.unwrap_or_else(|_| String::from_utf8_lossy(output.stdout.as_slice()).to_string()),
)
})?;
})?;
output.preprocess_ast(&version, pipeline, suppressed_warnings.as_slice())?;
output.remove_evm();
@@ -183,21 +183,21 @@ impl Compiler {
);
}
let mut combined_json: CombinedJson = era_compiler_common::deserialize_from_slice(
output.stdout.as_slice(),
)
.map_err(|error| {
anyhow::anyhow!(
"{} subprocess output parsing error: {}\n{}",
self.executable,
error,
era_compiler_common::deserialize_from_slice::<serde_json::Value>(
output.stdout.as_slice()
let mut combined_json: CombinedJson =
revive_common::deserialize_from_slice(output.stdout.as_slice()).map_err(|error| {
anyhow::anyhow!(
"{} subprocess output parsing error: {}\n{}",
self.executable,
error,
revive_common::deserialize_from_slice::<serde_json::Value>(
output.stdout.as_slice()
)
.map(|json| serde_json::to_string_pretty(&json).expect("Always valid"))
.unwrap_or_else(
|_| String::from_utf8_lossy(output.stdout.as_slice()).to_string()
),
)
.map(|json| serde_json::to_string_pretty(&json).expect("Always valid"))
.unwrap_or_else(|_| String::from_utf8_lossy(output.stdout.as_slice()).to_string()),
)
})?;
})?;
for filtered_flag in filtered_flags.into_iter() {
for (_path, contract) in combined_json.contracts.iter_mut() {
match filtered_flag {
@@ -62,7 +62,7 @@ impl Input {
#[allow(clippy::too_many_arguments)]
pub fn try_from_paths(
language: Language,
evm_version: Option<era_compiler_common::EVMVersion>,
evm_version: Option<revive_common::EVMVersion>,
paths: &[PathBuf],
library_map: Vec<String>,
remappings: Option<BTreeSet<String>>,
@@ -107,7 +107,7 @@ impl Input {
///
#[allow(clippy::too_many_arguments)]
pub fn try_from_sources(
evm_version: Option<era_compiler_common::EVMVersion>,
evm_version: Option<revive_common::EVMVersion>,
sources: BTreeMap<String, String>,
libraries: BTreeMap<String, BTreeMap<String, String>>,
remappings: Option<BTreeSet<String>>,
@@ -24,7 +24,7 @@ use self::selection::Selection;
pub struct Settings {
/// The target EVM version.
#[serde(skip_serializing_if = "Option::is_none")]
pub evm_version: Option<era_compiler_common::EVMVersion>,
pub evm_version: Option<revive_common::EVMVersion>,
/// The linker library addresses.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub libraries: Option<BTreeMap<String, BTreeMap<String, String>>>,
@@ -53,7 +53,7 @@ impl Settings {
/// A shortcut constructor.
///
pub fn new(
evm_version: Option<era_compiler_common::EVMVersion>,
evm_version: Option<revive_common::EVMVersion>,
libraries: BTreeMap<String, BTreeMap<String, String>>,
remappings: Option<BTreeSet<String>>,
output_selection: Selection,
@@ -83,7 +83,7 @@ impl Integer {
/// Checks whether the character can continue a decimal number.
///
pub fn can_continue_decimal(character: char) -> bool {
character.is_digit(era_compiler_common::BASE_DECIMAL)
character.is_digit(revive_common::BASE_DECIMAL)
}
///
@@ -97,7 +97,7 @@ impl Integer {
/// Checks whether the character can continue a hexadecimal number.
///
pub fn can_continue_hexadecimal(character: char) -> bool {
character.is_digit(era_compiler_common::BASE_HEXADECIMAL)
character.is_digit(revive_common::BASE_HEXADECIMAL)
}
///
@@ -155,7 +155,7 @@ where
&[
context.field_const(0),
context
.integer_type(era_compiler_common::BIT_LENGTH_X32)
.integer_type(revive_common::BIT_LENGTH_X32)
.const_int(index as u64, false),
],
context.field_type().as_basic_type_enum(),
@@ -894,9 +894,7 @@ impl FunctionCall {
let offset = context.builder().build_int_add(
arguments[0].into_int_value(),
context.field_const(
(era_compiler_common::BYTE_LENGTH_X32
+ era_compiler_common::BYTE_LENGTH_FIELD)
as u64,
(revive_common::BYTE_LENGTH_X32 + revive_common::BYTE_LENGTH_FIELD) as u64,
),
"datacopy_contract_hash_offset",
)?;
@@ -125,13 +125,12 @@ impl Literal {
.as_basic_value_enum();
let constant = match inner {
IntegerLiteral::Decimal { ref inner } => num::BigUint::from_str_radix(
inner.as_str(),
era_compiler_common::BASE_DECIMAL,
),
IntegerLiteral::Decimal { ref inner } => {
num::BigUint::from_str_radix(inner.as_str(), revive_common::BASE_DECIMAL)
}
IntegerLiteral::Hexadecimal { ref inner } => num::BigUint::from_str_radix(
&inner["0x".len()..],
era_compiler_common::BASE_HEXADECIMAL,
revive_common::BASE_HEXADECIMAL,
),
}
.expect("Always valid");
@@ -148,7 +147,7 @@ impl Literal {
string.clone()
} else {
let mut hex_string =
String::with_capacity(era_compiler_common::BYTE_LENGTH_FIELD * 2);
String::with_capacity(revive_common::BYTE_LENGTH_FIELD * 2);
let mut index = 0;
loop {
if index >= string.len() {
@@ -165,7 +164,7 @@ impl Literal {
let codepoint_str = &string[index + 1..index + 5];
let codepoint = u32::from_str_radix(
codepoint_str,
era_compiler_common::BASE_HEXADECIMAL,
revive_common::BASE_HEXADECIMAL,
)
.map_err(|error| {
anyhow::anyhow!(
@@ -209,16 +208,16 @@ impl Literal {
hex_string
};
if hex_string.len() > era_compiler_common::BYTE_LENGTH_FIELD * 2 {
if hex_string.len() > revive_common::BYTE_LENGTH_FIELD * 2 {
return Ok(era_compiler_llvm_context::EraVMArgument::new_with_original(
r#type.const_zero().as_basic_value_enum(),
string,
));
}
if hex_string.len() < era_compiler_common::BYTE_LENGTH_FIELD * 2 {
if hex_string.len() < revive_common::BYTE_LENGTH_FIELD * 2 {
hex_string.push_str(
"0".repeat((era_compiler_common::BYTE_LENGTH_FIELD * 2) - hex_string.len())
"0".repeat((revive_common::BYTE_LENGTH_FIELD * 2) - hex_string.len())
.as_str(),
);
}
@@ -297,7 +297,7 @@ where
&[
context.field_const(0),
context
.integer_type(era_compiler_common::BIT_LENGTH_X32)
.integer_type(revive_common::BIT_LENGTH_X32)
.const_int(index as u64, false),
],
context.field_type(),
@@ -195,7 +195,7 @@ where
&[
context.field_const(0),
context
.integer_type(era_compiler_common::BIT_LENGTH_X32)
.integer_type(revive_common::BIT_LENGTH_X32)
.const_int(index as u64, false),
],
binding.r#type.unwrap_or_default().into_llvm(context),
+2 -2
View File
@@ -31,7 +31,7 @@ pub enum Type {
impl Default for Type {
fn default() -> Self {
Self::UInt(era_compiler_common::BIT_LENGTH_FIELD)
Self::UInt(revive_common::BIT_LENGTH_FIELD)
}
}
@@ -79,7 +79,7 @@ impl Type {
D: era_compiler_llvm_context::EraVMDependency + Clone,
{
match self {
Self::Bool => context.integer_type(era_compiler_common::BIT_LENGTH_BOOLEAN),
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(),
+3 -5
View File
@@ -20,10 +20,10 @@ static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
///
fn main() {
std::process::exit(match main_inner() {
Ok(()) => era_compiler_common::EXIT_CODE_SUCCESS,
Ok(()) => revive_common::EXIT_CODE_SUCCESS,
Err(error) => {
eprintln!("{error}");
era_compiler_common::EXIT_CODE_FAILURE
revive_common::EXIT_CODE_FAILURE
}
})
}
@@ -82,9 +82,7 @@ fn main_inner() -> anyhow::Result<()> {
)?;
let evm_version = match arguments.evm_version {
Some(evm_version) => Some(era_compiler_common::EVMVersion::try_from(
evm_version.as_str(),
)?),
Some(evm_version) => Some(revive_common::EVMVersion::try_from(evm_version.as_str())?),
None => None,
};