Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the gasprice opcode #127

Merged
merged 8 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions crates/integration/contracts/GasPrice.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8;

/* runner.json
{
"differential": false,
"actions": [
{
"Instantiate": {
"code": {
"Solidity": {
"contract": "GasPrice"
}
}
}
},
{
"VerifyCall": {
"success": true
}
}
]
}
*/

contract GasPrice {
constructor() payable {
assert(tx.gasprice == 1);
}
}
1 change: 1 addition & 0 deletions crates/integration/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ test_spec!(immutables, "Immutables", "Immutables.sol");
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");

fn instantiate(path: &str, contract: &str) -> Vec<SpecsAction> {
vec![Instantiate {
Expand Down
4 changes: 2 additions & 2 deletions crates/llvm-context/src/polkavm/evm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ where

/// Translates the `gas_price` instruction.
pub fn gas_price<'ctx, D>(
_context: &mut Context<'ctx, D>,
context: &mut Context<'ctx, D>,
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
where
D: Dependency + Clone,
{
todo!()
Ok(context.word_const(1).as_basic_value_enum())
}

/// Translates the `tx.origin` instruction.
Expand Down
2 changes: 2 additions & 0 deletions crates/runtime-api/src/polkavm_imports.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,5 @@ POLKAVM_IMPORT(void, return_data_size, uint32_t)
POLKAVM_IMPORT(void, set_immutable_data, uint32_t, uint32_t);

POLKAVM_IMPORT(void, value_transferred, uint32_t)

POLKAVM_IMPORT(void, weight_to_fee, uint64_t, uint64_t, uint32_t);
5 changes: 4 additions & 1 deletion crates/runtime-api/src/polkavm_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ pub static SET_IMMUTABLE_DATA: &str = "set_immutable_data";

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; 27] = [
pub static IMPORTS: [&str; 28] = [
SBRK,
MEMORY_SIZE,
ADDRESS,
Expand Down Expand Up @@ -94,6 +96,7 @@ pub static IMPORTS: [&str; 27] = [
SET_IMMUTABLE_DATA,
SET_STORAGE,
VALUE_TRANSFERRED,
WEIGHT_TO_FEE,
];

/// Creates a LLVM module from the [BITCODE].
Expand Down