Skip to content

Commit

Permalink
Feat: add CANCUN hard fork support (#926)
Browse files Browse the repository at this point in the history
## Description

➡️ Added **EVM CANCUN** hard fork support. Based on SputnikVM release
[v0.42.0-aurora](https://github.com/aurora-is-near/sputnikvm/releases/tag/v0.42.0-aurora)
➡️  Changed `engine-tests` that related to **CACUN** changes
➡️  Solidity: updated to `0.8.25` which support **CANCUN** Features
➡️  Extended Transactions fields for **CANCUN** hard fork requirements

### Cancun hard fork

➡️ EVM impelentation of Cancun hard fork:
aurora-is-near/sputnikvm/pull/39

### Breaking changes

➡️ Transaction extended according to
[EIP-4844](https://eips.ethereum.org/EIPS/eip-4844) requirements

### Gas cost
Gas cost changed as expected insignificantly.
- 2 tests: gas increased to `1 TGas`
- 1 test: gas decreased to `1 TGas`
  • Loading branch information
mrLSD authored Jun 13, 2024
1 parent 04dd7f0 commit b4a0eac
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 58 deletions.
64 changes: 21 additions & 43 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ byte-slice-cast = { version = "1", default-features = false }
criterion = "0.5"
digest = "0.10"
ethabi = { version = "18", default-features = false }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.39.1", default-features = false }
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.39.1", default-features = false, features = ["std"] }
evm-gasometer = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.39.1", default-features = false, features = ["std", "tracing"] }
evm-runtime = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.39.1", default-features = false, features = ["std", "tracing"] }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.42.0-aurora", default-features = false }
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.42.0-aurora", default-features = false, features = ["std"] }
evm-gasometer = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.42.0-aurora", default-features = false, features = ["std", "tracing"] }
evm-runtime = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.42.0-aurora", default-features = false, features = ["std", "tracing"] }
fixed-hash = { version = "0.8", default-features = false }
function_name = "0.3"
git2 = "0.18"
Expand Down
8 changes: 4 additions & 4 deletions engine-tests/src/tests/repro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn repro_GdASJ3KESs() {
block_timestamp: 1_645_717_564_644_206_730,
input_path: "src/tests/res/input_GdASJ3KESs.hex",
evm_gas_used: 706_713,
near_gas_used: 116,
near_gas_used: 117,
});
}

Expand All @@ -51,7 +51,7 @@ fn repro_8ru7VEA() {
block_timestamp: 1_648_829_935_343_349_589,
input_path: "src/tests/res/input_8ru7VEA.hex",
evm_gas_used: 1_732_181,
near_gas_used: 210,
near_gas_used: 211,
});
}

Expand Down Expand Up @@ -88,7 +88,7 @@ fn repro_5bEgfRQ() {
block_timestamp: 1_651_073_772_931_594_646,
input_path: "src/tests/res/input_5bEgfRQ.hex",
evm_gas_used: 6_414_105,
near_gas_used: 656,
near_gas_used: 655,
});
}

Expand All @@ -106,7 +106,7 @@ fn repro_D98vwmi() {
block_timestamp: 1_651_753_443_421_003_245,
input_path: "src/tests/res/input_D98vwmi.hex",
evm_gas_used: 1_035_348,
near_gas_used: 172,
near_gas_used: 173,
});
}

Expand Down
6 changes: 2 additions & 4 deletions engine-tests/src/tests/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,8 @@ fn test_total_supply_accounting() {
})
.unwrap();
#[cfg(not(feature = "ext-connector"))]
assert_eq!(
get_total_supply(&mut runner),
INITIAL_BALANCE - TRANSFER_AMOUNT
);
// For CANCUN hard fork `total_supply` can't change
assert_eq!(get_total_supply(&mut runner), INITIAL_BALANCE);
}

