From 93b7b350fe9f9c8423435f54d6ec2e4ba4ac354a Mon Sep 17 00:00:00 2001 From: Morty Date: Thu, 31 Jul 2025 18:37:27 +0800 Subject: [PATCH 1/3] feat: override difficulty opcode to always return zero --- src/instructions.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/instructions.rs b/src/instructions.rs index 59f2b8a..d887824 100644 --- a/src/instructions.rs +++ b/src/instructions.rs @@ -16,6 +16,8 @@ use std::rc::Rc; const HISTORY_STORAGE_ADDRESS: Address = address!("0x0000F90827F1C53a10cb7A02335B175320002935"); const HISTORY_SERVE_WINDOW: u64 = 8191; +// const DIFFICULTY: U256 = U256::ZERO; +const DIFFICULTY: U256 = U256::from_limbs([1233, 0, 0, 0]); /// Holds the EVM instruction table for Scroll. pub struct ScrollInstructions { @@ -67,9 +69,10 @@ where /// - `TLOAD` /// - `SELFDESTRUCT` /// - `MCOPY` +/// - `DIFFICULTY` pub fn make_scroll_instruction_table( ) -> InstructionTable { - let mut table = instruction_table::(); + let mut table: [fn(InstructionContext<'_, HOST, WIRE>); 256] = instruction_table::(); // override the instructions table[opcode::BLOCKHASH as usize] = blockhash::; @@ -78,6 +81,7 @@ pub fn make_scroll_instruction_table; table[opcode::SELFDESTRUCT as usize] = selfdestruct::; table[opcode::MCOPY as usize] = mcopy::; + table[opcode::DIFFICULTY as usize] = difficulty::; table } @@ -216,6 +220,16 @@ fn mcopy(context: InstructionContext interpreter.memory.copy(dst, src, len); } +/// Implements the DIFFICULTY instruction. +/// +/// Pushes the block difficulty(default to 0) onto the stack. +pub fn difficulty( + context: InstructionContext<'_, H, WIRE>, +) { + gas!(context.interpreter, gas::BASE); + push!(context.interpreter, DIFFICULTY); +} + // HELPER FUNCTIONS // ================================================================================================ From c67a26eb613d4e0b3d1e7c5c8be0705dfeff7980 Mon Sep 17 00:00:00 2001 From: Morty Date: Thu, 31 Jul 2025 18:39:28 +0800 Subject: [PATCH 2/3] fix typo --- src/instructions.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/instructions.rs b/src/instructions.rs index d887824..9524ca8 100644 --- a/src/instructions.rs +++ b/src/instructions.rs @@ -72,7 +72,7 @@ where /// - `DIFFICULTY` pub fn make_scroll_instruction_table( ) -> InstructionTable { - let mut table: [fn(InstructionContext<'_, HOST, WIRE>); 256] = instruction_table::(); + let mut table = instruction_table::(); // override the instructions table[opcode::BLOCKHASH as usize] = blockhash::; From 01030c48e50c55a9a2cf271478753c3f4aa84f9d Mon Sep 17 00:00:00 2001 From: Morty Date: Thu, 31 Jul 2025 19:27:28 +0800 Subject: [PATCH 3/3] update DIFFICULTY --- src/instructions.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/instructions.rs b/src/instructions.rs index 9524ca8..c9a79ff 100644 --- a/src/instructions.rs +++ b/src/instructions.rs @@ -16,8 +16,7 @@ use std::rc::Rc; const HISTORY_STORAGE_ADDRESS: Address = address!("0x0000F90827F1C53a10cb7A02335B175320002935"); const HISTORY_SERVE_WINDOW: u64 = 8191; -// const DIFFICULTY: U256 = U256::ZERO; -const DIFFICULTY: U256 = U256::from_limbs([1233, 0, 0, 0]); +const DIFFICULTY: U256 = U256::ZERO; /// Holds the EVM instruction table for Scroll. pub struct ScrollInstructions {