Compare commits

...

3 Commits

Author SHA1 Message Date
Cyrill Leutwiler 36d9317831 update the polkadot-sdk and polkavm dependencies (#104)
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2024-10-30 09:28:24 +01:00
Cyrill Leutwiler 5b3b90db83 support the origin opcode (#103)
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2024-10-29 18:40:25 +01:00
Cyrill Leutwiler a4043ecde7 update LLVM target features (#102)
Signed-off-by: xermicus <cyrill@parity.io>
2024-10-29 18:17:29 +01:00
10 changed files with 520 additions and 434 deletions
Generated
+434 -415
View File
File diff suppressed because it is too large Load Diff
+5 -5
View File
@@ -51,10 +51,10 @@ path-slash = "0.2"
rayon = "1.8" rayon = "1.8"
clap = { version = "4", default-features = false, features = ["derive"] } clap = { version = "4", default-features = false, features = ["derive"] }
rand = "0.8" rand = "0.8"
polkavm-common = "0.13" polkavm-common = "0.14"
polkavm-linker = "0.13" polkavm-linker = "0.14"
polkavm-disassembler = "0.13" polkavm-disassembler = "0.14"
polkavm = "0.13" polkavm = "0.14"
alloy-primitives = { version = "0.8", features = ["serde"] } alloy-primitives = { version = "0.8", features = ["serde"] }
alloy-sol-types = "0.8" alloy-sol-types = "0.8"
alloy-genesis = "0.3" alloy-genesis = "0.3"
@@ -67,7 +67,7 @@ log = { version = "0.4" }
# polkadot-sdk and friends # polkadot-sdk and friends
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" } codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
scale-info = { version = "2.11.1", default-features = false } scale-info = { version = "2.11.1", default-features = false }
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "35535efb3d9f4d3b3be63c3c2bcf963883ab6af1" } polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "db40a66db71e8e7fe943dda5cd0e28078efa2a19" }
# llvm # llvm
[workspace.dependencies.inkwell] [workspace.dependencies.inkwell]
+8 -8
View File
@@ -1,10 +1,10 @@
{ {
"Baseline": 989, "Baseline": 967,
"Computation": 4153, "Computation": 4022,
"DivisionArithmetics": 40614, "DivisionArithmetics": 31787,
"ERC20": 47348, "ERC20": 44233,
"Events": 1781, "Events": 1743,
"FibonacciIterative": 3035, "FibonacciIterative": 2927,
"Flipper": 3448, "Flipper": 3408,
"SHA1": 33553 "SHA1": 26009
} }
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/* runner.json
{
"differential": true,
"actions": [
{
"Upload": {
"code": {
"Solidity": {
"contract": "TransactionOrigin"
}
}
}
},
{
"Instantiate": {
"code": {
"Solidity": {
"contract": "TransactionTester"
}
}
}
},
{
"Call": {
"dest": {
"Instantiated": 0
},
"data": "f8a8fd6d"
}
}
]
}
*/
contract TransactionTester {
constructor() payable {
assert(tx.origin == new TransactionOrigin().test());
}
function test() public payable returns (address ret) {
ret = tx.origin;
}
}
contract TransactionOrigin {
function test() public payable returns (address ret) {
assert(msg.sender != tx.origin);
ret = tx.origin;
}
}
+1
View File
@@ -43,6 +43,7 @@ test_spec!(call, "Caller", "Call.sol");
test_spec!(transfer, "Transfer", "Transfer.sol"); test_spec!(transfer, "Transfer", "Transfer.sol");
test_spec!(return_data_oob, "ReturnDataOob", "ReturnDataOob.sol"); test_spec!(return_data_oob, "ReturnDataOob", "ReturnDataOob.sol");
test_spec!(immutables, "Immutables", "Immutables.sol"); test_spec!(immutables, "Immutables", "Immutables.sol");
test_spec!(transaction, "Transaction", "Transaction.sol");
fn instantiate(path: &str, contract: &str) -> Vec<SpecsAction> { fn instantiate(path: &str, contract: &str) -> Vec<SpecsAction> {
vec![Instantiate { vec![Instantiate {
@@ -27,12 +27,19 @@ where
/// Translates the `tx.origin` instruction. /// Translates the `tx.origin` instruction.
pub fn origin<'ctx, D>( pub fn origin<'ctx, D>(
_context: &mut Context<'ctx, D>, context: &mut Context<'ctx, D>,
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> ) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
where where
D: Dependency + Clone, D: Dependency + Clone,
{ {
todo!() let address_type = context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
let address_pointer = context.build_alloca_at_entry(address_type, "origin_address");
context.build_store(address_pointer, address_type.const_zero())?;
context.build_runtime_call(
revive_runtime_api::polkavm_imports::ORIGIN,
&[address_pointer.to_int(context).into()],
);
context.build_load_address(address_pointer)
} }
/// Translates the `chain_id` instruction. /// Translates the `chain_id` instruction.
@@ -39,9 +39,9 @@ impl TargetMachine {
/// LLVM target features. /// LLVM target features.
#[cfg(feature = "riscv-zbb")] #[cfg(feature = "riscv-zbb")]
pub const VM_FEATURES: &'static str = "+zbb,+e,+m,+c"; pub const VM_FEATURES: &'static str = "+zbb,+a,+e,+m,+c,+fast-unaligned-access,+xtheadcondmov";
#[cfg(not(feature = "riscv-zbb"))] #[cfg(not(feature = "riscv-zbb"))]
pub const VM_FEATURES: &'static str = "+e,+m,+c"; pub const VM_FEATURES: &'static str = "+a,+e,+m,+c,+fast-unaligned-access,+xtheadcondmov";
/// A shortcut constructor. /// A shortcut constructor.
/// A separate instance for every optimization level is created. /// A separate instance for every optimization level is created.
+1 -1
View File
@@ -246,7 +246,7 @@ pub enum Code {
/// A contract blob /// A contract blob
Bytes(Vec<u8>), Bytes(Vec<u8>),
/// Pre-existing contract hash /// Pre-existing contract hash
Hash(Hash), Hash(crate::runtime::Hash),
} }
impl Default for Code { impl Default for Code {
+2
View File
@@ -96,6 +96,8 @@ POLKAVM_IMPORT(uint32_t, instantiate, uint32_t)
POLKAVM_IMPORT(void, now, uint32_t) POLKAVM_IMPORT(void, now, uint32_t)
POLKAVM_IMPORT(void, origin, uint32_t)
POLKAVM_IMPORT(void, seal_return, uint32_t, uint32_t, uint32_t) POLKAVM_IMPORT(void, seal_return, uint32_t, uint32_t, uint32_t)
POLKAVM_IMPORT(uint32_t, set_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t) POLKAVM_IMPORT(uint32_t, set_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
+4 -1
View File
@@ -46,6 +46,8 @@ pub static INSTANTIATE: &str = "instantiate";
pub static NOW: &str = "now"; pub static NOW: &str = "now";
pub static ORIGIN: &str = "origin";
pub static RETURN: &str = "seal_return"; pub static RETURN: &str = "seal_return";
pub static SET_STORAGE: &str = "set_storage"; pub static SET_STORAGE: &str = "set_storage";
@@ -60,7 +62,7 @@ pub static VALUE_TRANSFERRED: &str = "value_transferred";
/// All imported runtime API symbols. /// All imported runtime API symbols.
/// Useful for configuring common attributes and linkage. /// Useful for configuring common attributes and linkage.
pub static IMPORTS: [&str; 24] = [ pub static IMPORTS: [&str; 25] = [
SBRK, SBRK,
MEMORY_SIZE, MEMORY_SIZE,
ADDRESS, ADDRESS,
@@ -79,6 +81,7 @@ pub static IMPORTS: [&str; 24] = [
INPUT, INPUT,
INSTANTIATE, INSTANTIATE,
NOW, NOW,
ORIGIN,
RETURN, RETURN,
RETURNDATACOPY, RETURNDATACOPY,
RETURNDATASIZE, RETURNDATASIZE,