#[test]
Expand Down
4 changes: 3 additions & 1 deletion engine-tests/src/tests/self_destruct_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use crate::utils::solidity::self_destruct::{

/// Check that account state should be properly removed after calling selfdestruct
#[test]
// For CANCUN hard fork SELFDESCTRUCT disabled
#[ignore]
fn test_self_destruct_reset_state() {
let mut signer = utils::Signer::random();
let mut runner = utils::deploy_runner();
Expand All @@ -29,7 +31,7 @@ fn test_self_destruct_reset_state() {
assert_eq!(counter_value, Some(1));
sd.finish(&mut runner);
let counter_value = sd.counter(&mut runner, &mut signer);
assert!(counter_value.is_none());
assert!(counter_value.is_some());

let sd_contract_addr1 = sd_factory.deploy(&mut runner, &mut signer);
assert_eq!(sd_contract_addr, sd_contract_addr1);
Expand Down
2 changes: 1 addition & 1 deletion engine-tests/src/utils/solidity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ where
&source_mount_arg,
"-v",
&output_mount_arg,
"ethereum/solc:0.8.24", // TODO: 0.8.25 introduces support of the Dencun hard fork.
"ethereum/solc:stable",
"--allow-paths",
"/contracts/",
"-o",
Expand Down
3 changes: 3 additions & 0 deletions engine-transactions/src/eip_4844.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Type indicator (per EIP-4844) for shard blob transactions
/// [EIP-4844 Specification](https://eips.ethereum.org/EIPS/eip-4844#specification)
pub const TYPE_BYTE: u8 = 0x03;
5 changes: 5 additions & 0 deletions engine-transactions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use rlp::{Decodable, DecoderError, Rlp};
pub mod backwards_compatibility;
pub mod eip_1559;
pub mod eip_2930;
pub mod eip_4844;
pub mod legacy;

/// Typed Transaction Envelope (see `https://eips.ethereum.org/EIPS/eip-2718`)
Expand All @@ -40,6 +41,8 @@ impl TryFrom<&[u8]> for EthTransactionKind {
Ok(Self::Eip1559(eip_1559::SignedTransaction1559::decode(
&Rlp::new(&bytes[1..]),
)?))
} else if bytes[0] == eip_4844::TYPE_BYTE {
Err(Error::UnsupportedTransactionEip4844)
} else if bytes[0] <= 0x7f {
Err(Error::UnknownTransactionType)
} else if bytes[0] == 0xff {
Expand Down Expand Up @@ -212,6 +215,7 @@ pub enum Error {
IntegerConversion,
#[cfg_attr(feature = "serde", serde(serialize_with = "decoder_err_to_str"))]
RlpDecodeError(DecoderError),
UnsupportedTransactionEip4844,
}

#[cfg(feature = "serde")]
Expand All @@ -231,6 +235,7 @@ impl Error {
Self::GasOverflow => "ERR_GAS_OVERFLOW",
Self::IntegerConversion => "ERR_INTEGER_CONVERSION",
Self::RlpDecodeError(_) => "ERR_TX_RLP_DECODE",
Self::UnsupportedTransactionEip4844 => "ERR_UNSUPPORTED_TX_EIP4844",
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ pub struct Engine<'env, I: IO, E: Env, M = AuroraModExp> {
modexp_algorithm: PhantomData<M>,
}

pub(crate) const CONFIG: &Config = &Config::shanghai();
pub(crate) const CONFIG: &Config = &Config::cancun();

impl<'env, I: IO + Copy, E: Env, M: ModExpAlgorithm> Engine<'env, I, E, M> {
pub fn new(
Expand Down Expand Up @@ -1923,6 +1923,14 @@ impl<'env, I: IO + Copy, E: Env, M: ModExpAlgorithm> Backend for Engine<'env, I,
fn original_storage(&self, address: H160, index: H256) -> Option<H256> {
Some(self.storage(address, index))
}

fn get_blob_hash(&self, _index: usize) -> Option<U256> {
None
}

fn blob_gas_price(&self) -> Option<u128> {
None
}
}

impl<'env, J: IO + Copy, E: Env, M: ModExpAlgorithm> ApplyBackend for Engine<'env, J, E, M> {
Expand Down

0 comments on commit b4a0eac

Please sign in to comment.