Skip to content

Commit

Permalink
Merge pull request #29 from weaveVM/fix-precompiles-test-precompiles
Browse files Browse the repository at this point in the history
Fix precompiles test precompiles
  • Loading branch information
andreespirela authored Aug 7, 2024
2 parents b66baf9 + 03273c2 commit 32b360a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn arweave_upload(input: &Bytes, gas_limit: u64) -> PrecompileResult {
let gas_used: u64 = (10_000 + data_size * 3) as u64;

if gas_used > gas_limit {
return Err(PrecompileErrors::Error(PrecompileError::OutOfGas))
return Err(PrecompileErrors::Error(PrecompileError::OutOfGas));
}

if input.is_empty() {
Expand All @@ -43,6 +43,7 @@ fn arweave_upload(input: &Bytes, gas_limit: u64) -> PrecompileResult {
let res = tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(
async {
IrysRequest::new()
.set_private_key(SOLANA_SILLY_PRIVATE_KEY.to_string())
.set_tag("Content-Type", "application/octet-stream")
.set_tag("WeaveVM:Precompile", "true")
.set_tag("WeaveVM:Precompile-Address", PC_ADDRESS.to_string().as_str())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn arweave_read(input: &Bytes, gas_limit: u64) -> PrecompileResult {
let gas_used: u64 = (ARWEAVE_PC_READ_BASE as usize + data_size * 3) as u64;

if gas_used > gas_limit {
return Err(PrecompileErrors::Error(PrecompileError::OutOfGas))
return Err(PrecompileErrors::Error(PrecompileError::OutOfGas));
}

if input.is_empty() {
Expand Down
4 changes: 3 additions & 1 deletion wvm-apps/wvm-exexed/crates/precompiles/src/inner/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use crate::inner::test_precompile::HELLO_WORLD_PC;
use crate::inner::{
arweave_precompile::ARWEAVE_UPLOAD_PC, arweave_read_precompile::ARWEAVE_READ_PC,
};
use reth::revm::precompile::PrecompileWithAddress;

pub mod arweave_precompile;
mod arweave_read_precompile;
mod test_precompile;

pub fn wvm_precompiles() -> impl Iterator<Item = PrecompileWithAddress> {
[ARWEAVE_UPLOAD_PC, ARWEAVE_READ_PC].into_iter()
[ARWEAVE_UPLOAD_PC, ARWEAVE_READ_PC, HELLO_WORLD_PC].into_iter()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use reth::primitives::revm_primitives::{Precompile, PrecompileOutput, PrecompileResult};
use reth::primitives::Bytes;
use reth::revm::precompile::{u64_to_address, PrecompileWithAddress};

pub const PC_ADDRESS: u64 = 0x19;
pub const HELLO_WORLD_PC: PrecompileWithAddress =
PrecompileWithAddress(u64_to_address(PC_ADDRESS), Precompile::Standard(hello_world_pc));

fn hello_world_pc(_input: &Bytes, _gas_limit: u64) -> PrecompileResult {
Ok(PrecompileOutput::new(0 as u64, "Hello World".into()))
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl StatefulPrecompileMut for WrappedPrecompile {

// get the result if it exists
if let Some(result) = cache.get(&key) {
return result.clone()
return result.clone();
}

// call the precompile if cache miss
Expand Down

0 comments on commit 32b360a

Please sign in to comment.