From dc0277fd2adafa2e51afc275ebe586df596c9580 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Fri, 15 Mar 2024 18:28:00 +0100 Subject: [PATCH 01/36] added the rest of bls12-381 precompile entrypoints --- crates/precompile/src/bls12_381.rs | 151 +++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) diff --git a/crates/precompile/src/bls12_381.rs b/crates/precompile/src/bls12_381.rs index c7fa29a..2defdeb 100644 --- a/crates/precompile/src/bls12_381.rs +++ b/crates/precompile/src/bls12_381.rs @@ -271,6 +271,157 @@ fn map_fp2_to_g2(_input: &Bytes, gas_limit: u64) -> PrecompileResult { Ok((MAP_FP2_TO_G2_BASE, B256::with_last_byte(result as u8).into())) } +/// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G1MUL precompile. +pub const BLS12_G1MUL: PrecompileWithAddress = + PrecompileWithAddress(crate::u64_to_address(BLS12_G1MUL_ADDRESS), Precompile::Standard(g1_mul)); + +fn g1_mul(input: &Bytes, gas_limit: u64) -> PrecompileResult { + const G1MUL_BASE: u64 = 12000; + if G1MUL_BASE > gas_limit { + return Err(PrecompileError::OutOfGas); + } + let result = g1_mul_impl(input).is_some(); + Ok((G1MUL_BASE, B256::with_last_byte(result as u8).into())) +} + +fn g1_mul_impl(_input: &[u8]) -> Option<()> { + None +} + +/// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G1MULTIEXP precompile. +pub const BLS12_G1MULTIEXP: PrecompileWithAddress = PrecompileWithAddress( + crate::u64_to_address(BLS12_G1MULTIEXP_ADDRESS), + Precompile::Standard(g1_multiexp), +); + +fn g1_multiexp(input: &Bytes, gas_limit: u64) -> PrecompileResult { + // TODO: make gas base depend on input k + const G1MULTIEXP_BASE: u64 = 12000; + if G1MULTIEXP_BASE > gas_limit { + return Err(PrecompileError::OutOfGas); + } + let result = g1_multiexp_impl(input).is_some(); + Ok((G1MULTIEXP_BASE, B256::with_last_byte(result as u8).into())) +} + +fn g1_multiexp_impl(_input: &[u8]) -> Option<()> { + None +} + +/// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G2ADD precompile. +pub const BLS12_G2ADD: PrecompileWithAddress = + PrecompileWithAddress(crate::u64_to_address(BLS12_G2ADD_ADDRESS), Precompile::Standard(g2_add)); + +fn g2_add(input: &Bytes, gas_limit: u64) -> PrecompileResult { + const G2ADD_BASE: u64 = 800; + if G2ADD_BASE > gas_limit { + return Err(PrecompileError::OutOfGas); + } + let result = g2_add_impl(input).is_some(); + Ok((G2ADD_BASE, B256::with_last_byte(result as u8).into())) +} + +fn g2_add_impl(_input: &[u8]) -> Option<()> { + None +} + +/// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G2MUL precompile. +pub const BLS12_G2MUL: PrecompileWithAddress = + PrecompileWithAddress(crate::u64_to_address(BLS12_G2MUL_ADDRESS), Precompile::Standard(g2_mul)); + +fn g2_mul(input: &Bytes, gas_limit: u64) -> PrecompileResult { + const G2MUL_BASE: u64 = 45000; + if G2MUL_BASE > gas_limit { + return Err(PrecompileError::OutOfGas); + } + let result = g2_mul_impl(input).is_some(); + Ok((G2MUL_BASE, B256::with_last_byte(result as u8).into())) +} + +fn g2_mul_impl(_input: &[u8]) -> Option<()> { + None +} + +/// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G2MULTIEXP precompile. +pub const BLS12_G2MULTIEXP: PrecompileWithAddress = PrecompileWithAddress( + crate::u64_to_address(BLS12_G2MULTIEXP_ADDRESS), + Precompile::Standard(g2_multiexp), +); + +fn g2_multiexp(input: &Bytes, gas_limit: u64) -> PrecompileResult { + // TODO: make gas base depend on input k + const G2MULTIEXP_BASE: u64 = 12000; + if G2MULTIEXP_BASE > gas_limit { + return Err(PrecompileError::OutOfGas); + } + let result = g2_multiexp_impl(input).is_some(); + Ok((G2MULTIEXP_BASE, B256::with_last_byte(result as u8).into())) +} + +fn g2_multiexp_impl(_input: &[u8]) -> Option<()> { + None +} + +/// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_PAIRING precompile. +pub const BLS12_PAIRING: PrecompileWithAddress = PrecompileWithAddress( + crate::u64_to_address(BLS12_PAIRING_ADDRESS), + Precompile::Standard(pairing), +); + +fn pairing(input: &Bytes, gas_limit: u64) -> PrecompileResult { + // TODO: make gas base depend on input k + const PAIRING_BASE: u64 = 12000; + if PAIRING_BASE > gas_limit { + return Err(PrecompileError::OutOfGas); + } + let result = pairing_impl(input).is_some(); + Ok((PAIRING_BASE, B256::with_last_byte(result as u8).into())) +} + +fn pairing_impl(_input: &[u8]) -> Option<()> { + None +} + +/// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_MAP_FP_TO_G1 precompile. +pub const BLS12_MAP_FP_TO_G1: PrecompileWithAddress = PrecompileWithAddress( + crate::u64_to_address(BLS12_MAP_FP_TO_G1_ADDRESS), + Precompile::Standard(map_fp_to_g1), +); + +fn map_fp_to_g1(input: &Bytes, gas_limit: u64) -> PrecompileResult { + // TODO: make gas base depend on input k + const MAP_FP_TO_G1_BASE: u64 = 12000; + if MAP_FP_TO_G1_BASE > gas_limit { + return Err(PrecompileError::OutOfGas); + } + let result = map_fp_to_g1_impl(input).is_some(); + Ok((MAP_FP_TO_G1_BASE, B256::with_last_byte(result as u8).into())) +} + +fn map_fp_to_g1_impl(_input: &[u8]) -> Option<()> { + None +} + +/// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_MAP_FP2_TO_G2 precompile. +pub const BLS12_MAP_FP2_TO_G2: PrecompileWithAddress = PrecompileWithAddress( + crate::u64_to_address(BLS12_MAP_FP2_TO_G2_ADDRESS), + Precompile::Standard(map_fp2_to_g2), +); + +fn map_fp2_to_g2(input: &Bytes, gas_limit: u64) -> PrecompileResult { + // TODO: make gas base depend on input k + const MAP_FP2_TO_G2_BASE: u64 = 12000; + if MAP_FP2_TO_G2_BASE > gas_limit { + return Err(PrecompileError::OutOfGas); + } + let result = map_fp2_to_g2_impl(input).is_some(); + Ok((MAP_FP2_TO_G2_BASE, B256::with_last_byte(result as u8).into())) +} + +fn map_fp2_to_g2_impl(_input: &[u8]) -> Option<()> { + None +} + #[cfg(test)] mod test { use super::*; From 52d845129d41d370e82a940078234e671a3963c7 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Mon, 18 Mar 2024 12:59:37 +0100 Subject: [PATCH 02/36] add g1_add test and first failing case --- crates/precompile/src/bls12_381.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/precompile/src/bls12_381.rs b/crates/precompile/src/bls12_381.rs index 2defdeb..79ddd5c 100644 --- a/crates/precompile/src/bls12_381.rs +++ b/crates/precompile/src/bls12_381.rs @@ -452,6 +452,7 @@ mod test { #[case::fail_violate_top_bytes("0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000108b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e10000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1", "", true, 500)] #[case::fail_invalid_field_element("0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb000000000000000000000000000000001a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaac0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1", "", true, 500)] #[case::fail_point_not_on_curve("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1", "", true, 500)] + #[case::g1_add_g1_plus_g1_equals_2_times_g1("0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e10000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1", "000000000000000000000000000000000572cbea904d67468808c8eb50a9450c9721db309128012543902d0ac358a62ae28f75bb8f1c7c42c39a8c5529bf0f4e00000000000000000000000000000000166a9d8cabc673a322fda673779d8e3822ba3ecb8670e461f73bb9021d5fd76a4c56d9d4cd16bd1bba86881979749d28", false, 500)] fn test_g1_add( #[case] input: &str, #[case] expected_output: &str, From 33d213486a0875ebaee115779242974f2d9b02d6 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Mon, 18 Mar 2024 21:17:43 +0100 Subject: [PATCH 03/36] initial implementation --- crates/precompile/src/bls12_381.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/precompile/src/bls12_381.rs b/crates/precompile/src/bls12_381.rs index 79ddd5c..10aaa32 100644 --- a/crates/precompile/src/bls12_381.rs +++ b/crates/precompile/src/bls12_381.rs @@ -33,6 +33,10 @@ pub fn precompiles() -> impl Iterator { .into_iter() } +const G1ADD_BASE: u64 = 500; +const INPUT_LENGTH: usize = 256; +const OUTPUT_LENGTH: usize = 128; + /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G1ADD precompile. const BLS12_G1ADD: PrecompileWithAddress = PrecompileWithAddress(crate::u64_to_address(BLS12_G1ADD_ADDRESS), Precompile::Standard(g1_add)); From 18dcbb5ca8892b9537fa32c107d4eb92ed6a194b Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Tue, 19 Mar 2024 09:56:13 +0100 Subject: [PATCH 04/36] remove impl functions --- crates/precompile/src/bls12_381.rs | 64 ++++++++---------------------- 1 file changed, 16 insertions(+), 48 deletions(-) diff --git a/crates/precompile/src/bls12_381.rs b/crates/precompile/src/bls12_381.rs index 10aaa32..76b03db 100644 --- a/crates/precompile/src/bls12_381.rs +++ b/crates/precompile/src/bls12_381.rs @@ -279,153 +279,121 @@ fn map_fp2_to_g2(_input: &Bytes, gas_limit: u64) -> PrecompileResult { pub const BLS12_G1MUL: PrecompileWithAddress = PrecompileWithAddress(crate::u64_to_address(BLS12_G1MUL_ADDRESS), Precompile::Standard(g1_mul)); -fn g1_mul(input: &Bytes, gas_limit: u64) -> PrecompileResult { +fn g1_mul(_input: &Bytes, gas_limit: u64) -> PrecompileResult { const G1MUL_BASE: u64 = 12000; if G1MUL_BASE > gas_limit { return Err(PrecompileError::OutOfGas); } - let result = g1_mul_impl(input).is_some(); + let result = 1; Ok((G1MUL_BASE, B256::with_last_byte(result as u8).into())) } -fn g1_mul_impl(_input: &[u8]) -> Option<()> { - None -} - /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G1MULTIEXP precompile. pub const BLS12_G1MULTIEXP: PrecompileWithAddress = PrecompileWithAddress( crate::u64_to_address(BLS12_G1MULTIEXP_ADDRESS), Precompile::Standard(g1_multiexp), ); -fn g1_multiexp(input: &Bytes, gas_limit: u64) -> PrecompileResult { +fn g1_multiexp(_input: &Bytes, gas_limit: u64) -> PrecompileResult { // TODO: make gas base depend on input k const G1MULTIEXP_BASE: u64 = 12000; if G1MULTIEXP_BASE > gas_limit { return Err(PrecompileError::OutOfGas); } - let result = g1_multiexp_impl(input).is_some(); + let result = 1; Ok((G1MULTIEXP_BASE, B256::with_last_byte(result as u8).into())) } -fn g1_multiexp_impl(_input: &[u8]) -> Option<()> { - None -} - /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G2ADD precompile. pub const BLS12_G2ADD: PrecompileWithAddress = PrecompileWithAddress(crate::u64_to_address(BLS12_G2ADD_ADDRESS), Precompile::Standard(g2_add)); -fn g2_add(input: &Bytes, gas_limit: u64) -> PrecompileResult { +fn g2_add(_input: &Bytes, gas_limit: u64) -> PrecompileResult { const G2ADD_BASE: u64 = 800; if G2ADD_BASE > gas_limit { return Err(PrecompileError::OutOfGas); } - let result = g2_add_impl(input).is_some(); + let result = 1; Ok((G2ADD_BASE, B256::with_last_byte(result as u8).into())) } -fn g2_add_impl(_input: &[u8]) -> Option<()> { - None -} - /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G2MUL precompile. pub const BLS12_G2MUL: PrecompileWithAddress = PrecompileWithAddress(crate::u64_to_address(BLS12_G2MUL_ADDRESS), Precompile::Standard(g2_mul)); -fn g2_mul(input: &Bytes, gas_limit: u64) -> PrecompileResult { +fn g2_mul(_input: &Bytes, gas_limit: u64) -> PrecompileResult { const G2MUL_BASE: u64 = 45000; if G2MUL_BASE > gas_limit { return Err(PrecompileError::OutOfGas); } - let result = g2_mul_impl(input).is_some(); + let result = 1; Ok((G2MUL_BASE, B256::with_last_byte(result as u8).into())) } -fn g2_mul_impl(_input: &[u8]) -> Option<()> { - None -} - /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G2MULTIEXP precompile. pub const BLS12_G2MULTIEXP: PrecompileWithAddress = PrecompileWithAddress( crate::u64_to_address(BLS12_G2MULTIEXP_ADDRESS), Precompile::Standard(g2_multiexp), ); -fn g2_multiexp(input: &Bytes, gas_limit: u64) -> PrecompileResult { +fn g2_multiexp(_input: &Bytes, gas_limit: u64) -> PrecompileResult { // TODO: make gas base depend on input k const G2MULTIEXP_BASE: u64 = 12000; if G2MULTIEXP_BASE > gas_limit { return Err(PrecompileError::OutOfGas); } - let result = g2_multiexp_impl(input).is_some(); + let result = 1; Ok((G2MULTIEXP_BASE, B256::with_last_byte(result as u8).into())) } -fn g2_multiexp_impl(_input: &[u8]) -> Option<()> { - None -} - /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_PAIRING precompile. pub const BLS12_PAIRING: PrecompileWithAddress = PrecompileWithAddress( crate::u64_to_address(BLS12_PAIRING_ADDRESS), Precompile::Standard(pairing), ); -fn pairing(input: &Bytes, gas_limit: u64) -> PrecompileResult { +fn pairing(_input: &Bytes, gas_limit: u64) -> PrecompileResult { // TODO: make gas base depend on input k const PAIRING_BASE: u64 = 12000; if PAIRING_BASE > gas_limit { return Err(PrecompileError::OutOfGas); } - let result = pairing_impl(input).is_some(); + let result = 1; Ok((PAIRING_BASE, B256::with_last_byte(result as u8).into())) } -fn pairing_impl(_input: &[u8]) -> Option<()> { - None -} - /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_MAP_FP_TO_G1 precompile. pub const BLS12_MAP_FP_TO_G1: PrecompileWithAddress = PrecompileWithAddress( crate::u64_to_address(BLS12_MAP_FP_TO_G1_ADDRESS), Precompile::Standard(map_fp_to_g1), ); -fn map_fp_to_g1(input: &Bytes, gas_limit: u64) -> PrecompileResult { +fn map_fp_to_g1(_input: &Bytes, gas_limit: u64) -> PrecompileResult { // TODO: make gas base depend on input k const MAP_FP_TO_G1_BASE: u64 = 12000; if MAP_FP_TO_G1_BASE > gas_limit { return Err(PrecompileError::OutOfGas); } - let result = map_fp_to_g1_impl(input).is_some(); + let result = 1; Ok((MAP_FP_TO_G1_BASE, B256::with_last_byte(result as u8).into())) } -fn map_fp_to_g1_impl(_input: &[u8]) -> Option<()> { - None -} - /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_MAP_FP2_TO_G2 precompile. pub const BLS12_MAP_FP2_TO_G2: PrecompileWithAddress = PrecompileWithAddress( crate::u64_to_address(BLS12_MAP_FP2_TO_G2_ADDRESS), Precompile::Standard(map_fp2_to_g2), ); -fn map_fp2_to_g2(input: &Bytes, gas_limit: u64) -> PrecompileResult { +fn map_fp2_to_g2(_input: &Bytes, gas_limit: u64) -> PrecompileResult { // TODO: make gas base depend on input k const MAP_FP2_TO_G2_BASE: u64 = 12000; if MAP_FP2_TO_G2_BASE > gas_limit { return Err(PrecompileError::OutOfGas); } - let result = map_fp2_to_g2_impl(input).is_some(); + let result = 1; Ok((MAP_FP2_TO_G2_BASE, B256::with_last_byte(result as u8).into())) } -fn map_fp2_to_g2_impl(_input: &[u8]) -> Option<()> { - None -} - #[cfg(test)] mod test { use super::*; From 9cccfe7d7f1ed58e0b97ff58770844af80c085cd Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Tue, 19 Mar 2024 12:58:03 +0100 Subject: [PATCH 05/36] use bls12_381 crate, g1add complete --- crates/precompile/src/bls12_381.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/precompile/src/bls12_381.rs b/crates/precompile/src/bls12_381.rs index 76b03db..92d4f2a 100644 --- a/crates/precompile/src/bls12_381.rs +++ b/crates/precompile/src/bls12_381.rs @@ -36,6 +36,9 @@ pub fn precompiles() -> impl Iterator { const G1ADD_BASE: u64 = 500; const INPUT_LENGTH: usize = 256; const OUTPUT_LENGTH: usize = 128; +const FP_LEGTH: usize = 48; +const PADDED_INPUT_LENGTH: usize = 64; +const PADDING_LEGTH: usize = 16; /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G1ADD precompile. const BLS12_G1ADD: PrecompileWithAddress = @@ -119,6 +122,20 @@ fn extract_g1_input(input: &[u8]) -> Result { } Ok(output.unwrap()) } + + let input_p0_x = match remove_padding(&input[..64]) { + Ok(input_p0_x) => input_p0_x, + Err(e) => return Err(e), + }; + let input_p0_y = match remove_padding(&input[64..128]) { + Ok(input_p0_y) => input_p0_y, + Err(e) => return Err(e), + }; + let mut input_p0: [u8; 96] = [0; 96]; + input_p0[..48].copy_from_slice(&input_p0_x); + input_p0[48..].copy_from_slice(&input_p0_y); + + Ok(input_p0) } // G1 addition call expects `256` bytes as an input that is interpreted as byte From 86cd95c5ed3085130bc81340c8664d5ae3174bc9 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Tue, 19 Mar 2024 16:16:50 +0100 Subject: [PATCH 06/36] more tests and take into account point of inifinity; more constants --- crates/precompile/src/bls12_381.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/precompile/src/bls12_381.rs b/crates/precompile/src/bls12_381.rs index 92d4f2a..c710504 100644 --- a/crates/precompile/src/bls12_381.rs +++ b/crates/precompile/src/bls12_381.rs @@ -35,10 +35,12 @@ pub fn precompiles() -> impl Iterator { const G1ADD_BASE: u64 = 500; const INPUT_LENGTH: usize = 256; +const INPUT_ITEM_LENGTH: usize = 128; const OUTPUT_LENGTH: usize = 128; const FP_LEGTH: usize = 48; const PADDED_INPUT_LENGTH: usize = 64; const PADDING_LEGTH: usize = 16; +const FP_CONCAT_LENGTH: usize = 96; /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G1ADD precompile. const BLS12_G1ADD: PrecompileWithAddress = @@ -123,17 +125,17 @@ fn extract_g1_input(input: &[u8]) -> Result { Ok(output.unwrap()) } - let input_p0_x = match remove_padding(&input[..64]) { + let input_p0_x = match remove_padding(&input[..PADDED_INPUT_LENGTH]) { Ok(input_p0_x) => input_p0_x, Err(e) => return Err(e), }; - let input_p0_y = match remove_padding(&input[64..128]) { + let input_p0_y = match remove_padding(&input[PADDED_INPUT_LENGTH..INPUT_ITEM_LENGTH]) { Ok(input_p0_y) => input_p0_y, Err(e) => return Err(e), }; - let mut input_p0: [u8; 96] = [0; 96]; - input_p0[..48].copy_from_slice(&input_p0_x); - input_p0[48..].copy_from_slice(&input_p0_y); + let mut input_p0: [u8; FP_CONCAT_LENGTH] = [0; FP_CONCAT_LENGTH]; + input_p0[..FP_LEGTH].copy_from_slice(&input_p0_x); + input_p0[FP_LEGTH..].copy_from_slice(&input_p0_y); Ok(input_p0) } From 9f36fe02c90fcfa40b242eaecbe826f8a95baa2a Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Wed, 20 Mar 2024 10:53:19 +0100 Subject: [PATCH 07/36] typo --- crates/precompile/src/bls12_381.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/precompile/src/bls12_381.rs b/crates/precompile/src/bls12_381.rs index c710504..c8716cd 100644 --- a/crates/precompile/src/bls12_381.rs +++ b/crates/precompile/src/bls12_381.rs @@ -37,7 +37,7 @@ const G1ADD_BASE: u64 = 500; const INPUT_LENGTH: usize = 256; const INPUT_ITEM_LENGTH: usize = 128; const OUTPUT_LENGTH: usize = 128; -const FP_LEGTH: usize = 48; +const FP_LENGTH: usize = 48; const PADDED_INPUT_LENGTH: usize = 64; const PADDING_LEGTH: usize = 16; const FP_CONCAT_LENGTH: usize = 96; From 41074beec5f9f95e29253644b138c051b33d590d Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Wed, 20 Mar 2024 22:11:42 +0100 Subject: [PATCH 08/36] add insert_precompiles function --- crates/precompile/src/bls12_381.rs | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/crates/precompile/src/bls12_381.rs b/crates/precompile/src/bls12_381.rs index c8716cd..dfed700 100644 --- a/crates/precompile/src/bls12_381.rs +++ b/crates/precompile/src/bls12_381.rs @@ -42,6 +42,22 @@ const PADDED_INPUT_LENGTH: usize = 64; const PADDING_LEGTH: usize = 16; const FP_CONCAT_LENGTH: usize = 96; +/// bls12381 precompiles +pub fn precompiles() -> impl Iterator { + [ + BLS12_G1ADD, + BLS12_G1MUL, + BLS12_G1MULTIEXP, + BLS12_G2ADD, + BLS12_G2MUL, + BLS12_G2MULTIEXP, + BLS12_PAIRING, + BLS12_MAP_FP_TO_G1, + BLS12_MAP_FP2_TO_G2, + ] + .into_iter() +} + /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G1ADD precompile. const BLS12_G1ADD: PrecompileWithAddress = PrecompileWithAddress(crate::u64_to_address(BLS12_G1ADD_ADDRESS), Precompile::Standard(g1_add)); @@ -308,7 +324,7 @@ fn g1_mul(_input: &Bytes, gas_limit: u64) -> PrecompileResult { } /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G1MULTIEXP precompile. -pub const BLS12_G1MULTIEXP: PrecompileWithAddress = PrecompileWithAddress( +const BLS12_G1MULTIEXP: PrecompileWithAddress = PrecompileWithAddress( crate::u64_to_address(BLS12_G1MULTIEXP_ADDRESS), Precompile::Standard(g1_multiexp), ); @@ -324,7 +340,7 @@ fn g1_multiexp(_input: &Bytes, gas_limit: u64) -> PrecompileResult { } /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G2ADD precompile. -pub const BLS12_G2ADD: PrecompileWithAddress = +const BLS12_G2ADD: PrecompileWithAddress = PrecompileWithAddress(crate::u64_to_address(BLS12_G2ADD_ADDRESS), Precompile::Standard(g2_add)); fn g2_add(_input: &Bytes, gas_limit: u64) -> PrecompileResult { @@ -337,7 +353,7 @@ fn g2_add(_input: &Bytes, gas_limit: u64) -> PrecompileResult { } /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G2MUL precompile. -pub const BLS12_G2MUL: PrecompileWithAddress = +const BLS12_G2MUL: PrecompileWithAddress = PrecompileWithAddress(crate::u64_to_address(BLS12_G2MUL_ADDRESS), Precompile::Standard(g2_mul)); fn g2_mul(_input: &Bytes, gas_limit: u64) -> PrecompileResult { @@ -350,7 +366,7 @@ fn g2_mul(_input: &Bytes, gas_limit: u64) -> PrecompileResult { } /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G2MULTIEXP precompile. -pub const BLS12_G2MULTIEXP: PrecompileWithAddress = PrecompileWithAddress( +const BLS12_G2MULTIEXP: PrecompileWithAddress = PrecompileWithAddress( crate::u64_to_address(BLS12_G2MULTIEXP_ADDRESS), Precompile::Standard(g2_multiexp), ); @@ -366,7 +382,7 @@ fn g2_multiexp(_input: &Bytes, gas_limit: u64) -> PrecompileResult { } /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_PAIRING precompile. -pub const BLS12_PAIRING: PrecompileWithAddress = PrecompileWithAddress( +const BLS12_PAIRING: PrecompileWithAddress = PrecompileWithAddress( crate::u64_to_address(BLS12_PAIRING_ADDRESS), Precompile::Standard(pairing), ); @@ -382,7 +398,7 @@ fn pairing(_input: &Bytes, gas_limit: u64) -> PrecompileResult { } /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_MAP_FP_TO_G1 precompile. -pub const BLS12_MAP_FP_TO_G1: PrecompileWithAddress = PrecompileWithAddress( +const BLS12_MAP_FP_TO_G1: PrecompileWithAddress = PrecompileWithAddress( crate::u64_to_address(BLS12_MAP_FP_TO_G1_ADDRESS), Precompile::Standard(map_fp_to_g1), ); @@ -398,7 +414,7 @@ fn map_fp_to_g1(_input: &Bytes, gas_limit: u64) -> PrecompileResult { } /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_MAP_FP2_TO_G2 precompile. -pub const BLS12_MAP_FP2_TO_G2: PrecompileWithAddress = PrecompileWithAddress( +const BLS12_MAP_FP2_TO_G2: PrecompileWithAddress = PrecompileWithAddress( crate::u64_to_address(BLS12_MAP_FP2_TO_G2_ADDRESS), Precompile::Standard(map_fp2_to_g2), ); From a8e2a482c9857824ba72525bd7217497fb560867 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Thu, 21 Mar 2024 18:21:32 +0100 Subject: [PATCH 09/36] feat: set authorized context variable in AUTH --- Cargo.lock | 630 ++++++++++++++--------------- Cargo.toml | 22 +- bin/alphanet/Cargo.toml | 6 +- bin/alphanet/src/main.rs | 2 +- crates/instructions/Cargo.toml | 2 +- crates/instructions/src/eip3074.rs | 21 +- 6 files changed, 322 insertions(+), 361 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7837897..3df2542 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -124,7 +124,7 @@ checksum = "e96c81b05c893348760f232c4cc6a6a77fd91cfb09885d4eaad25cd03bd7732e" dependencies = [ "alloy-rlp", "arbitrary", - "num_enum 0.7.2", + "num_enum", "proptest", "serde", "strum 0.26.2", @@ -151,20 +151,20 @@ dependencies = [ [[package]] name = "alloy-eips" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=9ac2c90#9ac2c90d58a9994d4b61c879e33c6af2739a2b4f" +source = "git+https://github.com/alloy-rs/alloy?rev=410850b#410850b305a28297483d819b669b04ba31796359" dependencies = [ "alloy-primitives", "alloy-rlp", - "thiserror", + "serde", ] [[package]] name = "alloy-genesis" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=9ac2c90#9ac2c90d58a9994d4b61c879e33c6af2739a2b4f" +source = "git+https://github.com/alloy-rs/alloy?rev=410850b#410850b305a28297483d819b669b04ba31796359" dependencies = [ "alloy-primitives", - "alloy-rpc-types", + "alloy-serde", "serde", ] @@ -232,11 +232,12 @@ dependencies = [ [[package]] name = "alloy-rpc-engine-types" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=9ac2c90#9ac2c90d58a9994d4b61c879e33c6af2739a2b4f" +source = "git+https://github.com/alloy-rs/alloy?rev=410850b#410850b305a28297483d819b669b04ba31796359" dependencies = [ "alloy-primitives", "alloy-rlp", "alloy-rpc-types", + "alloy-serde", "jsonrpsee-types", "serde", "thiserror", @@ -245,10 +246,11 @@ dependencies = [ [[package]] name = "alloy-rpc-trace-types" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=9ac2c90#9ac2c90d58a9994d4b61c879e33c6af2739a2b4f" +source = "git+https://github.com/alloy-rs/alloy?rev=410850b#410850b305a28297483d819b669b04ba31796359" dependencies = [ "alloy-primitives", "alloy-rpc-types", + "alloy-serde", "serde", "serde_json", ] @@ -256,10 +258,11 @@ dependencies = [ [[package]] name = "alloy-rpc-types" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=9ac2c90#9ac2c90d58a9994d4b61c879e33c6af2739a2b4f" +source = "git+https://github.com/alloy-rs/alloy?rev=410850b#410850b305a28297483d819b669b04ba31796359" dependencies = [ "alloy-primitives", "alloy-rlp", + "alloy-serde", "arbitrary", "itertools 0.12.1", "jsonrpsee-types", @@ -270,6 +273,16 @@ dependencies = [ "thiserror", ] +[[package]] +name = "alloy-serde" +version = "0.1.0" +source = "git+https://github.com/alloy-rs/alloy?rev=410850b#410850b305a28297483d819b669b04ba31796359" +dependencies = [ + "alloy-primitives", + "serde", + "serde_json", +] + [[package]] name = "alloy-sol-macro" version = "0.6.4" @@ -334,10 +347,12 @@ name = "alphanet" version = "0.0.0" dependencies = [ "alphanet-node", - "clap", - "jemallocator", + "eyre", "reth", "reth-node-optimism", + "reth-tracing", + "tikv-jemallocator", + "tokio", "tracing", ] @@ -347,6 +362,7 @@ version = "0.0.0" dependencies = [ "revm", "revm-interpreter", + "revm-precompile", "revm-primitives", "secp256k1 0.28.2", ] @@ -877,9 +893,9 @@ dependencies = [ [[package]] name = "boa_ast" -version = "0.17.3" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73498e9b2f0aa7db74977afa4d594657611e90587abf0dd564c0b55b4a130163" +checksum = "5b6fb81ca0f301f33aff7401e2ffab37dc9e0e4a1cf0ccf6b34f4d9e60aa0682" dependencies = [ "bitflags 2.5.0", "boa_interner", @@ -891,30 +907,34 @@ dependencies = [ [[package]] name = "boa_engine" -version = "0.17.3" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16377479d5d6d33896e7acdd1cc698d04a8f72004025bbbddf47558cd29146a6" +checksum = "600e4e4a65b26efcef08a7b1cf2899d3845a32e82e067ee3b75eaf7e413ff31c" dependencies = [ "bitflags 2.5.0", "boa_ast", "boa_gc", - "boa_icu_provider", "boa_interner", "boa_macros", "boa_parser", "boa_profiler", - "chrono", + "bytemuck", + "cfg-if", "dashmap", "fast-float", + "hashbrown 0.14.3", "icu_normalizer", "indexmap 2.2.5", - "itertools 0.11.0", + "intrusive-collections", + "itertools 0.12.1", "num-bigint", "num-integer", "num-traits", - "num_enum 0.6.1", + "num_enum", "once_cell", + "paste", "pollster", + "portable-atomic", "rand 0.8.5", "regress", "rustc-hash", @@ -926,39 +946,26 @@ dependencies = [ "tap", "thin-vec", "thiserror", + "time", ] [[package]] name = "boa_gc" -version = "0.17.3" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c97b44beaef9d4452342d117d94607fdfa8d474280f1ba0fd97853834e3a49b2" +checksum = "c055ef3cd87ea7db014779195bc90c6adfc35de4902e3b2fe587adecbd384578" dependencies = [ "boa_macros", "boa_profiler", + "hashbrown 0.14.3", "thin-vec", ] -[[package]] -name = "boa_icu_provider" -version = "0.17.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b30e52e34e451dd0bfc2c654a9a43ed34b0073dbd4ae3394b40313edda8627aa" -dependencies = [ - "icu_collections", - "icu_normalizer", - "icu_properties", - "icu_provider", - "icu_provider_adapters", - "icu_provider_blob", - "once_cell", -] - [[package]] name = "boa_interner" -version = "0.17.3" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3e5afa991908cfbe79bd3109b824e473a1dc5f74f31fab91bb44c9e245daa77" +checksum = "0cacc9caf022d92195c827a3e5bf83f96089d4bfaff834b359ac7b6be46e9187" dependencies = [ "boa_gc", "boa_macros", @@ -972,9 +979,9 @@ dependencies = [ [[package]] name = "boa_macros" -version = "0.17.3" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "005fa0c5bd20805466dda55eb34cd709bb31a2592bb26927b47714eeed6914d8" +checksum = "6be9c93793b60dac381af475b98634d4b451e28336e72218cad9a20176218dbc" dependencies = [ "proc-macro2", "quote", @@ -984,34 +991,28 @@ dependencies = [ [[package]] name = "boa_parser" -version = "0.17.3" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e09afb035377a9044443b598187a7d34cd13164617182a4d7c348522ee3f052" +checksum = "9e8592556849f0619ed142ce2b3a19086769314a8d657f93a5765d06dbce4818" dependencies = [ "bitflags 2.5.0", "boa_ast", - "boa_icu_provider", "boa_interner", "boa_macros", "boa_profiler", "fast-float", - "icu_locid", "icu_properties", - "icu_provider", - "icu_provider_macros", "num-bigint", "num-traits", - "once_cell", "regress", "rustc-hash", - "tinystr", ] [[package]] name = "boa_profiler" -version = "0.17.3" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3190f92dfe48224adc92881c620f08ccf37ff62b91a094bb357fe53bd5e84647" +checksum = "e0d8372f2d5cbac600a260de87877141b42da1e18d2c7a08ccb493a49cbd55c0" [[package]] name = "boyer-moore-magiclen" @@ -1089,9 +1090,9 @@ dependencies = [ [[package]] name = "c-kzg" -version = "0.4.2" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94a4bc5367b6284358d2a6a6a1dc2d92ec4b86034561c3b9d3341909752fd848" +checksum = "3130f3d8717cc02e668a896af24984d5d5d4e8bf12e278e982e0f1bd88a0f9af" dependencies = [ "blst", "cc", @@ -1249,12 +1250,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" -[[package]] -name = "cobs" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" - [[package]] name = "colorchoice" version = "1.0.0" @@ -1273,6 +1268,15 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "concat-kdf" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d72c1252426a83be2092dd5884a5f6e3b8e7180f6891b6263d2c21b92ec8816" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "confy" version = "0.6.1" @@ -1386,12 +1390,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "critical-section" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" - [[package]] name = "crossbeam-channel" version = "0.5.12" @@ -1954,12 +1952,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "embedded-io" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" - [[package]] name = "encode_unicode" version = "0.3.6" @@ -2708,12 +2700,11 @@ dependencies = [ [[package]] name = "icu_collections" -version = "1.2.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef8302d8dfd6044d3ddb3f807a5ef3d7bbca9a574959c6d6e4dc39aa7012d0d5" +checksum = "137d96353afc8544d437e8a99eceb10ab291352699573b0de5b08bda38c78c60" dependencies = [ "displaydoc", - "serde", "yoke", "zerofrom", "zerovec", @@ -2721,29 +2712,48 @@ dependencies = [ [[package]] name = "icu_locid" -version = "1.2.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3003f85dccfc0e238ff567693248c59153a46f4e6125ba4020b973cef4d1d335" +checksum = "5c0aa2536adc14c07e2a521e95512b75ed8ef832f0fdf9299d4a0a45d2be2a9d" dependencies = [ "displaydoc", "litemap", - "serde", "tinystr", "writeable", "zerovec", ] +[[package]] +name = "icu_locid_transform" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c17d8f6524fdca4471101dd71f0a132eb6382b5d6d7f2970441cb25f6f435a" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "545c6c3e8bf9580e2dafee8de6f9ec14826aaf359787789c7724f1f85f47d3dc" + [[package]] name = "icu_normalizer" -version = "1.2.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "652869735c9fb9f5a64ba180ee16f2c848390469c116deef517ecc53f4343598" +checksum = "c183e31ed700f1ecd6b032d104c52fe8b15d028956b73727c97ec176b170e187" dependencies = [ "displaydoc", "icu_collections", + "icu_normalizer_data", "icu_properties", "icu_provider", - "serde", "smallvec", "utf16_iter", "utf8_iter", @@ -2751,75 +2761,59 @@ dependencies = [ "zerovec", ] +[[package]] +name = "icu_normalizer_data" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22026918a80e6a9a330cb01b60f950e2b4e5284c59528fd0c6150076ef4c8522" + [[package]] name = "icu_properties" -version = "1.2.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce0e1aa26851f16c9e04412a5911c86b7f8768dac8f8d4c5f1c568a7e5d7a434" +checksum = "976e296217453af983efa25f287a4c1da04b9a63bf1ed63719455068e4453eb5" dependencies = [ "displaydoc", "icu_collections", + "icu_locid_transform", + "icu_properties_data", "icu_provider", - "serde", "tinystr", "zerovec", ] +[[package]] +name = "icu_properties_data" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6a86c0e384532b06b6c104814f9c1b13bcd5b64409001c0d05713a1f3529d99" + [[package]] name = "icu_provider" -version = "1.2.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dc312a7b6148f7dfe098047ae2494d12d4034f48ade58d4f353000db376e305" +checksum = "ba58e782287eb6950247abbf11719f83f5d4e4a5c1f2cd490d30a334bc47c2f4" dependencies = [ "displaydoc", "icu_locid", "icu_provider_macros", - "postcard", - "serde", "stable_deref_trait", - "writeable", - "yoke", - "zerofrom", - "zerovec", -] - -[[package]] -name = "icu_provider_adapters" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4ae1e2bd0c41728b77e7c46e9afdec5e2127d1eedacc684724667d50c126bd3" -dependencies = [ - "icu_locid", - "icu_provider", - "serde", "tinystr", - "yoke", - "zerovec", -] - -[[package]] -name = "icu_provider_blob" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd364c9a01f791a4bc04a74cf2a1d01d9f6926a40fd5ae1c28004e1e70d8338b" -dependencies = [ - "icu_provider", - "postcard", - "serde", "writeable", "yoke", + "zerofrom", "zerovec", ] [[package]] name = "icu_provider_macros" -version = "1.2.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b728b9421e93eff1d9f8681101b78fa745e0748c95c655c83f337044a7e10" +checksum = "d2abdd3a62551e8337af119c5899e600ca0c88ec8f23a46c60ba216c803dcf1a" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.52", ] [[package]] @@ -2988,6 +2982,15 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "intrusive-collections" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b694dc9f70c3bda874626d2aed13b780f137aab435f4e9814121955cf706122e" +dependencies = [ + "memoffset", +] + [[package]] name = "ipconfig" version = "0.3.2" @@ -3025,15 +3028,6 @@ dependencies = [ "either", ] -[[package]] -name = "itertools" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" -dependencies = [ - "either", -] - [[package]] name = "itertools" version = "0.12.1" @@ -3049,37 +3043,6 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" -[[package]] -name = "jemalloc-ctl" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cffc705424a344c054e135d12ee591402f4539245e8bbd64e6c9eaa9458b63c" -dependencies = [ - "jemalloc-sys", - "libc", - "paste", -] - -[[package]] -name = "jemalloc-sys" -version = "0.5.4+5.3.0-patched" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac6c1946e1cea1788cbfde01c993b52a10e2da07f4bac608228d1bed20bfebf2" -dependencies = [ - "cc", - "libc", -] - -[[package]] -name = "jemallocator" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0de374a9f8e63150e6f5e8a60cc14c668226d7a347d8aee1a45766e3c4dd3bc" -dependencies = [ - "jemalloc-sys", - "libc", -] - [[package]] name = "jobserver" version = "0.1.28" @@ -3496,6 +3459,15 @@ dependencies = [ "libc", ] +[[package]] +name = "memoffset" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +dependencies = [ + "autocfg", +] + [[package]] name = "metrics" version = "0.21.1" @@ -3762,15 +3734,6 @@ dependencies = [ "libc", ] -[[package]] -name = "num_enum" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a015b430d3c108a207fd776d2e2196aaf8b1cf8cf93253e3a097ff3085076a1" -dependencies = [ - "num_enum_derive 0.6.1", -] - [[package]] name = "num_enum" version = "0.7.2" @@ -3798,6 +3761,7 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" dependencies = [ + "proc-macro-crate 2.0.0", "proc-macro2", "quote", "syn 2.0.53", @@ -3840,10 +3804,6 @@ name = "once_cell" version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -dependencies = [ - "critical-section", - "portable-atomic", -] [[package]] name = "opaque-debug" @@ -4172,17 +4132,6 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" -[[package]] -name = "postcard" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a55c51ee6c0db07e68448e336cf8ea4131a620edefebf9893e759b2d793420f8" -dependencies = [ - "cobs", - "embedded-io", - "serde", -] - [[package]] name = "powerfmt" version = "0.2.0" @@ -4597,11 +4546,11 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "regress" -version = "0.6.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82a9ecfa0cb04d0b04dddb99b8ccf4f66bc8dfd23df694b398570bd8ae3a50fb" +checksum = "d06f9a1f7cd8473611ba1a480cf35f9c5cffc2954336ba90a982fdb7e7d7f51e" dependencies = [ - "hashbrown 0.13.2", + "hashbrown 0.14.3", "memchr", ] @@ -4664,8 +4613,8 @@ dependencies = [ [[package]] name = "reth" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "alloy-chains", "alloy-rlp", @@ -4681,7 +4630,6 @@ dependencies = [ "futures", "human_bytes", "itertools 0.12.1", - "jemallocator", "libc", "metrics-process", "proptest", @@ -4707,7 +4655,6 @@ dependencies = [ "reth-node-core", "reth-node-ethereum", "reth-node-optimism", - "reth-optimism-payload-builder", "reth-payload-builder", "reth-payload-validator", "reth-primitives", @@ -4730,6 +4677,7 @@ dependencies = [ "serde_json", "similar-asserts", "tempfile", + "tikv-jemallocator", "tokio", "toml", "tracing", @@ -4737,8 +4685,8 @@ dependencies = [ [[package]] name = "reth-auto-seal-consensus" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "futures-util", "reth-beacon-consensus", @@ -4756,8 +4704,8 @@ dependencies = [ [[package]] name = "reth-basic-payload-builder" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "alloy-rlp", "futures-core", @@ -4779,8 +4727,8 @@ dependencies = [ [[package]] name = "reth-beacon-consensus" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "futures", "metrics", @@ -4808,8 +4756,8 @@ dependencies = [ [[package]] name = "reth-beacon-consensus-core" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "reth-consensus-common", "reth-interfaces", @@ -4818,8 +4766,8 @@ dependencies = [ [[package]] name = "reth-blockchain-tree" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "aquamarine", "linked_hash_set", @@ -4839,8 +4787,8 @@ dependencies = [ [[package]] name = "reth-codecs" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "alloy-primitives", "bytes", @@ -4849,8 +4797,8 @@ dependencies = [ [[package]] name = "reth-codecs-derive" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "convert_case 0.6.0", "proc-macro2", @@ -4860,8 +4808,8 @@ dependencies = [ [[package]] name = "reth-config" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "humantime-serde", "reth-discv4", @@ -4874,8 +4822,8 @@ dependencies = [ [[package]] name = "reth-consensus-common" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "reth-interfaces", "reth-primitives", @@ -4884,8 +4832,8 @@ dependencies = [ [[package]] name = "reth-db" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "arbitrary", "bytes", @@ -4915,8 +4863,8 @@ dependencies = [ [[package]] name = "reth-discv4" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "alloy-rlp", "discv5", @@ -4937,8 +4885,8 @@ dependencies = [ [[package]] name = "reth-dns-discovery" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "alloy-rlp", "data-encoding", @@ -4960,8 +4908,8 @@ dependencies = [ [[package]] name = "reth-downloaders" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "alloy-rlp", "futures", @@ -4985,14 +4933,15 @@ dependencies = [ [[package]] name = "reth-ecies" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "aes 0.8.4", "alloy-rlp", "block-padding", "byteorder", "cipher 0.4.4", + "concat-kdf", "ctr 0.9.2", "digest 0.10.7", "educe", @@ -5016,8 +4965,8 @@ dependencies = [ [[package]] name = "reth-eth-wire" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "alloy-chains", "alloy-rlp", @@ -5042,8 +4991,8 @@ dependencies = [ [[package]] name = "reth-ethereum-forks" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "alloy-chains", "alloy-primitives", @@ -5058,8 +5007,8 @@ dependencies = [ [[package]] name = "reth-ethereum-payload-builder" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "reth-basic-payload-builder", "reth-payload-builder", @@ -5073,8 +5022,8 @@ dependencies = [ [[package]] name = "reth-etl" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "rayon", "reth-db", @@ -5083,15 +5032,14 @@ dependencies = [ [[package]] name = "reth-interfaces" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "auto_impl", "clap", "futures", "reth-eth-wire", "reth-network-api", - "reth-nippy-jar", "reth-primitives", "reth-rpc-types", "thiserror", @@ -5101,8 +5049,8 @@ dependencies = [ [[package]] name = "reth-ipc" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "async-trait", "bytes", @@ -5121,8 +5069,8 @@ dependencies = [ [[package]] name = "reth-libmdbx" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "bitflags 2.5.0", "byteorder", @@ -5139,8 +5087,8 @@ dependencies = [ [[package]] name = "reth-mdbx-sys" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "bindgen", "cc", @@ -5149,8 +5097,8 @@ dependencies = [ [[package]] name = "reth-metrics" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "futures", "metrics", @@ -5161,8 +5109,8 @@ dependencies = [ [[package]] name = "reth-metrics-derive" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "once_cell", "proc-macro2", @@ -5173,8 +5121,8 @@ dependencies = [ [[package]] name = "reth-net-common" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "pin-project", "reth-primitives", @@ -5183,8 +5131,8 @@ dependencies = [ [[package]] name = "reth-net-nat" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "igd-next", "pin-project-lite", @@ -5197,8 +5145,8 @@ dependencies = [ [[package]] name = "reth-network" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "alloy-rlp", "aquamarine", @@ -5243,8 +5191,8 @@ dependencies = [ [[package]] name = "reth-network-api" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "alloy-chains", "reth-discv4", @@ -5258,8 +5206,8 @@ dependencies = [ [[package]] name = "reth-nippy-jar" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "anyhow", "bincode", @@ -5278,8 +5226,8 @@ dependencies = [ [[package]] name = "reth-node-api" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "reth-primitives", "reth-rpc-types", @@ -5291,8 +5239,8 @@ dependencies = [ [[package]] name = "reth-node-builder" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "confy", "eyre", @@ -5324,11 +5272,9 @@ dependencies = [ [[package]] name = "reth-node-core" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ - "alloy-chains", - "alloy-rlp", "clap", "const-str", "derive_more", @@ -5337,7 +5283,6 @@ dependencies = [ "futures", "humantime", "hyper", - "jemalloc-ctl", "metrics", "metrics-exporter-prometheus", "metrics-process", @@ -5347,7 +5292,6 @@ dependencies = [ "procfs", "rand 0.8.5", "reth-auto-seal-consensus", - "reth-basic-payload-builder", "reth-beacon-consensus", "reth-blockchain-tree", "reth-config", @@ -5355,15 +5299,12 @@ dependencies = [ "reth-db", "reth-discv4", "reth-downloaders", - "reth-eth-wire", "reth-interfaces", "reth-metrics", "reth-net-nat", "reth-network", "reth-network-api", "reth-node-api", - "reth-optimism-payload-builder", - "reth-payload-builder", "reth-primitives", "reth-provider", "reth-prune", @@ -5379,12 +5320,12 @@ dependencies = [ "reth-tasks", "reth-tracing", "reth-transaction-pool", - "revm-inspectors", "secp256k1 0.27.0", "serde", "serde_json", "shellexpand", "thiserror", + "tikv-jemalloc-ctl", "tokio", "tracing", "vergen", @@ -5392,8 +5333,8 @@ dependencies = [ [[package]] name = "reth-node-ethereum" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "eyre", "reth-basic-payload-builder", @@ -5412,8 +5353,8 @@ dependencies = [ [[package]] name = "reth-node-optimism" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "clap", "eyre", @@ -5438,24 +5379,29 @@ dependencies = [ [[package]] name = "reth-optimism-payload-builder" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ + "alloy-rlp", "reth-basic-payload-builder", + "reth-node-api", "reth-payload-builder", "reth-primitives", "reth-provider", "reth-revm", + "reth-rpc-types", + "reth-rpc-types-compat", "reth-transaction-pool", "revm", + "sha2", "thiserror", "tracing", ] [[package]] name = "reth-payload-builder" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "alloy-rlp", "futures-util", @@ -5478,8 +5424,8 @@ dependencies = [ [[package]] name = "reth-payload-validator" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "reth-primitives", "reth-rpc-types", @@ -5488,8 +5434,8 @@ dependencies = [ [[package]] name = "reth-primitives" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "alloy-chains", "alloy-eips", @@ -5504,6 +5450,7 @@ dependencies = [ "cfg-if", "clap", "derive_more", + "enr", "itertools 0.12.1", "modular-bitfield", "nybbles", @@ -5520,6 +5467,7 @@ dependencies = [ "secp256k1 0.27.0", "serde", "serde_json", + "serde_with", "sha2", "strum 0.26.2", "tempfile", @@ -5529,8 +5477,8 @@ dependencies = [ [[package]] name = "reth-provider" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "alloy-rlp", "auto_impl", @@ -5557,8 +5505,8 @@ dependencies = [ [[package]] name = "reth-prune" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "itertools 0.12.1", "metrics", @@ -5577,8 +5525,8 @@ dependencies = [ [[package]] name = "reth-revm" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "reth-consensus-common", "reth-interfaces", @@ -5592,8 +5540,8 @@ dependencies = [ [[package]] name = "reth-rpc" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "alloy-dyn-abi", "alloy-primitives", @@ -5602,6 +5550,7 @@ dependencies = [ "async-trait", "bytes", "derive_more", + "dyn-clone", "futures", "http", "http-body", @@ -5609,6 +5558,7 @@ dependencies = [ "jsonrpsee", "jsonwebtoken", "metrics", + "parking_lot 0.12.1", "pin-project", "rand 0.8.5", "reqwest", @@ -5644,8 +5594,8 @@ dependencies = [ [[package]] name = "reth-rpc-api" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "jsonrpsee", "reth-node-api", @@ -5656,8 +5606,8 @@ dependencies = [ [[package]] name = "reth-rpc-builder" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "hyper", "jsonrpsee", @@ -5681,8 +5631,8 @@ dependencies = [ [[package]] name = "reth-rpc-engine-api" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "async-trait", "jsonrpsee-core", @@ -5707,9 +5657,10 @@ dependencies = [ [[package]] name = "reth-rpc-types" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ + "alloy-genesis", "alloy-primitives", "alloy-rlp", "alloy-rpc-engine-types", @@ -5729,8 +5680,8 @@ dependencies = [ [[package]] name = "reth-rpc-types-compat" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "alloy-rlp", "alloy-rpc-types", @@ -5740,8 +5691,8 @@ dependencies = [ [[package]] name = "reth-stages" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "aquamarine", "auto_impl", @@ -5751,6 +5702,7 @@ dependencies = [ "num-traits", "rayon", "reth-codecs", + "reth-config", "reth-db", "reth-etl", "reth-interfaces", @@ -5769,10 +5721,11 @@ dependencies = [ [[package]] name = "reth-static-file" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "clap", + "parking_lot 0.12.1", "rayon", "reth-db", "reth-interfaces", @@ -5786,8 +5739,8 @@ dependencies = [ [[package]] name = "reth-tasks" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "dyn-clone", "futures-util", @@ -5803,8 +5756,8 @@ dependencies = [ [[package]] name = "reth-tokio-util" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "tokio", "tokio-stream", @@ -5812,8 +5765,8 @@ dependencies = [ [[package]] name = "reth-tracing" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "clap", "eyre", @@ -5827,8 +5780,8 @@ dependencies = [ [[package]] name = "reth-transaction-pool" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "alloy-rlp", "aquamarine", @@ -5845,7 +5798,6 @@ dependencies = [ "reth-metrics", "reth-primitives", "reth-provider", - "reth-revm", "reth-tasks", "revm", "schnellru", @@ -5859,8 +5811,8 @@ dependencies = [ [[package]] name = "reth-trie" -version = "0.2.0-beta.1" -source = "git+https://github.com/paradigmxyz/reth.git?rev=82b6504#82b6504ef451edd0b466196c2c0b9f0f76ce48d6" +version = "0.2.0-beta.3" +source = "git+https://github.com/paradigmxyz/reth.git?rev=1a42b09#1a42b0929ffeb2b77e23cdfdd276d1a2e3f5820e" dependencies = [ "alloy-chains", "alloy-rlp", @@ -5878,9 +5830,9 @@ dependencies = [ [[package]] name = "revm" -version = "7.1.0" +version = "7.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "217d21144d329f21d5245b8e6a46e0d6d0a527d9917d7a087f225b161e529169" +checksum = "24fd3ed4b62dc61c647552d8b781811ae25ec74d23309055077e4dfb392444d2" dependencies = [ "auto_impl", "cfg-if", @@ -5894,7 +5846,7 @@ dependencies = [ [[package]] name = "revm-inspectors" version = "0.1.0" -source = "git+https://github.com/paradigmxyz/evm-inspectors?rev=1f935e7#1f935e71849466c297a64df0b162e6ffd48da25b" +source = "git+https://github.com/paradigmxyz/evm-inspectors?rev=2b48b65#2b48b65f3880803f51883948c319012da09ecba7" dependencies = [ "alloy-primitives", "alloy-rpc-trace-types", @@ -5911,9 +5863,9 @@ dependencies = [ [[package]] name = "revm-interpreter" -version = "3.3.0" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "776848391ed76d5103ca1aa1632cd21b521e2870afb30b63723da862d69efd0f" +checksum = "9f0a1818f8c876b0d71a0714217c34da7df8a42c0462750768779d55680e4554" dependencies = [ "revm-primitives", "serde", @@ -5921,9 +5873,9 @@ dependencies = [ [[package]] name = "revm-precompile" -version = "5.0.0" +version = "5.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3fd1856a7cb09197a02669d779e1afb5a627b0888a24814ba2b6a1ad4c3ff8d" +checksum = "7a9645a70f1df1e5bd7fa8718b9ba486fac9c3f0467aa6b58e7f590d5f6fd0f7" dependencies = [ "aurora-engine-modexp", "c-kzg", @@ -5938,9 +5890,9 @@ dependencies = [ [[package]] name = "revm-primitives" -version = "3.0.0" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a4d7d3e793e907dc0797a9d3b43abfdf5226d133855214db9bd27d4cee33ebd" +checksum = "323ad597cf75ac9cb1d161be29fcc3562426f0278a1d04741697fca556e1ceea" dependencies = [ "alloy-primitives", "auto_impl", @@ -6228,9 +6180,9 @@ checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" [[package]] name = "ryu-js" -version = "0.2.2" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6518fc26bced4d53678a22d6e423e9d8716377def84545fe328236e3af070e7f" +checksum = "ad97d4ce1560a5e27cec89519dc8300d1aa6035b099821261c651486a19e44d5" [[package]] name = "schannel" @@ -6958,6 +6910,37 @@ dependencies = [ "num_cpus", ] +[[package]] +name = "tikv-jemalloc-ctl" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "619bfed27d807b54f7f776b9430d4f8060e66ee138a28632ca898584d462c31c" +dependencies = [ + "libc", + "paste", + "tikv-jemalloc-sys", +] + +[[package]] +name = "tikv-jemalloc-sys" +version = "0.5.4+5.3.0-patched" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9402443cb8fd499b6f327e40565234ff34dbda27460c5b47db0db77443dd85d1" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "tikv-jemallocator" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "965fe0c26be5c56c94e38ba547249074803efd52adfb66de62107d95aab3eaca" +dependencies = [ + "libc", + "tikv-jemalloc-sys", +] + [[package]] name = "time" version = "0.3.34" @@ -6966,6 +6949,7 @@ checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" dependencies = [ "deranged", "itoa", + "js-sys", "libc", "num-conv", "num_threads", @@ -7002,12 +6986,11 @@ dependencies = [ [[package]] name = "tinystr" -version = "0.7.2" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8faa444297615a4e020acb64146b0603c9c395c03a97c17fd9028816d3b4d63e" +checksum = "83c02bf3c538ab32ba913408224323915f4ef9a6d61c0e85d493f355921c0ece" dependencies = [ "displaydoc", - "serde", "zerovec", ] @@ -8042,11 +8025,10 @@ dependencies = [ [[package]] name = "zerovec" -version = "0.9.6" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "591691014119b87047ead4dcf3e6adfbf73cb7c38ab6980d4f18a32138f35d46" +checksum = "eff4439ae91fb5c72b8abc12f3f2dbf51bd27e6eadb9f8a5bc8898dddb0e27ea" dependencies = [ - "serde", "yoke", "zerofrom", "zerovec-derive", @@ -8054,9 +8036,9 @@ dependencies = [ [[package]] name = "zerovec-derive" -version = "0.9.6" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a4a1638a1934450809c2266a70362bfc96cd90550c073f5b8a55014d1010157" +checksum = "7b4e5997cbf58990550ef1f0e5124a05e47e1ebd33a84af25739be6031a62c20" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index dfb1b21..ba5939d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,25 +50,21 @@ alphanet-precompile = { path = "crates/precompile" } tokio = { version = "1.21", default-features = false } # reth -reth = { git = "https://github.com/paradigmxyz/reth.git", rev = "82b6504", features = ["optimism"] } -reth-node-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "82b6504" } -reth-node-optimism = { git = "https://github.com/paradigmxyz/reth.git", rev = "82b6504" } -reth-tracing = { git = "https://github.com/paradigmxyz/reth.git", rev = "82b6504" } +reth = { git = "https://github.com/paradigmxyz/reth.git", rev = "1a42b09", features = ["optimism"] } +reth-node-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "1a42b09" } +reth-node-optimism = { git = "https://github.com/paradigmxyz/reth.git", rev = "1a42b09" } +reth-tracing = { git = "https://github.com/paradigmxyz/reth.git", rev = "1a42b09" } # revm -revm = { version = "7.1.0", features = ["std", "secp256k1"], default-features = false } -revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors", rev = "1f935e7" } -revm-interpreter = { version = "3.3.0", features = ["std"], default-features = false } -revm-precompile = { version = "5.0.0", features = ["std"], default-features = false } -revm-primitives = { version = "3.0.0", features = ["std"], default-features = false } +revm = { version = "7.2.0", features = ["std", "secp256k1"], default-features = false } +revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors", rev = "2b48b65" } +revm-interpreter = { version = "3.4.0", features = ["std"], default-features = false } +revm-precompile = { version = "5.1.0", features = ["std"], default-features = false } +revm-primitives = { version = "3.1.0", features = ["std"], default-features = false } # misc clap = "4" eyre = "0.6.12" -secp256k1 = { version = "0.28.2", default-features = false, features = [ - "alloc", - "recovery", -] } tracing = "0.1.0" # misc-testing diff --git a/bin/alphanet/Cargo.toml b/bin/alphanet/Cargo.toml index b300394..e05359e 100644 --- a/bin/alphanet/Cargo.toml +++ b/bin/alphanet/Cargo.toml @@ -19,14 +19,14 @@ reth-node-optimism.workspace = true clap = { workspace = true, features = ["derive"] } [target.'cfg(not(windows))'.dependencies] -jemallocator = { version = "0.5", optional = true } +tikv-jemallocator = { version = "0.5", optional = true } [features] default = ["jemalloc"] asm-keccak = [] -jemalloc = ["dep:jemallocator"] -jemalloc-prof = ["jemalloc", "jemallocator?/profiling"] +jemalloc = ["dep:tikv-jemallocator"] +jemalloc-prof = ["jemalloc", "tikv-jemallocator?/profiling"] min-error-logs = ["tracing/release_max_level_error"] min-warn-logs = ["tracing/release_max_level_warn"] diff --git a/bin/alphanet/src/main.rs b/bin/alphanet/src/main.rs index 05a93b8..d3cd585 100644 --- a/bin/alphanet/src/main.rs +++ b/bin/alphanet/src/main.rs @@ -16,7 +16,7 @@ use reth_node_optimism::{args::RollupArgs, OptimismEngineTypes, OptimismNode}; // We use jemalloc for performance reasons. #[cfg(all(feature = "jemalloc", unix))] #[global_allocator] -static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; +static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; fn main() { reth::sigsegv_handler::install(); diff --git a/crates/instructions/Cargo.toml b/crates/instructions/Cargo.toml index 92d7710..42314d8 100644 --- a/crates/instructions/Cargo.toml +++ b/crates/instructions/Cargo.toml @@ -12,8 +12,8 @@ categories.workspace = true [dependencies] revm.workspace = true revm-interpreter.workspace = true +revm-precompile.workspace = true revm-primitives.workspace = true -secp256k1.workspace = true [dev-dependencies] secp256k1 = { version = "0.28.2", default-features = false, features = [ diff --git a/crates/instructions/src/eip3074.rs b/crates/instructions/src/eip3074.rs index cdf865d..e2afccb 100644 --- a/crates/instructions/src/eip3074.rs +++ b/crates/instructions/src/eip3074.rs @@ -1,11 +1,8 @@ use crate::InstructionWithOpCode; use revm::{Database, Evm}; use revm_interpreter::{gas::memory_gas, next_multiple_of_32, InstructionResult, Interpreter}; +use revm_precompile::secp256k1::ecrecover; use revm_primitives::{alloy_primitives::B512, keccak256, Address, B256}; -use secp256k1::{ - ecdsa::{RecoverableSignature, RecoveryId}, - Message, Secp256k1, -}; const AUTH_OPCODE: u8 = 0xF6; const AUTHCALL_OPCODE: u8 = 0xF7; @@ -27,20 +24,6 @@ pub fn instructions<'a, EXT: 'a, DB: Database + 'a>( .into_iter() } -// TODO: use ecrecover from revm-precompile::secp256k1. -fn ecrecover(sig: &B512, recid: u8, msg: &B256) -> Result { - let recid = RecoveryId::from_i32(recid as i32).expect("recovery ID is valid"); - let sig = RecoverableSignature::from_compact(sig.as_slice(), recid)?; - - let secp = Secp256k1::new(); - let msg = Message::from_digest(msg.0); - let public = secp.recover_ecdsa(&msg, &sig)?; - - let mut hash = keccak256(&public.serialize_uncompressed()[1..]); - hash[..12].fill(0); - Ok(hash) -} - // keccak256(MAGIC || chainId || nonce || invokerAddress || commit) fn compose_msg(chain_id: u64, nonce: u64, invoker_address: Address, commit: B256) -> B256 { let mut msg = [0u8; 129]; @@ -146,7 +129,7 @@ mod tests { }; use revm_interpreter::{Contract, SharedMemory, Stack}; use revm_primitives::{Account, Bytecode, Bytes, U256}; - use secp256k1::{rand, Context, PublicKey, SecretKey, Signing}; + use secp256k1::{rand, Context, Message, PublicKey, Secp256k1, SecretKey, Signing}; use std::convert::Infallible; fn setup_interpreter() -> Interpreter { From 97bb353a14e91dd19f4b0296d1731cd57f207e17 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Fri, 22 Mar 2024 09:48:47 +0100 Subject: [PATCH 10/36] setup context --- crates/instructions/src/eip3074.rs | 79 ++++++++++++++++++++++++------ crates/instructions/src/lib.rs | 11 ++--- crates/node/src/evm.rs | 21 +++++--- 3 files changed, 81 insertions(+), 30 deletions(-) diff --git a/crates/instructions/src/eip3074.rs b/crates/instructions/src/eip3074.rs index e2afccb..ca3b301 100644 --- a/crates/instructions/src/eip3074.rs +++ b/crates/instructions/src/eip3074.rs @@ -1,8 +1,9 @@ -use crate::InstructionWithOpCode; +use crate::BoxedInstructionWithOpCode; use revm::{Database, Evm}; use revm_interpreter::{gas::memory_gas, next_multiple_of_32, InstructionResult, Interpreter}; use revm_precompile::secp256k1::ecrecover; use revm_primitives::{alloy_primitives::B512, keccak256, Address, B256}; +use std::{borrow::BorrowMut, cell::RefCell, rc::Rc}; const AUTH_OPCODE: u8 = 0xF6; const AUTHCALL_OPCODE: u8 = 0xF7; @@ -11,14 +12,40 @@ const WARM_AUTHORITY_GAS: u64 = 100; const COLD_AUTHORITY_GAS: u64 = 2600; const FIXED_FEE_GAS: u64 = 3100; -/// eip3074 instructions. -pub fn instructions<'a, EXT: 'a, DB: Database + 'a>( -) -> impl Iterator>> { +#[derive(Default)] +struct CustomContext { + authority: Address, +} + +/// eip3074 boxed instructions. +pub fn boxed_instructions<'a, EXT: 'a, DB: Database + 'a>( +) -> impl Iterator>> { + let shared_context = Rc::new(RefCell::new(CustomContext::default())); + + let auth_context = Rc::clone(&shared_context); + let wrapped_auth_instruction = { + move |interpreter: &mut Interpreter, evm: &mut Evm<'a, EXT, DB>| { + let mut ctx = auth_context.borrow_mut(); + auth_instruction(interpreter, evm, ctx) + } + }; + + let authcall_context = Rc::clone(&shared_context); + let wrapped_authcall_instruction = { + move |interpreter: &mut Interpreter, evm: &mut Evm<'a, EXT, DB>| { + let mut ctx = authcall_context.borrow_mut(); + authcall_instruction(interpreter, evm, ctx) + } + }; + [ - InstructionWithOpCode { opcode: AUTH_OPCODE, instruction: auth_instruction:: }, - InstructionWithOpCode { + BoxedInstructionWithOpCode { + opcode: AUTH_OPCODE, + boxed_instruction: Box::new(wrapped_auth_instruction), + }, + BoxedInstructionWithOpCode { opcode: AUTHCALL_OPCODE, - instruction: authcall_instruction::, + boxed_instruction: Box::new(wrapped_authcall_instruction), }, ] .into_iter() @@ -35,7 +62,11 @@ fn compose_msg(chain_id: u64, nonce: u64, invoker_address: Address, commit: B256 keccak256(msg.as_slice()) } -fn auth_instruction(interp: &mut Interpreter, evm: &mut Evm<'_, EXT, DB>) { +fn auth_instruction( + interp: &mut Interpreter, + evm: &mut Evm<'_, EXT, DB>, + ctx: &mut Rc>, +) { interp.gas.record_cost(FIXED_FEE_GAS); // TODO: use pop_ret! from revm-interpreter @@ -116,7 +147,11 @@ fn auth_instruction(interp: &mut Interpreter, evm: &mut Evm<' } } -fn authcall_instruction(interp: &mut Interpreter, _evm: &mut Evm<'_, EXT, DB>) { +fn authcall_instruction( + interp: &mut Interpreter, + _evm: &mut Evm<'_, EXT, DB>, + ctx: &mut Rc>, +) { interp.gas.record_cost(133); } @@ -155,7 +190,7 @@ mod tests { .with_db(InMemoryDB::default()) .append_handler_register(|handler| { if let Some(ref mut table) = handler.instruction_table { - table.insert(AUTH_OPCODE, auth_instruction); + table.insert_boxed(AUTH_OPCODE, Box::new(move |_interpreter, _handler| {})); } }) .build() @@ -201,12 +236,19 @@ mod tests { compose_msg(1, 0, Address::default(), B256::ZERO) } + fn default_context() -> Rc> { + let shared_context = Rc::new(RefCell::new(CustomContext::default())); + let mut context = Rc::clone(&shared_context); + context + } + #[test] fn test_auth_instruction_stack_underflow() { let mut interpreter = setup_interpreter(); let mut evm = setup_evm(); + let mut context = default_context(); - auth_instruction(&mut interpreter, &mut evm); + auth_instruction(&mut interpreter, &mut evm, &mut context); assert_eq!(interpreter.instruction_result, InstructionResult::StackUnderflow); // check gas @@ -230,8 +272,9 @@ mod tests { setup_shared_memory(&mut interpreter.shared_memory, y_parity, &r, &s); let mut evm = setup_evm(); + let mut context = default_context(); - auth_instruction(&mut interpreter, &mut evm); + auth_instruction(&mut interpreter, &mut evm, &mut context); assert_eq!(interpreter.instruction_result, InstructionResult::Continue); let result = interpreter.stack.pop().unwrap(); @@ -254,8 +297,9 @@ mod tests { setup_stack(&mut interpreter.stack, authority); let mut evm = setup_evm(); + let mut context = default_context(); - auth_instruction(&mut interpreter, &mut evm); + auth_instruction(&mut interpreter, &mut evm, &mut context); assert_eq!(interpreter.instruction_result, InstructionResult::Stop); @@ -281,8 +325,9 @@ mod tests { setup_shared_memory(&mut interpreter.shared_memory, y_parity, &r, &s); let mut evm = setup_evm(); + let mut context = default_context(); - auth_instruction(&mut interpreter, &mut evm); + auth_instruction(&mut interpreter, &mut evm, &mut context); assert_eq!(interpreter.instruction_result, InstructionResult::Continue); let result = interpreter.stack.pop().unwrap(); @@ -306,8 +351,9 @@ mod tests { let mut evm = setup_evm(); evm.context.evm.journaled_state.state.insert(authority, Account::default()); + let mut context = default_context(); - auth_instruction(&mut interpreter, &mut evm); + auth_instruction(&mut interpreter, &mut evm, &mut context); assert_eq!(interpreter.instruction_result, InstructionResult::Continue); let result = interpreter.stack.pop().unwrap(); @@ -334,8 +380,9 @@ mod tests { setup_shared_memory(&mut interpreter.shared_memory, y_parity, &r, &B256::ZERO); let mut evm = setup_evm(); + let mut context = default_context(); - auth_instruction(&mut interpreter, &mut evm); + auth_instruction(&mut interpreter, &mut evm, &mut context); assert_eq!(interpreter.instruction_result, InstructionResult::Stop); diff --git a/crates/instructions/src/lib.rs b/crates/instructions/src/lib.rs index 45f38e4..bf80f78 100644 --- a/crates/instructions/src/lib.rs +++ b/crates/instructions/src/lib.rs @@ -2,16 +2,15 @@ //! //! Custom instructions for Alphanet. -use revm_interpreter::Instruction; +use revm_interpreter::opcode::BoxedInstruction; /// EIP-3074 custom instructions. pub mod eip3074; -/// Association of OpCode and correspondent instruction. -#[derive(Clone, Debug)] -pub struct InstructionWithOpCode { +/// Association of OpCode and correspondent boxed instruction. +pub struct BoxedInstructionWithOpCode<'a, H> { /// Opcode. pub opcode: u8, - /// Instruction. - pub instruction: Instruction, + /// Boxed instruction. + pub boxed_instruction: BoxedInstruction<'a, H>, } diff --git a/crates/node/src/evm.rs b/crates/node/src/evm.rs index 3295cb6..7aed143 100644 --- a/crates/node/src/evm.rs +++ b/crates/node/src/evm.rs @@ -1,4 +1,4 @@ -use alphanet_instructions::{eip3074, InstructionWithOpCode}; +use alphanet_instructions::{eip3074, BoxedInstructionWithOpCode}; use alphanet_precompile::{bls12_381, secp256r1}; use reth::{ primitives::{ @@ -32,14 +32,19 @@ where } } -// Inserts the given instructions with opcodes in the instructions table. -fn insert_instructions<'a, I, H>(table: &mut InstructionTables<'a, H>, instructions_with_opcodes: I) -where - I: Iterator>, +// Inserts the given boxed instructions with opcodes in the instructions table. +fn insert_boxed_instructions<'a, I, H>( + table: &mut InstructionTables<'a, H>, + boxed_instructions_with_opcodes: I, +) where + I: Iterator>, H: Host + 'a, { - for instruction_with_opcode in instructions_with_opcodes { - table.insert(instruction_with_opcode.opcode, instruction_with_opcode.instruction); + for boxed_instruction_with_opcode in boxed_instructions_with_opcodes { + table.insert_boxed( + instruction_with_opcode.opcode, + boxed_instruction_with_opcode.boxed_instruction, + ); } } @@ -78,7 +83,7 @@ impl AlphaNetEvmConfig { DB: Database, { if let Some(ref mut table) = handler.instruction_table { - insert_instructions(table, eip3074::instructions()); + insert_boxed_instructions(table, eip3074::boxed_instructions()); } } } From 95a8bf4f11462395bff5abe67c99497ea5621b4e Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Fri, 22 Mar 2024 10:28:45 +0100 Subject: [PATCH 11/36] set authority --- crates/instructions/src/eip3074.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/instructions/src/eip3074.rs b/crates/instructions/src/eip3074.rs index ca3b301..37c4cdc 100644 --- a/crates/instructions/src/eip3074.rs +++ b/crates/instructions/src/eip3074.rs @@ -132,15 +132,16 @@ fn auth_instruction( } }; - let result = if Address::from_slice(&signer[12..]) == authority { - // TODO: set authorized context variable to authority - - B256::with_last_byte(1) + let context = ctx.borrow_mut(); + let (to_persist_authority, result) = if Address::from_slice(&signer[12..]) == authority { + (authority, B256::with_last_byte(1)) } else { - // TODO: authorized context variable is reset to unset value + context.authority = Address::default(); - B256::ZERO + (Address::default(), B256::ZERO) }; + let mut context = ctx.borrow_mut(); + context.authority = to_persist_authority; if let Err(e) = interp.stack.push_b256(result) { interp.instruction_result = e; From 7f70f293ae323e5c58291ec7333e55ed67489d2d Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Fri, 22 Mar 2024 10:29:48 +0100 Subject: [PATCH 12/36] use revm_precompile::u64_to_address --- crates/precompile/src/lib.rs | 12 ------------ crates/precompile/src/secp256r1.rs | 8 +++----- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index bfcda14..418d18c 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -11,15 +11,3 @@ pub mod secp256r1; pub mod bls12_381; mod addresses; - -/// Const function for making an address by concatenating the bytes from two given numbers. -/// -/// Note that 32 + 128 = 160 = 20 bytes (the length of an address). This function is used -/// as a convenience for specifying the addresses of the various precompiles. -#[inline] -const fn u64_to_address(x: u64) -> Address { - let x = x.to_be_bytes(); - Address::new([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7], - ]) -} diff --git a/crates/precompile/src/secp256r1.rs b/crates/precompile/src/secp256r1.rs index d4fdc16..53276b0 100644 --- a/crates/precompile/src/secp256r1.rs +++ b/crates/precompile/src/secp256r1.rs @@ -1,6 +1,6 @@ use crate::addresses::P256VERIFY_ADDRESS; use p256::ecdsa::{signature::hazmat::PrehashVerifier, Signature, VerifyingKey}; -use revm_precompile::{Precompile, PrecompileWithAddress}; +use revm_precompile::{u64_to_address, Precompile, PrecompileWithAddress}; use revm_primitives::{Bytes, PrecompileError, PrecompileResult, B256}; /// secp256r1 precompiles @@ -9,10 +9,8 @@ pub fn precompiles() -> impl Iterator { } /// [EIP-7212](https://eips.ethereum.org/EIPS/eip-7212#specification) secp256r1 precompile. -const P256VERIFY: PrecompileWithAddress = PrecompileWithAddress( - crate::u64_to_address(P256VERIFY_ADDRESS), - Precompile::Standard(p256_verify), -); +const P256VERIFY: PrecompileWithAddress = + PrecompileWithAddress(u64_to_address(P256VERIFY_ADDRESS), Precompile::Standard(p256_verify)); /// The input is encoded as follows: /// | signed msg hash | r | s | pk x | pk y | From 1fa0aaf056286bc665d44e5ec42ada325d3d2727 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Fri, 22 Mar 2024 13:08:14 +0100 Subject: [PATCH 13/36] use revm_precompile::u64_to_address --- crates/precompile/src/bls12_381.rs | 24 +++++++++++------------- crates/precompile/src/lib.rs | 2 -- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/crates/precompile/src/bls12_381.rs b/crates/precompile/src/bls12_381.rs index dfed700..15b8369 100644 --- a/crates/precompile/src/bls12_381.rs +++ b/crates/precompile/src/bls12_381.rs @@ -4,7 +4,7 @@ use crate::addresses::{ BLS12_MAP_FP_TO_G1_ADDRESS, BLS12_PAIRING_ADDRESS, }; use bls12_381::{G1Affine, G1Projective}; -use revm_precompile::{Precompile, PrecompileWithAddress}; +use revm_precompile::{u64_to_address, Precompile, PrecompileWithAddress}; use revm_primitives::{Bytes, PrecompileError, PrecompileResult, B256}; use std::ops::Add; @@ -60,7 +60,7 @@ pub fn precompiles() -> impl Iterator { /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G1ADD precompile. const BLS12_G1ADD: PrecompileWithAddress = - PrecompileWithAddress(crate::u64_to_address(BLS12_G1ADD_ADDRESS), Precompile::Standard(g1_add)); + PrecompileWithAddress(u64_to_address(BLS12_G1ADD_ADDRESS), Precompile::Standard(g1_add)); // Removes zeros with which the precompile inputs are left padded to 64 bytes. fn remove_padding(input: &[u8]) -> Result<[u8; FP_LENGTH], PrecompileError> { @@ -193,7 +193,7 @@ fn g1_add(input: &Bytes, gas_limit: u64) -> PrecompileResult { /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G1MUL precompile. const BLS12_G1MUL: PrecompileWithAddress = - PrecompileWithAddress(crate::u64_to_address(BLS12_G1MUL_ADDRESS), Precompile::Standard(g1_mul)); + PrecompileWithAddress(u64_to_address(BLS12_G1MUL_ADDRESS), Precompile::Standard(g1_mul)); fn g1_mul(_input: &Bytes, gas_limit: u64) -> PrecompileResult { const G1MUL_BASE: u64 = 12000; @@ -206,7 +206,7 @@ fn g1_mul(_input: &Bytes, gas_limit: u64) -> PrecompileResult { /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G1MULTIEXP precompile. const BLS12_G1MULTIEXP: PrecompileWithAddress = PrecompileWithAddress( - crate::u64_to_address(BLS12_G1MULTIEXP_ADDRESS), + u64_to_address(BLS12_G1MULTIEXP_ADDRESS), Precompile::Standard(g1_multiexp), ); @@ -222,7 +222,7 @@ fn g1_multiexp(_input: &Bytes, gas_limit: u64) -> PrecompileResult { /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G2ADD precompile. const BLS12_G2ADD: PrecompileWithAddress = - PrecompileWithAddress(crate::u64_to_address(BLS12_G2ADD_ADDRESS), Precompile::Standard(g2_add)); + PrecompileWithAddress(u64_to_address(BLS12_G2ADD_ADDRESS), Precompile::Standard(g2_add)); fn g2_add(_input: &Bytes, gas_limit: u64) -> PrecompileResult { const G2ADD_BASE: u64 = 800; @@ -235,7 +235,7 @@ fn g2_add(_input: &Bytes, gas_limit: u64) -> PrecompileResult { /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G2MUL precompile. const BLS12_G2MUL: PrecompileWithAddress = - PrecompileWithAddress(crate::u64_to_address(BLS12_G2MUL_ADDRESS), Precompile::Standard(g2_mul)); + PrecompileWithAddress(u64_to_address(BLS12_G2MUL_ADDRESS), Precompile::Standard(g2_mul)); fn g2_mul(_input: &Bytes, gas_limit: u64) -> PrecompileResult { const G2MUL_BASE: u64 = 45000; @@ -248,7 +248,7 @@ fn g2_mul(_input: &Bytes, gas_limit: u64) -> PrecompileResult { /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G2MULTIEXP precompile. const BLS12_G2MULTIEXP: PrecompileWithAddress = PrecompileWithAddress( - crate::u64_to_address(BLS12_G2MULTIEXP_ADDRESS), + u64_to_address(BLS12_G2MULTIEXP_ADDRESS), Precompile::Standard(g2_multiexp), ); @@ -263,10 +263,8 @@ fn g2_multiexp(_input: &Bytes, gas_limit: u64) -> PrecompileResult { } /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_PAIRING precompile. -const BLS12_PAIRING: PrecompileWithAddress = PrecompileWithAddress( - crate::u64_to_address(BLS12_PAIRING_ADDRESS), - Precompile::Standard(pairing), -); +const BLS12_PAIRING: PrecompileWithAddress = + PrecompileWithAddress(u64_to_address(BLS12_PAIRING_ADDRESS), Precompile::Standard(pairing)); fn pairing(_input: &Bytes, gas_limit: u64) -> PrecompileResult { // TODO: make gas base depend on input k @@ -280,7 +278,7 @@ fn pairing(_input: &Bytes, gas_limit: u64) -> PrecompileResult { /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_MAP_FP_TO_G1 precompile. const BLS12_MAP_FP_TO_G1: PrecompileWithAddress = PrecompileWithAddress( - crate::u64_to_address(BLS12_MAP_FP_TO_G1_ADDRESS), + u64_to_address(BLS12_MAP_FP_TO_G1_ADDRESS), Precompile::Standard(map_fp_to_g1), ); @@ -296,7 +294,7 @@ fn map_fp_to_g1(_input: &Bytes, gas_limit: u64) -> PrecompileResult { /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_MAP_FP2_TO_G2 precompile. const BLS12_MAP_FP2_TO_G2: PrecompileWithAddress = PrecompileWithAddress( - crate::u64_to_address(BLS12_MAP_FP2_TO_G2_ADDRESS), + u64_to_address(BLS12_MAP_FP2_TO_G2_ADDRESS), Precompile::Standard(map_fp2_to_g2), ); diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index 418d18c..6a089b7 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -2,8 +2,6 @@ //! //! Implementations of EVM precompiled contracts for AlphaNet. -use revm_primitives::Address; - /// EIP-7212 secp256r1 precompile. pub mod secp256r1; From 4990005dae1dba9d9672307f931489ab9fd6f1d6 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Fri, 22 Mar 2024 13:08:38 +0100 Subject: [PATCH 14/36] pass CustomContext to instructions --- crates/instructions/src/eip3074.rs | 74 +++++++++++------------------- 1 file changed, 27 insertions(+), 47 deletions(-) diff --git a/crates/instructions/src/eip3074.rs b/crates/instructions/src/eip3074.rs index 37c4cdc..956c8e9 100644 --- a/crates/instructions/src/eip3074.rs +++ b/crates/instructions/src/eip3074.rs @@ -12,40 +12,35 @@ const WARM_AUTHORITY_GAS: u64 = 100; const COLD_AUTHORITY_GAS: u64 = 2600; const FIXED_FEE_GAS: u64 = 3100; -#[derive(Default)] -struct CustomContext { - authority: Address, +#[derive(Default, Clone)] +pub(crate) struct CustomContext { + pub(crate) authority: Rc>, } /// eip3074 boxed instructions. pub fn boxed_instructions<'a, EXT: 'a, DB: Database + 'a>( ) -> impl Iterator>> { - let shared_context = Rc::new(RefCell::new(CustomContext::default())); + let shared_context = CustomContext::default(); + let to_capture = shared_context.clone(); - let auth_context = Rc::clone(&shared_context); - let wrapped_auth_instruction = { - move |interpreter: &mut Interpreter, evm: &mut Evm<'a, EXT, DB>| { - let mut ctx = auth_context.borrow_mut(); - auth_instruction(interpreter, evm, ctx) - } - }; + let wrapped_auth_instruction = + Box::new(move |interpreter: &mut Interpreter, evm: &mut Evm<'a, EXT, DB>| { + auth_instruction(interpreter, evm, &to_capture); + }); - let authcall_context = Rc::clone(&shared_context); - let wrapped_authcall_instruction = { - move |interpreter: &mut Interpreter, evm: &mut Evm<'a, EXT, DB>| { - let mut ctx = authcall_context.borrow_mut(); - authcall_instruction(interpreter, evm, ctx) - } - }; + let wrapped_authcall_instruction = + Box::new(move |interpreter: &mut Interpreter, evm: &mut Evm<'a, EXT, DB>| { + authcall_instruction(interpreter, evm, &to_capture); + }); [ BoxedInstructionWithOpCode { opcode: AUTH_OPCODE, - boxed_instruction: Box::new(wrapped_auth_instruction), + boxed_instruction: wrapped_auth_instruction, }, BoxedInstructionWithOpCode { opcode: AUTHCALL_OPCODE, - boxed_instruction: Box::new(wrapped_authcall_instruction), + boxed_instruction: wrapped_authcall_instruction, }, ] .into_iter() @@ -65,7 +60,7 @@ fn compose_msg(chain_id: u64, nonce: u64, invoker_address: Address, commit: B256 fn auth_instruction( interp: &mut Interpreter, evm: &mut Evm<'_, EXT, DB>, - ctx: &mut Rc>, + ctx: &CustomContext, ) { interp.gas.record_cost(FIXED_FEE_GAS); @@ -132,16 +127,13 @@ fn auth_instruction( } }; - let context = ctx.borrow_mut(); let (to_persist_authority, result) = if Address::from_slice(&signer[12..]) == authority { (authority, B256::with_last_byte(1)) } else { - context.authority = Address::default(); - (Address::default(), B256::ZERO) }; - let mut context = ctx.borrow_mut(); - context.authority = to_persist_authority; + let mut inner_authority = ctx.authority.borrow_mut(); + *inner_authority = to_persist_authority; if let Err(e) = interp.stack.push_b256(result) { interp.instruction_result = e; @@ -151,7 +143,7 @@ fn auth_instruction( fn authcall_instruction( interp: &mut Interpreter, _evm: &mut Evm<'_, EXT, DB>, - ctx: &mut Rc>, + _ctx: &CustomContext, ) { interp.gas.record_cost(133); } @@ -189,11 +181,11 @@ mod tests { fn setup_evm() -> Evm<'static, (), CacheDB>> { Evm::builder() .with_db(InMemoryDB::default()) - .append_handler_register(|handler| { + .append_handler_register_box(Box::new(|handler| { if let Some(ref mut table) = handler.instruction_table { table.insert_boxed(AUTH_OPCODE, Box::new(move |_interpreter, _handler| {})); } - }) + })) .build() } @@ -237,19 +229,12 @@ mod tests { compose_msg(1, 0, Address::default(), B256::ZERO) } - fn default_context() -> Rc> { - let shared_context = Rc::new(RefCell::new(CustomContext::default())); - let mut context = Rc::clone(&shared_context); - context - } - #[test] fn test_auth_instruction_stack_underflow() { let mut interpreter = setup_interpreter(); let mut evm = setup_evm(); - let mut context = default_context(); - auth_instruction(&mut interpreter, &mut evm, &mut context); + auth_instruction(&mut interpreter, &mut evm, &CustomContext::default()); assert_eq!(interpreter.instruction_result, InstructionResult::StackUnderflow); // check gas @@ -273,9 +258,8 @@ mod tests { setup_shared_memory(&mut interpreter.shared_memory, y_parity, &r, &s); let mut evm = setup_evm(); - let mut context = default_context(); - auth_instruction(&mut interpreter, &mut evm, &mut context); + auth_instruction(&mut interpreter, &mut evm, &CustomContext::default()); assert_eq!(interpreter.instruction_result, InstructionResult::Continue); let result = interpreter.stack.pop().unwrap(); @@ -298,9 +282,8 @@ mod tests { setup_stack(&mut interpreter.stack, authority); let mut evm = setup_evm(); - let mut context = default_context(); - auth_instruction(&mut interpreter, &mut evm, &mut context); + auth_instruction(&mut interpreter, &mut evm, &CustomContext::default()); assert_eq!(interpreter.instruction_result, InstructionResult::Stop); @@ -326,9 +309,8 @@ mod tests { setup_shared_memory(&mut interpreter.shared_memory, y_parity, &r, &s); let mut evm = setup_evm(); - let mut context = default_context(); - auth_instruction(&mut interpreter, &mut evm, &mut context); + auth_instruction(&mut interpreter, &mut evm, &CustomContext::default()); assert_eq!(interpreter.instruction_result, InstructionResult::Continue); let result = interpreter.stack.pop().unwrap(); @@ -352,9 +334,8 @@ mod tests { let mut evm = setup_evm(); evm.context.evm.journaled_state.state.insert(authority, Account::default()); - let mut context = default_context(); - auth_instruction(&mut interpreter, &mut evm, &mut context); + auth_instruction(&mut interpreter, &mut evm, &CustomContext::default()); assert_eq!(interpreter.instruction_result, InstructionResult::Continue); let result = interpreter.stack.pop().unwrap(); @@ -381,9 +362,8 @@ mod tests { setup_shared_memory(&mut interpreter.shared_memory, y_parity, &r, &B256::ZERO); let mut evm = setup_evm(); - let mut context = default_context(); - auth_instruction(&mut interpreter, &mut evm, &mut context); + auth_instruction(&mut interpreter, &mut evm, &CustomContext::default()); assert_eq!(interpreter.instruction_result, InstructionResult::Stop); From 9ca2468097380595d06385e0ad17e6544cbbae52 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Fri, 22 Mar 2024 14:59:48 +0100 Subject: [PATCH 15/36] removed leftovers --- Cargo.lock | 31 +++--- crates/precompile/src/bls12_381.rs | 158 ----------------------------- 2 files changed, 17 insertions(+), 172 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3df2542..e190558 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -911,6 +911,7 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "600e4e4a65b26efcef08a7b1cf2899d3845a32e82e067ee3b75eaf7e413ff31c" dependencies = [ + "arrayvec", "bitflags 2.5.0", "boa_ast", "boa_gc", @@ -1072,6 +1073,20 @@ name = "bytemuck" version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" +dependencies = [ + "bytemuck_derive", +] + +[[package]] +name = "bytemuck_derive" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4da9a32f3fed317401fa3c862968128267c3106685286e15d5aaa3d7389c2f60" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.53", +] [[package]] name = "byteorder" @@ -2813,7 +2828,7 @@ checksum = "d2abdd3a62551e8337af119c5899e600ca0c88ec8f23a46c60ba216c803dcf1a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.53", ] [[package]] @@ -3740,19 +3755,7 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02339744ee7253741199f897151b38e72257d13802d4ee837285cc2990a90845" dependencies = [ - "num_enum_derive 0.7.2", -] - -[[package]] -name = "num_enum_derive" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" -dependencies = [ - "proc-macro-crate 1.3.1", - "proc-macro2", - "quote", - "syn 2.0.53", + "num_enum_derive", ] [[package]] diff --git a/crates/precompile/src/bls12_381.rs b/crates/precompile/src/bls12_381.rs index 15b8369..f22a2d1 100644 --- a/crates/precompile/src/bls12_381.rs +++ b/crates/precompile/src/bls12_381.rs @@ -33,31 +33,6 @@ pub fn precompiles() -> impl Iterator { .into_iter() } -const G1ADD_BASE: u64 = 500; -const INPUT_LENGTH: usize = 256; -const INPUT_ITEM_LENGTH: usize = 128; -const OUTPUT_LENGTH: usize = 128; -const FP_LENGTH: usize = 48; -const PADDED_INPUT_LENGTH: usize = 64; -const PADDING_LEGTH: usize = 16; -const FP_CONCAT_LENGTH: usize = 96; - -/// bls12381 precompiles -pub fn precompiles() -> impl Iterator { - [ - BLS12_G1ADD, - BLS12_G1MUL, - BLS12_G1MULTIEXP, - BLS12_G2ADD, - BLS12_G2MUL, - BLS12_G2MULTIEXP, - BLS12_PAIRING, - BLS12_MAP_FP_TO_G1, - BLS12_MAP_FP2_TO_G2, - ] - .into_iter() -} - /// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G1ADD precompile. const BLS12_G1ADD: PrecompileWithAddress = PrecompileWithAddress(u64_to_address(BLS12_G1ADD_ADDRESS), Precompile::Standard(g1_add)); @@ -140,20 +115,6 @@ fn extract_g1_input(input: &[u8]) -> Result { } Ok(output.unwrap()) } - - let input_p0_x = match remove_padding(&input[..PADDED_INPUT_LENGTH]) { - Ok(input_p0_x) => input_p0_x, - Err(e) => return Err(e), - }; - let input_p0_y = match remove_padding(&input[PADDED_INPUT_LENGTH..INPUT_ITEM_LENGTH]) { - Ok(input_p0_y) => input_p0_y, - Err(e) => return Err(e), - }; - let mut input_p0: [u8; FP_CONCAT_LENGTH] = [0; FP_CONCAT_LENGTH]; - input_p0[..FP_LEGTH].copy_from_slice(&input_p0_x); - input_p0[FP_LEGTH..].copy_from_slice(&input_p0_y); - - Ok(input_p0) } // G1 addition call expects `256` bytes as an input that is interpreted as byte @@ -308,125 +269,6 @@ fn map_fp2_to_g2(_input: &Bytes, gas_limit: u64) -> PrecompileResult { Ok((MAP_FP2_TO_G2_BASE, B256::with_last_byte(result as u8).into())) } -/// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G1MUL precompile. -pub const BLS12_G1MUL: PrecompileWithAddress = - PrecompileWithAddress(crate::u64_to_address(BLS12_G1MUL_ADDRESS), Precompile::Standard(g1_mul)); - -fn g1_mul(_input: &Bytes, gas_limit: u64) -> PrecompileResult { - const G1MUL_BASE: u64 = 12000; - if G1MUL_BASE > gas_limit { - return Err(PrecompileError::OutOfGas); - } - let result = 1; - Ok((G1MUL_BASE, B256::with_last_byte(result as u8).into())) -} - -/// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G1MULTIEXP precompile. -const BLS12_G1MULTIEXP: PrecompileWithAddress = PrecompileWithAddress( - crate::u64_to_address(BLS12_G1MULTIEXP_ADDRESS), - Precompile::Standard(g1_multiexp), -); - -fn g1_multiexp(_input: &Bytes, gas_limit: u64) -> PrecompileResult { - // TODO: make gas base depend on input k - const G1MULTIEXP_BASE: u64 = 12000; - if G1MULTIEXP_BASE > gas_limit { - return Err(PrecompileError::OutOfGas); - } - let result = 1; - Ok((G1MULTIEXP_BASE, B256::with_last_byte(result as u8).into())) -} - -/// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G2ADD precompile. -const BLS12_G2ADD: PrecompileWithAddress = - PrecompileWithAddress(crate::u64_to_address(BLS12_G2ADD_ADDRESS), Precompile::Standard(g2_add)); - -fn g2_add(_input: &Bytes, gas_limit: u64) -> PrecompileResult { - const G2ADD_BASE: u64 = 800; - if G2ADD_BASE > gas_limit { - return Err(PrecompileError::OutOfGas); - } - let result = 1; - Ok((G2ADD_BASE, B256::with_last_byte(result as u8).into())) -} - -/// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G2MUL precompile. -const BLS12_G2MUL: PrecompileWithAddress = - PrecompileWithAddress(crate::u64_to_address(BLS12_G2MUL_ADDRESS), Precompile::Standard(g2_mul)); - -fn g2_mul(_input: &Bytes, gas_limit: u64) -> PrecompileResult { - const G2MUL_BASE: u64 = 45000; - if G2MUL_BASE > gas_limit { - return Err(PrecompileError::OutOfGas); - } - let result = 1; - Ok((G2MUL_BASE, B256::with_last_byte(result as u8).into())) -} - -/// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_G2MULTIEXP precompile. -const BLS12_G2MULTIEXP: PrecompileWithAddress = PrecompileWithAddress( - crate::u64_to_address(BLS12_G2MULTIEXP_ADDRESS), - Precompile::Standard(g2_multiexp), -); - -fn g2_multiexp(_input: &Bytes, gas_limit: u64) -> PrecompileResult { - // TODO: make gas base depend on input k - const G2MULTIEXP_BASE: u64 = 12000; - if G2MULTIEXP_BASE > gas_limit { - return Err(PrecompileError::OutOfGas); - } - let result = 1; - Ok((G2MULTIEXP_BASE, B256::with_last_byte(result as u8).into())) -} - -/// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_PAIRING precompile. -const BLS12_PAIRING: PrecompileWithAddress = PrecompileWithAddress( - crate::u64_to_address(BLS12_PAIRING_ADDRESS), - Precompile::Standard(pairing), -); - -fn pairing(_input: &Bytes, gas_limit: u64) -> PrecompileResult { - // TODO: make gas base depend on input k - const PAIRING_BASE: u64 = 12000; - if PAIRING_BASE > gas_limit { - return Err(PrecompileError::OutOfGas); - } - let result = 1; - Ok((PAIRING_BASE, B256::with_last_byte(result as u8).into())) -} - -/// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_MAP_FP_TO_G1 precompile. -const BLS12_MAP_FP_TO_G1: PrecompileWithAddress = PrecompileWithAddress( - crate::u64_to_address(BLS12_MAP_FP_TO_G1_ADDRESS), - Precompile::Standard(map_fp_to_g1), -); - -fn map_fp_to_g1(_input: &Bytes, gas_limit: u64) -> PrecompileResult { - // TODO: make gas base depend on input k - const MAP_FP_TO_G1_BASE: u64 = 12000; - if MAP_FP_TO_G1_BASE > gas_limit { - return Err(PrecompileError::OutOfGas); - } - let result = 1; - Ok((MAP_FP_TO_G1_BASE, B256::with_last_byte(result as u8).into())) -} - -/// [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537#specification) BLS12_MAP_FP2_TO_G2 precompile. -const BLS12_MAP_FP2_TO_G2: PrecompileWithAddress = PrecompileWithAddress( - crate::u64_to_address(BLS12_MAP_FP2_TO_G2_ADDRESS), - Precompile::Standard(map_fp2_to_g2), -); - -fn map_fp2_to_g2(_input: &Bytes, gas_limit: u64) -> PrecompileResult { - // TODO: make gas base depend on input k - const MAP_FP2_TO_G2_BASE: u64 = 12000; - if MAP_FP2_TO_G2_BASE > gas_limit { - return Err(PrecompileError::OutOfGas); - } - let result = 1; - Ok((MAP_FP2_TO_G2_BASE, B256::with_last_byte(result as u8).into())) -} - #[cfg(test)] mod test { use super::*; From 77aedcdb5ab8b2556da4f8143c4b1111dae291d5 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Fri, 22 Mar 2024 15:54:54 +0100 Subject: [PATCH 16/36] properly set contexts for each instruction --- crates/instructions/src/eip3074.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/instructions/src/eip3074.rs b/crates/instructions/src/eip3074.rs index 956c8e9..359af2a 100644 --- a/crates/instructions/src/eip3074.rs +++ b/crates/instructions/src/eip3074.rs @@ -20,17 +20,18 @@ pub(crate) struct CustomContext { /// eip3074 boxed instructions. pub fn boxed_instructions<'a, EXT: 'a, DB: Database + 'a>( ) -> impl Iterator>> { - let shared_context = CustomContext::default(); - let to_capture = shared_context.clone(); + let context = CustomContext::default(); + let to_capture_for_auth = context.clone(); + let to_capture_for_authcall = context.clone(); let wrapped_auth_instruction = Box::new(move |interpreter: &mut Interpreter, evm: &mut Evm<'a, EXT, DB>| { - auth_instruction(interpreter, evm, &to_capture); + auth_instruction(interpreter, evm, &to_capture_for_auth); }); let wrapped_authcall_instruction = Box::new(move |interpreter: &mut Interpreter, evm: &mut Evm<'a, EXT, DB>| { - authcall_instruction(interpreter, evm, &to_capture); + authcall_instruction(interpreter, evm, &to_capture_for_authcall); }); [ @@ -132,8 +133,10 @@ fn auth_instruction( } else { (Address::default(), B256::ZERO) }; - let mut inner_authority = ctx.authority.borrow_mut(); - *inner_authority = to_persist_authority; + + let mut at = &ctx.authority; + let inner_authority = at.borrow_mut(); + let _ = inner_authority.replace(to_persist_authority); if let Err(e) = interp.stack.push_b256(result) { interp.instruction_result = e; From 56e41a9786a0b9224f1aa91de63df7348767d860 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Fri, 22 Mar 2024 15:55:10 +0100 Subject: [PATCH 17/36] add missing lifetime and fix variable name --- crates/node/src/evm.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/node/src/evm.rs b/crates/node/src/evm.rs index 7aed143..3b25ecb 100644 --- a/crates/node/src/evm.rs +++ b/crates/node/src/evm.rs @@ -37,12 +37,12 @@ fn insert_boxed_instructions<'a, I, H>( table: &mut InstructionTables<'a, H>, boxed_instructions_with_opcodes: I, ) where - I: Iterator>, + I: Iterator>, H: Host + 'a, { for boxed_instruction_with_opcode in boxed_instructions_with_opcodes { table.insert_boxed( - instruction_with_opcode.opcode, + boxed_instruction_with_opcode.opcode, boxed_instruction_with_opcode.boxed_instruction, ); } From a7728c5ccf0016d2abffaa9840d1a4eac78b712e Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Fri, 22 Mar 2024 17:00:33 +0100 Subject: [PATCH 18/36] use macros from revm_interpreter --- crates/instructions/src/eip3074.rs | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/crates/instructions/src/eip3074.rs b/crates/instructions/src/eip3074.rs index 359af2a..cdfeff5 100644 --- a/crates/instructions/src/eip3074.rs +++ b/crates/instructions/src/eip3074.rs @@ -1,6 +1,6 @@ use crate::BoxedInstructionWithOpCode; use revm::{Database, Evm}; -use revm_interpreter::{gas::memory_gas, next_multiple_of_32, InstructionResult, Interpreter}; +use revm_interpreter::{pop, resize_memory, InstructionResult, Interpreter}; use revm_precompile::secp256k1::ecrecover; use revm_primitives::{alloy_primitives::B512, keccak256, Address, B256}; use std::{borrow::BorrowMut, cell::RefCell, rc::Rc}; @@ -65,13 +65,7 @@ fn auth_instruction( ) { interp.gas.record_cost(FIXED_FEE_GAS); - // TODO: use pop_ret! from revm-interpreter - if interp.stack.len() < 3 { - interp.instruction_result = InstructionResult::StackUnderflow; - return; - } - // SAFETY: length checked above - let (authority, offset, length) = unsafe { interp.stack.pop3_unsafe() }; + pop!(interp, authority, offset, length); let authority = Address::from_slice(&authority.to_be_bytes::<32>()[12..]); @@ -81,22 +75,9 @@ fn auth_instruction( COLD_AUTHORITY_GAS }); // authority state fee - // TODO: use shared_memory_resize! from revm-interpreter let length = length.saturating_to::(); let offset = offset.saturating_to::(); - if length != 0 { - let size = offset.saturating_add(length); - if size > interp.shared_memory.len() { - let rounded_size = next_multiple_of_32(size); - - let words_num = rounded_size / 32; - if !interp.gas.record_memory(memory_gas(words_num)) { - interp.instruction_result = InstructionResult::MemoryLimitOOG; - return; - } - interp.shared_memory.resize(rounded_size); - } - } + resize_memory!(interp, offset, length); // read yParity, r, s and commit from memory using offset and length let y_parity = interp.shared_memory.get_byte(offset); From ab34b06b6a0728cec025f25093a571df41f93f06 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Fri, 22 Mar 2024 17:14:23 +0100 Subject: [PATCH 19/36] CustomContext -> Eip3074Context --- crates/instructions/src/eip3074.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/instructions/src/eip3074.rs b/crates/instructions/src/eip3074.rs index cdfeff5..4547dd9 100644 --- a/crates/instructions/src/eip3074.rs +++ b/crates/instructions/src/eip3074.rs @@ -13,14 +13,14 @@ const COLD_AUTHORITY_GAS: u64 = 2600; const FIXED_FEE_GAS: u64 = 3100; #[derive(Default, Clone)] -pub(crate) struct CustomContext { +pub(crate) struct Eip3074Context { pub(crate) authority: Rc>, } /// eip3074 boxed instructions. pub fn boxed_instructions<'a, EXT: 'a, DB: Database + 'a>( ) -> impl Iterator>> { - let context = CustomContext::default(); + let context = Eip3074Context::default(); let to_capture_for_auth = context.clone(); let to_capture_for_authcall = context.clone(); @@ -61,7 +61,7 @@ fn compose_msg(chain_id: u64, nonce: u64, invoker_address: Address, commit: B256 fn auth_instruction( interp: &mut Interpreter, evm: &mut Evm<'_, EXT, DB>, - ctx: &CustomContext, + ctx: &Eip3074Context, ) { interp.gas.record_cost(FIXED_FEE_GAS); @@ -127,7 +127,7 @@ fn auth_instruction( fn authcall_instruction( interp: &mut Interpreter, _evm: &mut Evm<'_, EXT, DB>, - _ctx: &CustomContext, + _ctx: &Eip3074Context, ) { interp.gas.record_cost(133); } @@ -218,7 +218,7 @@ mod tests { let mut interpreter = setup_interpreter(); let mut evm = setup_evm(); - auth_instruction(&mut interpreter, &mut evm, &CustomContext::default()); + auth_instruction(&mut interpreter, &mut evm, &Eip3074Context::default()); assert_eq!(interpreter.instruction_result, InstructionResult::StackUnderflow); // check gas @@ -243,7 +243,7 @@ mod tests { let mut evm = setup_evm(); - auth_instruction(&mut interpreter, &mut evm, &CustomContext::default()); + auth_instruction(&mut interpreter, &mut evm, &Eip3074Context::default()); assert_eq!(interpreter.instruction_result, InstructionResult::Continue); let result = interpreter.stack.pop().unwrap(); @@ -267,7 +267,7 @@ mod tests { let mut evm = setup_evm(); - auth_instruction(&mut interpreter, &mut evm, &CustomContext::default()); + auth_instruction(&mut interpreter, &mut evm, &Eip3074Context::default()); assert_eq!(interpreter.instruction_result, InstructionResult::Stop); @@ -294,7 +294,7 @@ mod tests { let mut evm = setup_evm(); - auth_instruction(&mut interpreter, &mut evm, &CustomContext::default()); + auth_instruction(&mut interpreter, &mut evm, &Eip3074Context::default()); assert_eq!(interpreter.instruction_result, InstructionResult::Continue); let result = interpreter.stack.pop().unwrap(); @@ -319,7 +319,7 @@ mod tests { let mut evm = setup_evm(); evm.context.evm.journaled_state.state.insert(authority, Account::default()); - auth_instruction(&mut interpreter, &mut evm, &CustomContext::default()); + auth_instruction(&mut interpreter, &mut evm, &Eip3074Context::default()); assert_eq!(interpreter.instruction_result, InstructionResult::Continue); let result = interpreter.stack.pop().unwrap(); @@ -347,7 +347,7 @@ mod tests { let mut evm = setup_evm(); - auth_instruction(&mut interpreter, &mut evm, &CustomContext::default()); + auth_instruction(&mut interpreter, &mut evm, &Eip3074Context::default()); assert_eq!(interpreter.instruction_result, InstructionResult::Stop); From 9278852f49f9d7516cd0a2f1cc1dc99165e66572 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Fri, 22 Mar 2024 17:24:32 +0100 Subject: [PATCH 20/36] add Eip3074Context docs --- crates/instructions/src/eip3074.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/instructions/src/eip3074.rs b/crates/instructions/src/eip3074.rs index 4547dd9..e9fb428 100644 --- a/crates/instructions/src/eip3074.rs +++ b/crates/instructions/src/eip3074.rs @@ -13,6 +13,9 @@ const COLD_AUTHORITY_GAS: u64 = 2600; const FIXED_FEE_GAS: u64 = 3100; #[derive(Default, Clone)] +/// Contains the authority context variable used by EIP-3074 AUTH and AUTHCALL +/// instructions. It is wrapped in a Rc> so that we can read and write +/// to it inside the instructions. pub(crate) struct Eip3074Context { pub(crate) authority: Rc>, } From 73fc46a3034cd35526bdf739288ab5830770145f Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Sat, 23 Mar 2024 11:14:11 +0100 Subject: [PATCH 21/36] check authority context variable is set --- crates/instructions/src/eip3074.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/instructions/src/eip3074.rs b/crates/instructions/src/eip3074.rs index e9fb428..491353a 100644 --- a/crates/instructions/src/eip3074.rs +++ b/crates/instructions/src/eip3074.rs @@ -245,8 +245,9 @@ mod tests { setup_shared_memory(&mut interpreter.shared_memory, y_parity, &r, &s); let mut evm = setup_evm(); + let context = Eip3074Context::default(); - auth_instruction(&mut interpreter, &mut evm, &Eip3074Context::default()); + auth_instruction(&mut interpreter, &mut evm, &context); assert_eq!(interpreter.instruction_result, InstructionResult::Continue); let result = interpreter.stack.pop().unwrap(); @@ -256,7 +257,7 @@ mod tests { let expected_gas = FIXED_FEE_GAS + COLD_AUTHORITY_GAS; assert_eq!(expected_gas, interpreter.gas.spend()); - // TODO: check authorized context variable set + assert_eq!(*context.authority.borrow(), authority); } #[test] From ce43e1160199df09092b534280db60a93d78cd91 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Sat, 23 Mar 2024 11:17:36 +0100 Subject: [PATCH 22/36] authority -> authorized --- crates/instructions/src/eip3074.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/instructions/src/eip3074.rs b/crates/instructions/src/eip3074.rs index 491353a..897202f 100644 --- a/crates/instructions/src/eip3074.rs +++ b/crates/instructions/src/eip3074.rs @@ -13,11 +13,11 @@ const COLD_AUTHORITY_GAS: u64 = 2600; const FIXED_FEE_GAS: u64 = 3100; #[derive(Default, Clone)] -/// Contains the authority context variable used by EIP-3074 AUTH and AUTHCALL +/// Contains the authorized context variable used by EIP-3074 AUTH and AUTHCALL /// instructions. It is wrapped in a Rc> so that we can read and write /// to it inside the instructions. pub(crate) struct Eip3074Context { - pub(crate) authority: Rc>, + pub(crate) authorized: Rc>, } /// eip3074 boxed instructions. @@ -118,9 +118,9 @@ fn auth_instruction( (Address::default(), B256::ZERO) }; - let mut at = &ctx.authority; - let inner_authority = at.borrow_mut(); - let _ = inner_authority.replace(to_persist_authority); + let mut at = &ctx.authorized; + let inner_authorized = at.borrow_mut(); + let _ = inner_authorized.replace(to_persist_authority); if let Err(e) = interp.stack.push_b256(result) { interp.instruction_result = e; @@ -257,7 +257,7 @@ mod tests { let expected_gas = FIXED_FEE_GAS + COLD_AUTHORITY_GAS; assert_eq!(expected_gas, interpreter.gas.spend()); - assert_eq!(*context.authority.borrow(), authority); + assert_eq!(*context.authorized.borrow(), authority); } #[test] From 5165e335b5b41ee463276f07d3e233380339dc81 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Sat, 23 Mar 2024 17:59:11 +0100 Subject: [PATCH 23/36] generalized instructions context --- crates/instructions/src/eip3074.rs | 59 +++++++++++++++--------------- crates/instructions/src/lib.rs | 18 +++++++++ crates/node/src/evm.rs | 11 +++++- 3 files changed, 57 insertions(+), 31 deletions(-) diff --git a/crates/instructions/src/eip3074.rs b/crates/instructions/src/eip3074.rs index 897202f..d4c6331 100644 --- a/crates/instructions/src/eip3074.rs +++ b/crates/instructions/src/eip3074.rs @@ -1,9 +1,9 @@ -use crate::BoxedInstructionWithOpCode; +use crate::{BoxedInstructionWithOpCode, InstructionsContext}; use revm::{Database, Evm}; use revm_interpreter::{pop, resize_memory, InstructionResult, Interpreter}; use revm_precompile::secp256k1::ecrecover; use revm_primitives::{alloy_primitives::B512, keccak256, Address, B256}; -use std::{borrow::BorrowMut, cell::RefCell, rc::Rc}; +use std::{borrow::BorrowMut, collections::HashMap}; const AUTH_OPCODE: u8 = 0xF6; const AUTHCALL_OPCODE: u8 = 0xF7; @@ -11,28 +11,21 @@ const MAGIC: u8 = 0x04; const WARM_AUTHORITY_GAS: u64 = 100; const COLD_AUTHORITY_GAS: u64 = 2600; const FIXED_FEE_GAS: u64 = 3100; - -#[derive(Default, Clone)] -/// Contains the authorized context variable used by EIP-3074 AUTH and AUTHCALL -/// instructions. It is wrapped in a Rc> so that we can read and write -/// to it inside the instructions. -pub(crate) struct Eip3074Context { - pub(crate) authorized: Rc>, -} +const AUTORIZED_VAR_NAME: &str = "authorized"; /// eip3074 boxed instructions. pub fn boxed_instructions<'a, EXT: 'a, DB: Database + 'a>( + context: InstructionsContext, ) -> impl Iterator>> { - let context = Eip3074Context::default(); let to_capture_for_auth = context.clone(); let to_capture_for_authcall = context.clone(); - let wrapped_auth_instruction = + let boxed_auth_instruction = Box::new(move |interpreter: &mut Interpreter, evm: &mut Evm<'a, EXT, DB>| { auth_instruction(interpreter, evm, &to_capture_for_auth); }); - let wrapped_authcall_instruction = + let boxed_authcall_instruction = Box::new(move |interpreter: &mut Interpreter, evm: &mut Evm<'a, EXT, DB>| { authcall_instruction(interpreter, evm, &to_capture_for_authcall); }); @@ -40,11 +33,11 @@ pub fn boxed_instructions<'a, EXT: 'a, DB: Database + 'a>( [ BoxedInstructionWithOpCode { opcode: AUTH_OPCODE, - boxed_instruction: wrapped_auth_instruction, + boxed_instruction: boxed_auth_instruction, }, BoxedInstructionWithOpCode { opcode: AUTHCALL_OPCODE, - boxed_instruction: wrapped_authcall_instruction, + boxed_instruction: boxed_authcall_instruction, }, ] .into_iter() @@ -64,7 +57,7 @@ fn compose_msg(chain_id: u64, nonce: u64, invoker_address: Address, commit: B256 fn auth_instruction( interp: &mut Interpreter, evm: &mut Evm<'_, EXT, DB>, - ctx: &Eip3074Context, + ctx: &InstructionsContext, ) { interp.gas.record_cost(FIXED_FEE_GAS); @@ -113,14 +106,18 @@ fn auth_instruction( }; let (to_persist_authority, result) = if Address::from_slice(&signer[12..]) == authority { - (authority, B256::with_last_byte(1)) + (&signer[12..], B256::with_last_byte(1)) } else { - (Address::default(), B256::ZERO) + ((&[] as &[u8]), B256::ZERO) }; - let mut at = &ctx.authorized; - let inner_authorized = at.borrow_mut(); - let _ = inner_authorized.replace(to_persist_authority); + let mut at = &ctx.inner; + let inner_map = at.borrow_mut(); + let new_map: HashMap, Vec> = + vec![(Vec::from(AUTORIZED_VAR_NAME.as_bytes()), Vec::from(to_persist_authority))] + .into_iter() + .collect(); + let _ = inner_map.replace(new_map); if let Err(e) = interp.stack.push_b256(result) { interp.instruction_result = e; @@ -130,7 +127,7 @@ fn auth_instruction( fn authcall_instruction( interp: &mut Interpreter, _evm: &mut Evm<'_, EXT, DB>, - _ctx: &Eip3074Context, + _ctx: &InstructionsContext, ) { interp.gas.record_cost(133); } @@ -221,7 +218,7 @@ mod tests { let mut interpreter = setup_interpreter(); let mut evm = setup_evm(); - auth_instruction(&mut interpreter, &mut evm, &Eip3074Context::default()); + auth_instruction(&mut interpreter, &mut evm, &InstructionsContext::default()); assert_eq!(interpreter.instruction_result, InstructionResult::StackUnderflow); // check gas @@ -245,7 +242,7 @@ mod tests { setup_shared_memory(&mut interpreter.shared_memory, y_parity, &r, &s); let mut evm = setup_evm(); - let context = Eip3074Context::default(); + let context = InstructionsContext::default(); auth_instruction(&mut interpreter, &mut evm, &context); @@ -257,7 +254,11 @@ mod tests { let expected_gas = FIXED_FEE_GAS + COLD_AUTHORITY_GAS; assert_eq!(expected_gas, interpreter.gas.spend()); - assert_eq!(*context.authorized.borrow(), authority); + let inner_map = context.inner.borrow(); + assert_eq!( + inner_map.get(&Vec::from(AUTORIZED_VAR_NAME.as_bytes())).unwrap(), + &authority.to_vec() + ); } #[test] @@ -271,7 +272,7 @@ mod tests { let mut evm = setup_evm(); - auth_instruction(&mut interpreter, &mut evm, &Eip3074Context::default()); + auth_instruction(&mut interpreter, &mut evm, &InstructionsContext::default()); assert_eq!(interpreter.instruction_result, InstructionResult::Stop); @@ -298,7 +299,7 @@ mod tests { let mut evm = setup_evm(); - auth_instruction(&mut interpreter, &mut evm, &Eip3074Context::default()); + auth_instruction(&mut interpreter, &mut evm, &InstructionsContext::default()); assert_eq!(interpreter.instruction_result, InstructionResult::Continue); let result = interpreter.stack.pop().unwrap(); @@ -323,7 +324,7 @@ mod tests { let mut evm = setup_evm(); evm.context.evm.journaled_state.state.insert(authority, Account::default()); - auth_instruction(&mut interpreter, &mut evm, &Eip3074Context::default()); + auth_instruction(&mut interpreter, &mut evm, &InstructionsContext::default()); assert_eq!(interpreter.instruction_result, InstructionResult::Continue); let result = interpreter.stack.pop().unwrap(); @@ -351,7 +352,7 @@ mod tests { let mut evm = setup_evm(); - auth_instruction(&mut interpreter, &mut evm, &Eip3074Context::default()); + auth_instruction(&mut interpreter, &mut evm, &InstructionsContext::default()); assert_eq!(interpreter.instruction_result, InstructionResult::Stop); diff --git a/crates/instructions/src/lib.rs b/crates/instructions/src/lib.rs index bf80f78..0b0ebdd 100644 --- a/crates/instructions/src/lib.rs +++ b/crates/instructions/src/lib.rs @@ -3,6 +3,7 @@ //! Custom instructions for Alphanet. use revm_interpreter::opcode::BoxedInstruction; +use std::{cell::RefCell, collections::HashMap, rc::Rc}; /// EIP-3074 custom instructions. pub mod eip3074; @@ -14,3 +15,20 @@ pub struct BoxedInstructionWithOpCode<'a, H> { /// Boxed instruction. pub boxed_instruction: BoxedInstruction<'a, H>, } + +#[derive(Clone, Default)] +/// Context variables to be used in instructions. The data set here is expected +/// to live for the duration of a single transaction. +pub struct InstructionsContext { + /// Contains the actual variables. Is meant to be accessed both for reads + /// and writes using interior mutability, so that the Instruction and + /// BoxedInstruction signatures are observed. + pub inner: Rc, Vec>>>, +} + +impl InstructionsContext { + /// Empties inner state. + pub fn reset(&mut self) { + self.inner = Rc::new(RefCell::new(HashMap::default())); + } +} diff --git a/crates/node/src/evm.rs b/crates/node/src/evm.rs index 3b25ecb..808f24d 100644 --- a/crates/node/src/evm.rs +++ b/crates/node/src/evm.rs @@ -1,4 +1,4 @@ -use alphanet_instructions::{eip3074, BoxedInstructionWithOpCode}; +use alphanet_instructions::{eip3074, BoxedInstructionWithOpCode, InstructionsContext}; use alphanet_precompile::{bls12_381, secp256r1}; use reth::{ primitives::{ @@ -83,7 +83,14 @@ impl AlphaNetEvmConfig { DB: Database, { if let Some(ref mut table) = handler.instruction_table { - insert_boxed_instructions(table, eip3074::boxed_instructions()); + let mut instructions_context = InstructionsContext::default(); + + insert_boxed_instructions( + table, + eip3074::boxed_instructions(instructions_context.clone()), + ); + + instructions_context.reset(); } } } From b85916e109e2067705c0a355d15909b113938db2 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Sat, 23 Mar 2024 20:23:29 +0100 Subject: [PATCH 24/36] get and set methods for InstructionsContext --- crates/instructions/src/eip3074.rs | 14 +++----------- crates/instructions/src/lib.rs | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/crates/instructions/src/eip3074.rs b/crates/instructions/src/eip3074.rs index d4c6331..c83784f 100644 --- a/crates/instructions/src/eip3074.rs +++ b/crates/instructions/src/eip3074.rs @@ -3,7 +3,6 @@ use revm::{Database, Evm}; use revm_interpreter::{pop, resize_memory, InstructionResult, Interpreter}; use revm_precompile::secp256k1::ecrecover; use revm_primitives::{alloy_primitives::B512, keccak256, Address, B256}; -use std::{borrow::BorrowMut, collections::HashMap}; const AUTH_OPCODE: u8 = 0xF6; const AUTHCALL_OPCODE: u8 = 0xF7; @@ -111,13 +110,7 @@ fn auth_instruction( ((&[] as &[u8]), B256::ZERO) }; - let mut at = &ctx.inner; - let inner_map = at.borrow_mut(); - let new_map: HashMap, Vec> = - vec![(Vec::from(AUTORIZED_VAR_NAME.as_bytes()), Vec::from(to_persist_authority))] - .into_iter() - .collect(); - let _ = inner_map.replace(new_map); + ctx.set(Vec::from(AUTORIZED_VAR_NAME.as_bytes()), Vec::from(to_persist_authority)); if let Err(e) = interp.stack.push_b256(result) { interp.instruction_result = e; @@ -254,10 +247,9 @@ mod tests { let expected_gas = FIXED_FEE_GAS + COLD_AUTHORITY_GAS; assert_eq!(expected_gas, interpreter.gas.spend()); - let inner_map = context.inner.borrow(); assert_eq!( - inner_map.get(&Vec::from(AUTORIZED_VAR_NAME.as_bytes())).unwrap(), - &authority.to_vec() + context.get(Vec::from(AUTORIZED_VAR_NAME.as_bytes())).unwrap(), + authority.to_vec() ); } diff --git a/crates/instructions/src/lib.rs b/crates/instructions/src/lib.rs index 0b0ebdd..719ef46 100644 --- a/crates/instructions/src/lib.rs +++ b/crates/instructions/src/lib.rs @@ -3,7 +3,7 @@ //! Custom instructions for Alphanet. use revm_interpreter::opcode::BoxedInstruction; -use std::{cell::RefCell, collections::HashMap, rc::Rc}; +use std::{borrow::BorrowMut, cell::RefCell, collections::HashMap, rc::Rc}; /// EIP-3074 custom instructions. pub mod eip3074; @@ -27,6 +27,21 @@ pub struct InstructionsContext { } impl InstructionsContext { + /// Sets a value for the given key. Thanks to interior mutability, no need + /// to define on &mut self. + pub fn set(&self, key: Vec, value: Vec) { + let mut at = &self.inner; + let inner_map = at.borrow_mut(); + let new_map: HashMap, Vec> = vec![(key, value)].into_iter().collect(); + let _ = inner_map.replace(new_map); + } + + /// Gets the value for the given key, if any. + pub fn get(&self, key: Vec) -> Option> { + let inner_map = self.inner.borrow(); + inner_map.get(&key).cloned() + } + /// Empties inner state. pub fn reset(&mut self) { self.inner = Rc::new(RefCell::new(HashMap::default())); From 4f86b336cb746588cec4e7e6219e3fc1452d32b8 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Sat, 23 Mar 2024 20:27:56 +0100 Subject: [PATCH 25/36] refactor and &self for InstructionsContext.reset --- crates/instructions/src/lib.rs | 24 ++++++++++++------------ crates/node/src/evm.rs | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/instructions/src/lib.rs b/crates/instructions/src/lib.rs index 719ef46..a99a980 100644 --- a/crates/instructions/src/lib.rs +++ b/crates/instructions/src/lib.rs @@ -3,7 +3,7 @@ //! Custom instructions for Alphanet. use revm_interpreter::opcode::BoxedInstruction; -use std::{borrow::BorrowMut, cell::RefCell, collections::HashMap, rc::Rc}; +use std::{cell::RefCell, collections::HashMap, rc::Rc}; /// EIP-3074 custom instructions. pub mod eip3074; @@ -27,23 +27,23 @@ pub struct InstructionsContext { } impl InstructionsContext { - /// Sets a value for the given key. Thanks to interior mutability, no need - /// to define on &mut self. + /// Sets a value for the given key. pub fn set(&self, key: Vec, value: Vec) { - let mut at = &self.inner; - let inner_map = at.borrow_mut(); - let new_map: HashMap, Vec> = vec![(key, value)].into_iter().collect(); - let _ = inner_map.replace(new_map); + let cell = &self.inner; + let mut map = cell.borrow_mut(); + map.insert(key, value); } /// Gets the value for the given key, if any. pub fn get(&self, key: Vec) -> Option> { - let inner_map = self.inner.borrow(); - inner_map.get(&key).cloned() + let map = self.inner.borrow(); + map.get(&key).cloned() } - /// Empties inner state. - pub fn reset(&mut self) { - self.inner = Rc::new(RefCell::new(HashMap::default())); + /// Empties inner state + pub fn reset(&self) { + let cell = &self.inner; + let mut map = cell.borrow_mut(); + map.clear(); } } diff --git a/crates/node/src/evm.rs b/crates/node/src/evm.rs index 808f24d..91bc3ee 100644 --- a/crates/node/src/evm.rs +++ b/crates/node/src/evm.rs @@ -83,7 +83,7 @@ impl AlphaNetEvmConfig { DB: Database, { if let Some(ref mut table) = handler.instruction_table { - let mut instructions_context = InstructionsContext::default(); + let instructions_context = InstructionsContext::default(); insert_boxed_instructions( table, From 104556013c3cc9ec3183b2cb41817e05bf0f1930 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Sun, 24 Mar 2024 09:13:52 +0100 Subject: [PATCH 26/36] get and set named variables --- crates/instructions/src/eip3074.rs | 7 ++----- crates/instructions/src/lib.rs | 10 ++++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/crates/instructions/src/eip3074.rs b/crates/instructions/src/eip3074.rs index c83784f..3702097 100644 --- a/crates/instructions/src/eip3074.rs +++ b/crates/instructions/src/eip3074.rs @@ -110,7 +110,7 @@ fn auth_instruction( ((&[] as &[u8]), B256::ZERO) }; - ctx.set(Vec::from(AUTORIZED_VAR_NAME.as_bytes()), Vec::from(to_persist_authority)); + ctx.set_named_variable(AUTORIZED_VAR_NAME, Vec::from(to_persist_authority)); if let Err(e) = interp.stack.push_b256(result) { interp.instruction_result = e; @@ -247,10 +247,7 @@ mod tests { let expected_gas = FIXED_FEE_GAS + COLD_AUTHORITY_GAS; assert_eq!(expected_gas, interpreter.gas.spend()); - assert_eq!( - context.get(Vec::from(AUTORIZED_VAR_NAME.as_bytes())).unwrap(), - authority.to_vec() - ); + assert_eq!(context.get_named_variable(AUTORIZED_VAR_NAME).unwrap(), authority.to_vec()); } #[test] diff --git a/crates/instructions/src/lib.rs b/crates/instructions/src/lib.rs index a99a980..a14b706 100644 --- a/crates/instructions/src/lib.rs +++ b/crates/instructions/src/lib.rs @@ -40,6 +40,16 @@ impl InstructionsContext { map.get(&key).cloned() } + /// Sets a value for the given &str as key. + pub fn set_named_variable(&self, key: &str, value: Vec) { + self.set(Vec::from(key.as_bytes()), value); + } + + /// Gets the value for the given &str key, if any. + pub fn get_named_variable(&self, key: &str) -> Option> { + self.get(Vec::from(key.as_bytes())) + } + /// Empties inner state pub fn reset(&self) { let cell = &self.inner; From a7b8e0fc78cf95e0eeb716eb12090b8892452307 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Sun, 24 Mar 2024 13:12:29 +0100 Subject: [PATCH 27/36] instruction context submodule and test with context writer and reader instructions --- crates/instructions/src/context.rs | 124 +++++++++++++++++++++++++++++ crates/instructions/src/eip3074.rs | 2 +- crates/instructions/src/lib.rs | 46 +---------- crates/node/src/evm.rs | 4 +- 4 files changed, 130 insertions(+), 46 deletions(-) create mode 100644 crates/instructions/src/context.rs diff --git a/crates/instructions/src/context.rs b/crates/instructions/src/context.rs new file mode 100644 index 0000000..93a63ef --- /dev/null +++ b/crates/instructions/src/context.rs @@ -0,0 +1,124 @@ +use std::{cell::RefCell, collections::HashMap, rc::Rc}; + +#[derive(Clone, Default)] +/// Context variables to be used in instructions. The data set here is expected +/// to live for the duration of a single transaction. +pub struct InstructionsContext { + /// Contains the actual variables. Is meant to be accessed both for reads + /// and writes using interior mutability, so that the Instruction and + /// BoxedInstruction signatures are observed. + inner: Rc, Vec>>>, +} + +impl InstructionsContext { + /// Sets a value for the given key. + pub fn set(&self, key: Vec, value: Vec) { + let cell = &self.inner; + let mut map = cell.borrow_mut(); + map.insert(key, value); + } + + /// Gets the value for the given key, if any. + pub fn get(&self, key: Vec) -> Option> { + let map = self.inner.borrow(); + map.get(&key).cloned() + } + + /// Sets a value for the given &str as key. + pub fn set_named_variable(&self, key: &str, value: Vec) { + self.set(Vec::from(key.as_bytes()), value); + } + + /// Gets the value for the given &str key, if any. + pub fn get_named_variable(&self, key: &str) -> Option> { + self.get(Vec::from(key.as_bytes())) + } + + /// Empties inner state. + pub fn clear(&self) { + let cell = &self.inner; + let mut map = cell.borrow_mut(); + map.clear(); + } + + /// Empties inner state for the given key. + pub fn remove_named_variable(&self, key: &str) { + let cell = &self.inner; + let mut map = cell.borrow_mut(); + map.remove(&Vec::from(key.as_bytes())); + } +} + +#[cfg(test)] +mod tests { + use super::*; + use revm::{Evm, InMemoryDB}; + use revm_interpreter::Interpreter; + use revm_primitives::{address, AccountInfo, Bytecode, TransactTo, U256}; + + #[test] + fn test_set_get() { + let ctx = InstructionsContext::default(); + let key = "my-key"; + let value = vec![0x01, 0x02]; + + ctx.set_named_variable(key, value.clone()); + + let cloned_ctx = ctx.clone(); + assert_eq!(cloned_ctx.get_named_variable(key).unwrap(), value); + } + + #[test] + fn test_context_variables_are_available_during_tx() { + let code = Bytecode::new_raw([0xEE, 0xEF, 0x00].into()); + let code_hash = code.hash_slow(); + let to_addr = address!("ffffffffffffffffffffffffffffffffffffffff"); + + // initialize the custom context and make sure it's None for a given key + let custom_context = InstructionsContext::default(); + let key = "my-key"; + assert_eq!(custom_context.get_named_variable(key), None); + + let to_capture = custom_context.clone(); + let mut evm = Evm::builder() + .with_db(InMemoryDB::default()) + .modify_db(|db| { + db.insert_account_info(to_addr, AccountInfo::new(U256::ZERO, 0, code_hash, code)) + }) + .modify_tx_env(|tx| tx.transact_to = TransactTo::Call(to_addr)) + .append_handler_register_box(Box::new(move |handler| { + let writer_context = to_capture.clone(); + let writer_instruction = Box::new( + move |_interp: &mut Interpreter, _host: &mut Evm<'_, (), InMemoryDB>| { + // write into the context variable. + writer_context.set_named_variable(key, vec![0x01, 0x02]); + }, + ); + let reader_context = to_capture.clone(); + let reader_instruction = Box::new( + move |_interp: &mut Interpreter, _host: &mut Evm<'_, (), InMemoryDB>| { + // read from context variable and clear. + assert_eq!( + reader_context.get_named_variable(key).unwrap(), + vec![0x01, 0x02] + ); + reader_context.remove_named_variable(key); + }, + ); + + let mut table = handler.take_instruction_table(); + table = table.map(|mut table| { + table.insert_boxed(0xEE, writer_instruction); + table.insert_boxed(0xEF, reader_instruction); + table + }); + handler.instruction_table = table; + })) + .build(); + + let _result_and_state = evm.transact().unwrap(); + + // ensure the custom context was cleared + assert_eq!(custom_context.get_named_variable(key), None); + } +} diff --git a/crates/instructions/src/eip3074.rs b/crates/instructions/src/eip3074.rs index 3702097..9e9d0c5 100644 --- a/crates/instructions/src/eip3074.rs +++ b/crates/instructions/src/eip3074.rs @@ -1,4 +1,4 @@ -use crate::{BoxedInstructionWithOpCode, InstructionsContext}; +use crate::{context::InstructionsContext, BoxedInstructionWithOpCode}; use revm::{Database, Evm}; use revm_interpreter::{pop, resize_memory, InstructionResult, Interpreter}; use revm_precompile::secp256k1::ecrecover; diff --git a/crates/instructions/src/lib.rs b/crates/instructions/src/lib.rs index a14b706..600d74e 100644 --- a/crates/instructions/src/lib.rs +++ b/crates/instructions/src/lib.rs @@ -3,11 +3,13 @@ //! Custom instructions for Alphanet. use revm_interpreter::opcode::BoxedInstruction; -use std::{cell::RefCell, collections::HashMap, rc::Rc}; /// EIP-3074 custom instructions. pub mod eip3074; +/// Instructions context. +pub mod context; + /// Association of OpCode and correspondent boxed instruction. pub struct BoxedInstructionWithOpCode<'a, H> { /// Opcode. @@ -15,45 +17,3 @@ pub struct BoxedInstructionWithOpCode<'a, H> { /// Boxed instruction. pub boxed_instruction: BoxedInstruction<'a, H>, } - -#[derive(Clone, Default)] -/// Context variables to be used in instructions. The data set here is expected -/// to live for the duration of a single transaction. -pub struct InstructionsContext { - /// Contains the actual variables. Is meant to be accessed both for reads - /// and writes using interior mutability, so that the Instruction and - /// BoxedInstruction signatures are observed. - pub inner: Rc, Vec>>>, -} - -impl InstructionsContext { - /// Sets a value for the given key. - pub fn set(&self, key: Vec, value: Vec) { - let cell = &self.inner; - let mut map = cell.borrow_mut(); - map.insert(key, value); - } - - /// Gets the value for the given key, if any. - pub fn get(&self, key: Vec) -> Option> { - let map = self.inner.borrow(); - map.get(&key).cloned() - } - - /// Sets a value for the given &str as key. - pub fn set_named_variable(&self, key: &str, value: Vec) { - self.set(Vec::from(key.as_bytes()), value); - } - - /// Gets the value for the given &str key, if any. - pub fn get_named_variable(&self, key: &str) -> Option> { - self.get(Vec::from(key.as_bytes())) - } - - /// Empties inner state - pub fn reset(&self) { - let cell = &self.inner; - let mut map = cell.borrow_mut(); - map.clear(); - } -} diff --git a/crates/node/src/evm.rs b/crates/node/src/evm.rs index 91bc3ee..c682861 100644 --- a/crates/node/src/evm.rs +++ b/crates/node/src/evm.rs @@ -1,4 +1,4 @@ -use alphanet_instructions::{eip3074, BoxedInstructionWithOpCode, InstructionsContext}; +use alphanet_instructions::{context::InstructionsContext, eip3074, BoxedInstructionWithOpCode}; use alphanet_precompile::{bls12_381, secp256r1}; use reth::{ primitives::{ @@ -90,7 +90,7 @@ impl AlphaNetEvmConfig { eip3074::boxed_instructions(instructions_context.clone()), ); - instructions_context.reset(); + instructions_context.clear(); } } } From 447855457b338172820bd372bf92e13cc97f0ca7 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Sun, 24 Mar 2024 17:41:49 +0100 Subject: [PATCH 28/36] example of using Inspector to clear instruction context --- crates/instructions/src/context.rs | 48 +++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/crates/instructions/src/context.rs b/crates/instructions/src/context.rs index 93a63ef..2429f09 100644 --- a/crates/instructions/src/context.rs +++ b/crates/instructions/src/context.rs @@ -1,3 +1,4 @@ +use revm::{Database, Inspector}; use std::{cell::RefCell, collections::HashMap, rc::Rc}; #[derive(Clone, Default)] @@ -12,14 +13,14 @@ pub struct InstructionsContext { impl InstructionsContext { /// Sets a value for the given key. - pub fn set(&self, key: Vec, value: Vec) { + fn set(&self, key: Vec, value: Vec) { let cell = &self.inner; let mut map = cell.borrow_mut(); map.insert(key, value); } /// Gets the value for the given key, if any. - pub fn get(&self, key: Vec) -> Option> { + fn get(&self, key: Vec) -> Option> { let map = self.inner.borrow(); map.get(&key).cloned() } @@ -40,19 +41,36 @@ impl InstructionsContext { let mut map = cell.borrow_mut(); map.clear(); } +} - /// Empties inner state for the given key. - pub fn remove_named_variable(&self, key: &str) { - let cell = &self.inner; - let mut map = cell.borrow_mut(); - map.remove(&Vec::from(key.as_bytes())); +/// Inspector to manage instructions context. +pub struct InstructionsContextInspector { + instructions_context: InstructionsContext, +} + +impl InstructionsContextInspector { + /// Constructor, sets instructions context. + pub fn new(instructions_context: InstructionsContext) -> Self { + Self { instructions_context } + } +} + +impl Inspector for InstructionsContextInspector { + fn call_end( + &mut self, + _context: &mut revm::EvmContext, + _inputs: &revm_interpreter::CallInputs, + outcome: revm_interpreter::CallOutcome, + ) -> revm_interpreter::CallOutcome { + self.instructions_context.clear(); + outcome } } #[cfg(test)] mod tests { use super::*; - use revm::{Evm, InMemoryDB}; + use revm::{inspector_handle_register, Evm, InMemoryDB}; use revm_interpreter::Interpreter; use revm_primitives::{address, AccountInfo, Bytecode, TransactTo, U256}; @@ -79,30 +97,31 @@ mod tests { let key = "my-key"; assert_eq!(custom_context.get_named_variable(key), None); - let to_capture = custom_context.clone(); + let to_capture_instructions = custom_context.clone(); + let mut evm = Evm::builder() .with_db(InMemoryDB::default()) + .with_external_context(InstructionsContextInspector::new(custom_context.clone())) .modify_db(|db| { db.insert_account_info(to_addr, AccountInfo::new(U256::ZERO, 0, code_hash, code)) }) .modify_tx_env(|tx| tx.transact_to = TransactTo::Call(to_addr)) .append_handler_register_box(Box::new(move |handler| { - let writer_context = to_capture.clone(); + let writer_context = to_capture_instructions.clone(); let writer_instruction = Box::new( - move |_interp: &mut Interpreter, _host: &mut Evm<'_, (), InMemoryDB>| { + move |_interp: &mut Interpreter, _host: &mut Evm<'_, InstructionsContextInspector, InMemoryDB>| { // write into the context variable. writer_context.set_named_variable(key, vec![0x01, 0x02]); }, ); - let reader_context = to_capture.clone(); + let reader_context = to_capture_instructions.clone(); let reader_instruction = Box::new( - move |_interp: &mut Interpreter, _host: &mut Evm<'_, (), InMemoryDB>| { + move |_interp: &mut Interpreter, _host: &mut Evm<'_, InstructionsContextInspector, InMemoryDB>| { // read from context variable and clear. assert_eq!( reader_context.get_named_variable(key).unwrap(), vec![0x01, 0x02] ); - reader_context.remove_named_variable(key); }, ); @@ -114,6 +133,7 @@ mod tests { }); handler.instruction_table = table; })) + .append_handler_register(inspector_handle_register) .build(); let _result_and_state = evm.transact().unwrap(); From 08f6307e02a336829d4b6736097551a37700e11d Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Mon, 25 Mar 2024 16:44:12 +0100 Subject: [PATCH 29/36] use EndHandle to clear context instructions instead of inspector --- Cargo.lock | 4 +--- crates/instructions/src/context.rs | 18 ++++++++++++------ crates/precompile/src/bls12_381.rs | 1 - 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e190558..4c21ab3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -347,12 +347,10 @@ name = "alphanet" version = "0.0.0" dependencies = [ "alphanet-node", - "eyre", + "clap", "reth", "reth-node-optimism", - "reth-tracing", "tikv-jemallocator", - "tokio", "tracing", ] diff --git a/crates/instructions/src/context.rs b/crates/instructions/src/context.rs index 2429f09..5d950b4 100644 --- a/crates/instructions/src/context.rs +++ b/crates/instructions/src/context.rs @@ -70,9 +70,10 @@ impl Inspector for InstructionsContextInspector { #[cfg(test)] mod tests { use super::*; - use revm::{inspector_handle_register, Evm, InMemoryDB}; + use revm::{Evm, InMemoryDB}; use revm_interpreter::Interpreter; use revm_primitives::{address, AccountInfo, Bytecode, TransactTo, U256}; + use std::sync::Arc; #[test] fn test_set_get() { @@ -98,10 +99,9 @@ mod tests { assert_eq!(custom_context.get_named_variable(key), None); let to_capture_instructions = custom_context.clone(); - + let to_capture_post_execution = custom_context.clone(); let mut evm = Evm::builder() .with_db(InMemoryDB::default()) - .with_external_context(InstructionsContextInspector::new(custom_context.clone())) .modify_db(|db| { db.insert_account_info(to_addr, AccountInfo::new(U256::ZERO, 0, code_hash, code)) }) @@ -109,14 +109,14 @@ mod tests { .append_handler_register_box(Box::new(move |handler| { let writer_context = to_capture_instructions.clone(); let writer_instruction = Box::new( - move |_interp: &mut Interpreter, _host: &mut Evm<'_, InstructionsContextInspector, InMemoryDB>| { + move |_interp: &mut Interpreter, _host: &mut Evm<'_, (), InMemoryDB>| { // write into the context variable. writer_context.set_named_variable(key, vec![0x01, 0x02]); }, ); let reader_context = to_capture_instructions.clone(); let reader_instruction = Box::new( - move |_interp: &mut Interpreter, _host: &mut Evm<'_, InstructionsContextInspector, InMemoryDB>| { + move |_interp: &mut Interpreter, _host: &mut Evm<'_, (), InMemoryDB>| { // read from context variable and clear. assert_eq!( reader_context.get_named_variable(key).unwrap(), @@ -133,7 +133,13 @@ mod tests { }); handler.instruction_table = table; })) - .append_handler_register(inspector_handle_register) + .append_handler_register_box(Box::new(move |handler| { + let ctx = to_capture_post_execution.clone(); + handler.post_execution.end = Arc::new(move |_, outcome: _| { + ctx.clear(); + outcome + }); + })) .build(); let _result_and_state = evm.transact().unwrap(); diff --git a/crates/precompile/src/bls12_381.rs b/crates/precompile/src/bls12_381.rs index f22a2d1..ee902b5 100644 --- a/crates/precompile/src/bls12_381.rs +++ b/crates/precompile/src/bls12_381.rs @@ -299,7 +299,6 @@ mod test { #[case::fail_violate_top_bytes("0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000108b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e10000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1", "", true, 500)] #[case::fail_invalid_field_element("0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb000000000000000000000000000000001a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaac0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1", "", true, 500)] #[case::fail_point_not_on_curve("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1", "", true, 500)] - #[case::g1_add_g1_plus_g1_equals_2_times_g1("0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e10000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1", "000000000000000000000000000000000572cbea904d67468808c8eb50a9450c9721db309128012543902d0ac358a62ae28f75bb8f1c7c42c39a8c5529bf0f4e00000000000000000000000000000000166a9d8cabc673a322fda673779d8e3822ba3ecb8670e461f73bb9021d5fd76a4c56d9d4cd16bd1bba86881979749d28", false, 500)] fn test_g1_add( #[case] input: &str, #[case] expected_output: &str, From 860d5d0a52ec4888d48e8ea1eeacf3dcbf8b49cb Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Mon, 25 Mar 2024 17:34:03 +0100 Subject: [PATCH 30/36] InstructionContext handles &'static str keys --- crates/instructions/src/context.rs | 31 +++++++++--------------------- crates/instructions/src/eip3074.rs | 4 ++-- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/crates/instructions/src/context.rs b/crates/instructions/src/context.rs index 5d950b4..55ff8fa 100644 --- a/crates/instructions/src/context.rs +++ b/crates/instructions/src/context.rs @@ -8,33 +8,23 @@ pub struct InstructionsContext { /// Contains the actual variables. Is meant to be accessed both for reads /// and writes using interior mutability, so that the Instruction and /// BoxedInstruction signatures are observed. - inner: Rc, Vec>>>, + inner: Rc>>>, } impl InstructionsContext { /// Sets a value for the given key. - fn set(&self, key: Vec, value: Vec) { + pub fn set(&self, key: &'static str, value: Vec) { let cell = &self.inner; let mut map = cell.borrow_mut(); map.insert(key, value); } /// Gets the value for the given key, if any. - fn get(&self, key: Vec) -> Option> { + pub fn get(&self, key: &'static str) -> Option> { let map = self.inner.borrow(); map.get(&key).cloned() } - /// Sets a value for the given &str as key. - pub fn set_named_variable(&self, key: &str, value: Vec) { - self.set(Vec::from(key.as_bytes()), value); - } - - /// Gets the value for the given &str key, if any. - pub fn get_named_variable(&self, key: &str) -> Option> { - self.get(Vec::from(key.as_bytes())) - } - /// Empties inner state. pub fn clear(&self) { let cell = &self.inner; @@ -81,10 +71,10 @@ mod tests { let key = "my-key"; let value = vec![0x01, 0x02]; - ctx.set_named_variable(key, value.clone()); + ctx.set(key, value.clone()); let cloned_ctx = ctx.clone(); - assert_eq!(cloned_ctx.get_named_variable(key).unwrap(), value); + assert_eq!(cloned_ctx.get(key).unwrap(), value); } #[test] @@ -96,7 +86,7 @@ mod tests { // initialize the custom context and make sure it's None for a given key let custom_context = InstructionsContext::default(); let key = "my-key"; - assert_eq!(custom_context.get_named_variable(key), None); + assert_eq!(custom_context.get(key), None); let to_capture_instructions = custom_context.clone(); let to_capture_post_execution = custom_context.clone(); @@ -111,17 +101,14 @@ mod tests { let writer_instruction = Box::new( move |_interp: &mut Interpreter, _host: &mut Evm<'_, (), InMemoryDB>| { // write into the context variable. - writer_context.set_named_variable(key, vec![0x01, 0x02]); + writer_context.set(key, vec![0x01, 0x02]); }, ); let reader_context = to_capture_instructions.clone(); let reader_instruction = Box::new( move |_interp: &mut Interpreter, _host: &mut Evm<'_, (), InMemoryDB>| { // read from context variable and clear. - assert_eq!( - reader_context.get_named_variable(key).unwrap(), - vec![0x01, 0x02] - ); + assert_eq!(reader_context.get(key).unwrap(), vec![0x01, 0x02]); }, ); @@ -145,6 +132,6 @@ mod tests { let _result_and_state = evm.transact().unwrap(); // ensure the custom context was cleared - assert_eq!(custom_context.get_named_variable(key), None); + assert_eq!(custom_context.get(key), None); } } diff --git a/crates/instructions/src/eip3074.rs b/crates/instructions/src/eip3074.rs index 9e9d0c5..f60f786 100644 --- a/crates/instructions/src/eip3074.rs +++ b/crates/instructions/src/eip3074.rs @@ -110,7 +110,7 @@ fn auth_instruction( ((&[] as &[u8]), B256::ZERO) }; - ctx.set_named_variable(AUTORIZED_VAR_NAME, Vec::from(to_persist_authority)); + ctx.set(AUTORIZED_VAR_NAME, Vec::from(to_persist_authority)); if let Err(e) = interp.stack.push_b256(result) { interp.instruction_result = e; @@ -247,7 +247,7 @@ mod tests { let expected_gas = FIXED_FEE_GAS + COLD_AUTHORITY_GAS; assert_eq!(expected_gas, interpreter.gas.spend()); - assert_eq!(context.get_named_variable(AUTORIZED_VAR_NAME).unwrap(), authority.to_vec()); + assert_eq!(context.get(AUTORIZED_VAR_NAME).unwrap(), authority.to_vec()); } #[test] From 29c2f0bd3cf9f309a6d54109aba178c5c0c11be4 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Mon, 25 Mar 2024 17:34:17 +0100 Subject: [PATCH 31/36] allow clippy --- crates/instructions/src/context.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/instructions/src/context.rs b/crates/instructions/src/context.rs index 55ff8fa..080c495 100644 --- a/crates/instructions/src/context.rs +++ b/crates/instructions/src/context.rs @@ -122,10 +122,13 @@ mod tests { })) .append_handler_register_box(Box::new(move |handler| { let ctx = to_capture_post_execution.clone(); - handler.post_execution.end = Arc::new(move |_, outcome: _| { - ctx.clear(); - outcome - }); + #[allow(clippy::arc_with_non_send_sync)] + { + handler.post_execution.end = Arc::new(move |_, outcome: _| { + ctx.clear(); + outcome + }); + } })) .build(); From 354ff2380c5fc31c08b96b58c0eb9dc5c2685fbb Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Mon, 25 Mar 2024 17:35:39 +0100 Subject: [PATCH 32/36] InstructionsContext doc --- crates/instructions/src/context.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/instructions/src/context.rs b/crates/instructions/src/context.rs index 080c495..be1ec91 100644 --- a/crates/instructions/src/context.rs +++ b/crates/instructions/src/context.rs @@ -4,6 +4,7 @@ use std::{cell::RefCell, collections::HashMap, rc::Rc}; #[derive(Clone, Default)] /// Context variables to be used in instructions. The data set here is expected /// to live for the duration of a single transaction. +/// Similar to TStore for arbitrary data. pub struct InstructionsContext { /// Contains the actual variables. Is meant to be accessed both for reads /// and writes using interior mutability, so that the Instruction and From 8f397e10ab5e7dad9825c08844878ce1e80bb672 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Mon, 25 Mar 2024 17:39:13 +0100 Subject: [PATCH 33/36] simplify InstructionContext methods --- crates/instructions/src/context.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/crates/instructions/src/context.rs b/crates/instructions/src/context.rs index be1ec91..008feee 100644 --- a/crates/instructions/src/context.rs +++ b/crates/instructions/src/context.rs @@ -15,22 +15,17 @@ pub struct InstructionsContext { impl InstructionsContext { /// Sets a value for the given key. pub fn set(&self, key: &'static str, value: Vec) { - let cell = &self.inner; - let mut map = cell.borrow_mut(); - map.insert(key, value); + let _ = self.inner.borrow_mut().insert(key, value); } /// Gets the value for the given key, if any. pub fn get(&self, key: &'static str) -> Option> { - let map = self.inner.borrow(); - map.get(&key).cloned() + self.inner.borrow().get(&key).cloned() } /// Empties inner state. pub fn clear(&self) { - let cell = &self.inner; - let mut map = cell.borrow_mut(); - map.clear(); + self.inner.borrow_mut().clear(); } } From 821d4d94e591e0af0ddb5605852d9343063bcc95 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Mon, 25 Mar 2024 17:51:57 +0100 Subject: [PATCH 34/36] remove inspector --- crates/instructions/src/context.rs | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/crates/instructions/src/context.rs b/crates/instructions/src/context.rs index 008feee..ad87d4f 100644 --- a/crates/instructions/src/context.rs +++ b/crates/instructions/src/context.rs @@ -1,4 +1,3 @@ -use revm::{Database, Inspector}; use std::{cell::RefCell, collections::HashMap, rc::Rc}; #[derive(Clone, Default)] @@ -29,30 +28,6 @@ impl InstructionsContext { } } -/// Inspector to manage instructions context. -pub struct InstructionsContextInspector { - instructions_context: InstructionsContext, -} - -impl InstructionsContextInspector { - /// Constructor, sets instructions context. - pub fn new(instructions_context: InstructionsContext) -> Self { - Self { instructions_context } - } -} - -impl Inspector for InstructionsContextInspector { - fn call_end( - &mut self, - _context: &mut revm::EvmContext, - _inputs: &revm_interpreter::CallInputs, - outcome: revm_interpreter::CallOutcome, - ) -> revm_interpreter::CallOutcome { - self.instructions_context.clear(); - outcome - } -} - #[cfg(test)] mod tests { use super::*; From cec20f1f09146941f5211acc611f670256305464 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Mon, 25 Mar 2024 19:06:16 +0100 Subject: [PATCH 35/36] typo --- crates/instructions/src/eip3074.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/instructions/src/eip3074.rs b/crates/instructions/src/eip3074.rs index f60f786..e59fb62 100644 --- a/crates/instructions/src/eip3074.rs +++ b/crates/instructions/src/eip3074.rs @@ -10,7 +10,7 @@ const MAGIC: u8 = 0x04; const WARM_AUTHORITY_GAS: u64 = 100; const COLD_AUTHORITY_GAS: u64 = 2600; const FIXED_FEE_GAS: u64 = 3100; -const AUTORIZED_VAR_NAME: &str = "authorized"; +const AUTHORIZED_VAR_NAME: &str = "authorized"; /// eip3074 boxed instructions. pub fn boxed_instructions<'a, EXT: 'a, DB: Database + 'a>( @@ -110,7 +110,7 @@ fn auth_instruction( ((&[] as &[u8]), B256::ZERO) }; - ctx.set(AUTORIZED_VAR_NAME, Vec::from(to_persist_authority)); + ctx.set(AUTHORIZED_VAR_NAME, Vec::from(to_persist_authority)); if let Err(e) = interp.stack.push_b256(result) { interp.instruction_result = e; @@ -247,7 +247,7 @@ mod tests { let expected_gas = FIXED_FEE_GAS + COLD_AUTHORITY_GAS; assert_eq!(expected_gas, interpreter.gas.spend()); - assert_eq!(context.get(AUTORIZED_VAR_NAME).unwrap(), authority.to_vec()); + assert_eq!(context.get(AUTHORIZED_VAR_NAME).unwrap(), authority.to_vec()); } #[test] From 0ad59487d22e925b6197f23ff86f6c926906adc3 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Mon, 25 Mar 2024 19:08:44 +0100 Subject: [PATCH 36/36] merge handler_registers --- crates/instructions/src/context.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/instructions/src/context.rs b/crates/instructions/src/context.rs index ad87d4f..be4072d 100644 --- a/crates/instructions/src/context.rs +++ b/crates/instructions/src/context.rs @@ -90,13 +90,12 @@ mod tests { table }); handler.instruction_table = table; - })) - .append_handler_register_box(Box::new(move |handler| { - let ctx = to_capture_post_execution.clone(); + + let post_execution_context = to_capture_post_execution.clone(); #[allow(clippy::arc_with_non_send_sync)] { handler.post_execution.end = Arc::new(move |_, outcome: _| { - ctx.clear(); + post_execution_context.clear(); outcome }); }