Skip to content

Instantly share code, notes, and snippets.

@sourabhniyogi
Created May 8, 2025 12:20
Show Gist options
  • Save sourabhniyogi/7034b2c72b105050e4c4ca1abbe7d383 to your computer and use it in GitHub Desktop.
Save sourabhniyogi/7034b2c72b105050e4c4ca1abbe7d383 to your computer and use it in GitHub Desktop.
#![no_std]
#![no_main]
extern crate alloc;
const SIZE0 : usize = 4*1024*1024; // GP stack
// allocate memory for stack
use polkavm_derive::min_stack_size;
min_stack_size!(SIZE0); // 2^24 - 1 - 4096, should not greater than 2^24 - 1 (16777215)
const SIZE1 : usize = 512*1024*1024; // GP heap -- A.27 134MB (2^15 page -- if you reduce this it will panic)
use simplealloc::SimpleAlloc;
#[global_allocator]
static ALLOCATOR: SimpleAlloc<SIZE1> = SimpleAlloc::new(); // 2^24 - 1 - 4096, should not greater than 2^24 - 1 (16777215)
use revm::{
bytecode::Bytecode,
context::Context,
database::{BenchmarkDB, BENCH_CALLER, BENCH_TARGET},
primitives::{TxKind, U256},
ExecuteEvm,
MainBuilder,
MainContext,
};
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
unsafe {
core::arch::asm!("unimp", options(noreturn));
}
}
#[polkavm_derive::polkavm_export]
extern "C" fn add_numbers(_a: u32, _b: u32) -> u32 {
/* let mut evm = Context::mainnet()
.with_db(BenchmarkDB::new_bytecode(Bytecode::new()))
.modify_tx_chained(|tx| {
// Execution globals block hash/gas_limit/coinbase/timestamp..
tx.caller = BENCH_CALLER;
tx.kind = TxKind::Call(BENCH_TARGET);
tx.value = U256::from(911);
})
.build_mainnet();
let _res_and_state = evm.replay(); */
return 0; // Ensure you return properly and close the function
}
/*
fn main() {
add_numbers(1, 2);
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment