mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-12 02:31:02 +00:00
implement the gas opcode (#136)
This commit is contained in:
Generated
+357
-357
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -68,7 +68,7 @@ git2 = "0.19.0"
|
||||
# polkadot-sdk and friends
|
||||
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
|
||||
scale-info = { version = "2.11.1", default-features = false }
|
||||
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "4a0e3f624f42816cb4ca687d3ff9bba8e1a6bf19" }
|
||||
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "6ad748857e0e63c38cb7bb9435831ae73ab708cf" }
|
||||
|
||||
# llvm
|
||||
[workspace.dependencies.inkwell]
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"Baseline": 1126,
|
||||
"Computation": 2405,
|
||||
"DivisionArithmetics": 14486,
|
||||
"ERC20": 22755,
|
||||
"Events": 1620,
|
||||
"FibonacciIterative": 1670,
|
||||
"Flipper": 2005,
|
||||
"SHA1": 16832
|
||||
"Baseline": 1115,
|
||||
"Computation": 2394,
|
||||
"DivisionArithmetics": 14470,
|
||||
"ERC20": 22747,
|
||||
"Events": 1609,
|
||||
"FibonacciIterative": 1659,
|
||||
"Flipper": 1994,
|
||||
"SHA1": 16817
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8;
|
||||
|
||||
/* runner.json
|
||||
{
|
||||
"differential": false,
|
||||
"actions": [
|
||||
{
|
||||
"Instantiate": {
|
||||
"code": {
|
||||
"Solidity": {
|
||||
"contract": "GasLeft"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"VerifyCall": {
|
||||
"success": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
contract GasLeft {
|
||||
constructor() payable {
|
||||
assert(gasleft() > gasleft());
|
||||
assert(gasleft() > 0 && gasleft() < 0xffffffffffffffff);
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,7 @@ test_spec!(transaction, "Transaction", "Transaction.sol");
|
||||
test_spec!(block_hash, "BlockHash", "BlockHash.sol");
|
||||
test_spec!(delegate, "Delegate", "Delegate.sol");
|
||||
test_spec!(gas_price, "GasPrice", "GasPrice.sol");
|
||||
test_spec!(gas_left, "GasLeft", "GasLeft.sol");
|
||||
|
||||
fn instantiate(path: &str, contract: &str) -> Vec<SpecsAction> {
|
||||
vec![Instantiate {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
//! Translates the value and balance operations.
|
||||
|
||||
use inkwell::values::BasicValue;
|
||||
|
||||
use crate::polkavm::context::Context;
|
||||
use crate::polkavm::Dependency;
|
||||
|
||||
@@ -12,7 +10,15 @@ pub fn gas<'ctx, D>(
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
Ok(context.integer_const(256, 0).as_basic_value_enum())
|
||||
let ref_time_left_value = context
|
||||
.build_runtime_call(revive_runtime_api::polkavm_imports::REF_TIME_LEFT, &[])
|
||||
.expect("the ref_time_left syscall method should return a value")
|
||||
.into_int_value();
|
||||
|
||||
Ok(context
|
||||
.builder()
|
||||
.build_int_z_extend(ref_time_left_value, context.word_type(), "gas_left")?
|
||||
.into())
|
||||
}
|
||||
|
||||
/// Translates the `value` instruction.
|
||||
|
||||
@@ -108,7 +108,7 @@ POLKAVM_IMPORT(void, origin, uint32_t)
|
||||
|
||||
POLKAVM_IMPORT(void, seal_return, uint32_t, uint32_t, uint32_t)
|
||||
|
||||
POLKAVM_IMPORT(uint64_t, set_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
||||
POLKAVM_IMPORT(uint64_t, ref_time_left)
|
||||
|
||||
POLKAVM_IMPORT(void, return_data_copy, uint32_t, uint32_t, uint32_t)
|
||||
|
||||
@@ -116,6 +116,8 @@ POLKAVM_IMPORT(void, return_data_size, uint32_t)
|
||||
|
||||
POLKAVM_IMPORT(void, set_immutable_data, uint32_t, uint32_t);
|
||||
|
||||
POLKAVM_IMPORT(uint64_t, set_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
||||
|
||||
POLKAVM_IMPORT(void, value_transferred, uint32_t)
|
||||
|
||||
POLKAVM_IMPORT(void, weight_to_fee, uint64_t, uint64_t, uint32_t);
|
||||
|
||||
@@ -56,9 +56,9 @@ pub static NOW: &str = "now";
|
||||
|
||||
pub static ORIGIN: &str = "origin";
|
||||
|
||||
pub static RETURN: &str = "seal_return";
|
||||
pub static REF_TIME_LEFT: &str = "ref_time_left";
|
||||
|
||||
pub static SET_STORAGE: &str = "set_storage";
|
||||
pub static RETURN: &str = "seal_return";
|
||||
|
||||
pub static RETURNDATACOPY: &str = "return_data_copy";
|
||||
|
||||
@@ -66,13 +66,15 @@ pub static RETURNDATASIZE: &str = "return_data_size";
|
||||
|
||||
pub static SET_IMMUTABLE_DATA: &str = "set_immutable_data";
|
||||
|
||||
pub static SET_STORAGE: &str = "set_storage";
|
||||
|
||||
pub static VALUE_TRANSFERRED: &str = "value_transferred";
|
||||
|
||||
pub static WEIGHT_TO_FEE: &str = "weight_to_fee";
|
||||
|
||||
/// All imported runtime API symbols.
|
||||
/// Useful for configuring common attributes and linkage.
|
||||
pub static IMPORTS: [&str; 30] = [
|
||||
pub static IMPORTS: [&str; 31] = [
|
||||
SBRK,
|
||||
MEMORY_SIZE,
|
||||
ADDRESS,
|
||||
@@ -96,6 +98,7 @@ pub static IMPORTS: [&str; 30] = [
|
||||
INSTANTIATE,
|
||||
NOW,
|
||||
ORIGIN,
|
||||
REF_TIME_LEFT,
|
||||
RETURN,
|
||||
RETURNDATACOPY,
|
||||
RETURNDATASIZE,
|
||||
|
||||
Reference in New Issue
Block a user