mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-13 03:51:01 +00:00
Merge branch 'main' into kvpanch/llvm_21
This commit is contained in:
@@ -15,6 +15,7 @@ Supported `polkadot-sdk` rev: `unstable2507`
|
|||||||
- Instruct the LLVM backend and linker to `--relax` (may lead to smaller contract code size).
|
- Instruct the LLVM backend and linker to `--relax` (may lead to smaller contract code size).
|
||||||
- Standard JSON mode: Don't forward EVM bytecode related output selections to solc.
|
- Standard JSON mode: Don't forward EVM bytecode related output selections to solc.
|
||||||
- The supported `polkadot-sdk` release is `unstable2507`.
|
- The supported `polkadot-sdk` release is `unstable2507`.
|
||||||
|
- The `INVALID` opcode and OOB memory accesses now consume all remaining gas.
|
||||||
|
|
||||||
### Fixed:
|
### Fixed:
|
||||||
- The missing `STOP` instruction at the end of `code` blocks.
|
- The missing `STOP` instruction at the end of `code` blocks.
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"Baseline": 911,
|
"Baseline": 911,
|
||||||
"Computation": 2293,
|
"Computation": 2337,
|
||||||
"DivisionArithmetics": 14353,
|
"DivisionArithmetics": 14488,
|
||||||
"ERC20": 16936,
|
"ERC20": 17041,
|
||||||
"Events": 1672,
|
"Events": 1672,
|
||||||
"FibonacciIterative": 1454,
|
"FibonacciIterative": 1454,
|
||||||
"Flipper": 2083,
|
"Flipper": 2106,
|
||||||
"SHA1": 7727
|
"SHA1": 7814
|
||||||
}
|
}
|
||||||
@@ -669,3 +669,48 @@ fn sbrk_bounds_checks() {
|
|||||||
"not seeing a trap means the contract did not catch the OOB"
|
"not seeing a trap means the contract did not catch the OOB"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn invalid_opcode_works() {
|
||||||
|
let code = &build_yul(&[(
|
||||||
|
"invalid.yul",
|
||||||
|
r#"object "Test" {
|
||||||
|
code {
|
||||||
|
invalid()
|
||||||
|
}
|
||||||
|
object "Test_deployed" {
|
||||||
|
code {
|
||||||
|
invalid()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}"#,
|
||||||
|
)])
|
||||||
|
.unwrap()["invalid.yul:Test"];
|
||||||
|
|
||||||
|
let results = Specs {
|
||||||
|
actions: vec![
|
||||||
|
Instantiate {
|
||||||
|
origin: TestAddress::Alice,
|
||||||
|
value: 0,
|
||||||
|
gas_limit: Some(GAS_LIMIT),
|
||||||
|
storage_deposit_limit: None,
|
||||||
|
code: Code::Bytes(code.to_vec()),
|
||||||
|
data: Default::default(),
|
||||||
|
salt: OptionalHex::default(),
|
||||||
|
},
|
||||||
|
VerifyCall(VerifyCallExpectation {
|
||||||
|
success: false,
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
differential: false,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.run();
|
||||||
|
|
||||||
|
let CallResult::Instantiate { result, .. } = results.last().unwrap() else {
|
||||||
|
unreachable!()
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(result.weight_consumed, GAS_LIMIT);
|
||||||
|
}
|
||||||
|
|||||||
@@ -51,11 +51,11 @@ impl RuntimeFunction for WordToPointer {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
let block_continue = context.append_basic_block("offset_pointer_ok");
|
let block_continue = context.append_basic_block("offset_pointer_ok");
|
||||||
let block_trap = context.append_basic_block("offset_pointer_overflow");
|
let block_invalid = context.append_basic_block("offset_pointer_overflow");
|
||||||
context.build_conditional_branch(is_overflow, block_trap, block_continue)?;
|
context.build_conditional_branch(is_overflow, block_invalid, block_continue)?;
|
||||||
|
|
||||||
context.set_basic_block(block_trap);
|
context.set_basic_block(block_invalid);
|
||||||
context.build_call(context.intrinsics().trap, &[], "invalid_trap");
|
context.build_runtime_call(revive_runtime_api::polkavm_imports::INVALID, &[]);
|
||||||
context.build_unreachable();
|
context.build_unreachable();
|
||||||
|
|
||||||
context.set_basic_block(block_continue);
|
context.set_basic_block(block_continue);
|
||||||
|
|||||||
@@ -52,12 +52,14 @@ pub fn stop(context: &mut Context) -> anyhow::Result<()> {
|
|||||||
/// Translates the `invalid` instruction.
|
/// Translates the `invalid` instruction.
|
||||||
/// Burns all gas using an out-of-bounds memory store, causing a panic.
|
/// Burns all gas using an out-of-bounds memory store, causing a panic.
|
||||||
pub fn invalid(context: &mut Context) -> anyhow::Result<()> {
|
pub fn invalid(context: &mut Context) -> anyhow::Result<()> {
|
||||||
crate::polkavm::evm::memory::store(
|
let invalid_block = context.append_basic_block("explicit_invalid");
|
||||||
context,
|
context.build_unconditional_branch(invalid_block);
|
||||||
context.word_type().const_all_ones(),
|
context.set_basic_block(invalid_block);
|
||||||
context.word_const(0),
|
context.build_runtime_call(revive_runtime_api::polkavm_imports::INVALID, &[]);
|
||||||
)?;
|
context.build_unreachable();
|
||||||
context.build_call(context.intrinsics().trap, &[], "invalid_trap");
|
|
||||||
|
context.set_basic_block(context.append_basic_block("dead_code"));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ POLKAVM_IMPORT(uint64_t, code_size, uint32_t)
|
|||||||
|
|
||||||
POLKAVM_IMPORT(void, code_hash, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, code_hash, uint32_t, uint32_t)
|
||||||
|
|
||||||
|
POLKAVM_IMPORT(void, consume_all_gas)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, delegate_call, uint64_t, uint64_t, uint64_t, uint32_t, uint64_t, uint64_t)
|
POLKAVM_IMPORT(uint32_t, delegate_call, uint64_t, uint64_t, uint64_t, uint32_t, uint64_t, uint64_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, deposit_event, uint32_t, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, deposit_event, uint32_t, uint32_t, uint32_t, uint32_t)
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ pub static HASH_KECCAK_256: &str = "hash_keccak_256";
|
|||||||
|
|
||||||
pub static INSTANTIATE: &str = "instantiate";
|
pub static INSTANTIATE: &str = "instantiate";
|
||||||
|
|
||||||
|
pub static INVALID: &str = "consume_all_gas";
|
||||||
|
|
||||||
pub static NOW: &str = "now";
|
pub static NOW: &str = "now";
|
||||||
|
|
||||||
pub static ORIGIN: &str = "origin";
|
pub static ORIGIN: &str = "origin";
|
||||||
@@ -70,7 +72,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; 33] = [
|
pub static IMPORTS: [&str; 34] = [
|
||||||
ADDRESS,
|
ADDRESS,
|
||||||
BALANCE,
|
BALANCE,
|
||||||
BALANCE_OF,
|
BALANCE_OF,
|
||||||
@@ -94,6 +96,7 @@ pub static IMPORTS: [&str; 33] = [
|
|||||||
GET_STORAGE,
|
GET_STORAGE,
|
||||||
HASH_KECCAK_256,
|
HASH_KECCAK_256,
|
||||||
INSTANTIATE,
|
INSTANTIATE,
|
||||||
|
INVALID,
|
||||||
NOW,
|
NOW,
|
||||||
ORIGIN,
|
ORIGIN,
|
||||||
REF_TIME_LEFT,
|
REF_TIME_LEFT,
|
||||||
|
|||||||
Reference in New Issue
Block a user