diff --git a/prdoc/pr_10186.prdoc b/prdoc/pr_10186.prdoc new file mode 100644 index 0000000000000..bd46bbd7cfcac --- /dev/null +++ b/prdoc/pr_10186.prdoc @@ -0,0 +1,12 @@ +title: Return the correct block difficulty from the eth-rpc +doc: +- audience: Runtime Dev + description: |- + # Description + + This PR fixes an issue in the eth-rpc/pallet-revive that was causing it to return an incorrect value for the block's difficulty or prevrandao. + + In the VM/interpreter implementation we use a constant for the block difficulty. However, the eth block construction side was unaware of this constant being used and therefore the RPC was always returning a block difficulty of zero. +crates: +- name: pallet-revive + bump: patch diff --git a/substrate/frame/revive/src/evm/block_hash/block_builder.rs b/substrate/frame/revive/src/evm/block_hash/block_builder.rs index c84040c47390f..848429b69ce40 100644 --- a/substrate/frame/revive/src/evm/block_hash/block_builder.rs +++ b/substrate/frame/revive/src/evm/block_hash/block_builder.rs @@ -169,6 +169,9 @@ impl EthereumBlockBuilder { let tx_hashes = core::mem::replace(&mut self.tx_hashes, Vec::new()); let gas_info = core::mem::replace(&mut self.gas_info, Vec::new()); + let difficulty = U256::from(crate::vm::evm::DIFFICULTY); + let mix_hash = H256(difficulty.to_big_endian()); + let mut block = Block { number: block_number, parent_hash, @@ -186,6 +189,8 @@ impl EthereumBlockBuilder { logs_bloom: self.logs_bloom.bloom.into(), transactions: HashesOrTransactionInfos::Hashes(tx_hashes), + mix_hash, + ..Default::default() }; diff --git a/substrate/frame/revive/src/exec/tests.rs b/substrate/frame/revive/src/exec/tests.rs index 11c2cb65e7e53..9b483e922fa5e 100644 --- a/substrate/frame/revive/src/exec/tests.rs +++ b/substrate/frame/revive/src/exec/tests.rs @@ -2842,7 +2842,7 @@ fn block_hash_returns_proper_values() { assert_eq!( ctx.ext.block_hash(U256::from(0)), Some(H256::from(hex_literal::hex!( - "b9be84fb00044994dff6b62393b4c8aa8191717c5ea046f270bd2695524e9f85" + "c2fed5de763ecfa4cb65e8f57838c5517f69db4ede78a30093bf3fad66c5a8cd" ))) );