Skip to content

Commit cb0e9b2

Browse files
committed
ci: use cargo hack
1 parent b476a71 commit cb0e9b2

File tree

6 files changed

+47
-30
lines changed

6 files changed

+47
-30
lines changed

.cargo-husky/hooks/pre-commit

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fi
1414
set -xe
1515

1616
# Setting RUSTFLAGS env for clippy makes it not include custom rules
17-
RUSTFLAGS=-Dwarnings cargo check --workspace --all-targets --profile bench ${ALL_FEATURES}
17+
RUSTFLAGS=-Dwarnings cargo hack check --feature-powerset --no-dev-deps
1818
cargo clippy --all --all-targets ${ALL_FEATURES} -- -D warnings
1919
cargo fmt --all -- --check
2020
cargo test --doc --workspace ${ALL_FEATURES}

.github/workflows/hardhat-core-ci.yml

+6-9
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,16 @@ jobs:
5353
profile: minimal
5454
override: true
5555

56-
- uses: Swatinem/rust-cache@v2
56+
# Install pre-built binaries for cargo hack
57+
- uses: taiki-e/install-action@cargo-hack
5758

58-
- name: Cargo check
59-
uses: actions-rs/cargo@v1
60-
with:
61-
command: check
62-
args: --workspace --all-features --all-targets --profile bench
59+
- uses: Swatinem/rust-cache@v2
6360

64-
- name: Cargo check without all features
61+
- name: Cargo hack
6562
uses: actions-rs/cargo@v1
6663
with:
67-
command: check
68-
args: --workspace --all-targets --no-default-features --profile bench
64+
command: hack
65+
args: check --feature-powerset --no-dev-deps
6966

7067
test-core:
7168
name: Test core (${{ matrix.os }}, Node ${{ matrix.node }}, ${{ matrix.vm }})

Brewfile

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
tap "taiki-e/tap"
2+
13
# Rust toolchain
24
brew "rustup-init"
5+
# Cargo hack CLI
6+
brew "taiki-e/tap/cargo-hack"
37
# NodeJS version 18
48
brew "node@18"
59
# Yarn package manager for NodeJS

crates/rethnet_eth/src/block.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,22 @@ mod reorg;
1010

1111
use std::sync::OnceLock;
1212

13-
use revm_primitives::{
14-
keccak256,
15-
ruint::{self, aliases::U160},
16-
SpecId, B160,
17-
};
13+
use revm_primitives::{keccak256, ruint::aliases::U160, SpecId, B160};
1814
use rlp::Decodable;
1915

16+
#[cfg(feature = "serde")]
17+
use revm_primitives::ruint;
18+
2019
use crate::{
21-
remote::eth::{self, TransactionConversionError},
2220
transaction::SignedTransaction,
2321
trie::{self, KECCAK_NULL_RLP},
2422
withdrawal::Withdrawal,
2523
Address, Bloom, Bytes, B256, B64, U256,
2624
};
2725

26+
#[cfg(feature = "serde")]
27+
use crate::remote::eth::{self, TransactionConversionError};
28+
2829
use self::difficulty::calculate_ethash_canonical_difficulty;
2930
pub use self::{
3031
detailed::DetailedBlock,
@@ -103,6 +104,7 @@ impl PartialEq for Block {
103104

104105
/// Error that occurs when trying to convert the JSON-RPC `Block` type.
105106
#[derive(Debug, thiserror::Error)]
107+
#[cfg(feature = "serde")]
106108
pub enum BlockConversionError {
107109
/// Missing miner
108110
#[error("Missing miner")]
@@ -118,6 +120,7 @@ pub enum BlockConversionError {
118120
TransactionConversionError(#[from] TransactionConversionError),
119121
}
120122

123+
#[cfg(feature = "serde")]
121124
impl TryFrom<eth::Block<eth::Transaction>> for BlockAndCallers {
122125
type Error = BlockConversionError;
123126

@@ -208,9 +211,9 @@ pub struct Header {
208211
pub withdrawals_root: Option<B256>,
209212
}
210213

211-
#[cfg(feature = "serde")]
212214
#[derive(serde::Serialize, serde::Deserialize)]
213215
#[serde(remote = "B64")]
216+
#[cfg(feature = "serde")]
214217
struct B64Def(#[serde(getter = "B64::as_uint")] ruint::aliases::U64);
215218

216219
#[cfg(feature = "serde")]

crates/rethnet_eth/src/signature.rs

+23-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use secp256k1::{
1111
PublicKey, Secp256k1, SecretKey, SignOnly, ThirtyTwoByteHash,
1212
};
1313
use sha3::{Digest, Keccak256};
14-
use thiserror::Error;
1514

1615
use crate::{utils::hash_message, Address, B256, U256};
1716

@@ -52,23 +51,30 @@ fn private_to_public_key(
5251
}
5352

5453
/// An error involving a signature.
55-
#[derive(Debug, Error)]
54+
#[derive(Debug)]
55+
#[cfg_attr(feature = "std", derive(thiserror::Error))]
5656
pub enum SignatureError {
5757
/// Invalid length, secp256k1 signatures are 65 bytes
58-
#[error("invalid signature length, got {0}, expected 65")]
58+
#[cfg_attr(
59+
feature = "std",
60+
error("invalid signature length, got {0}, expected 65")
61+
)]
5962
InvalidLength(usize),
6063
/// When parsing a signature from string to hex
61-
#[error(transparent)]
62-
DecodingError(#[from] hex::FromHexError),
64+
#[cfg_attr(feature = "std", error(transparent))]
65+
DecodingError(#[cfg_attr(feature = "std", from)] hex::FromHexError),
6366
/// Thrown when signature verification failed (i.e. when the address that
6467
/// produced the signature did not match the expected address)
65-
#[error("Signature verification failed. Expected {0}, got {1}")]
68+
#[cfg_attr(
69+
feature = "std",
70+
error("Signature verification failed. Expected {0}, got {1}")
71+
)]
6672
VerificationError(Address, Address),
6773
/// Internal error during signature recovery
68-
#[error(transparent)]
69-
K256Error(#[from] secp256k1::Error),
74+
#[cfg_attr(feature = "std", error(transparent))]
75+
K256Error(#[cfg_attr(feature = "std", from)] secp256k1::Error),
7076
/// Error in recovering public key from signature
71-
#[error("Public key recovery error")]
77+
#[cfg_attr(feature = "std", error("Public key recovery error"))]
7278
RecoveryError,
7379
}
7480

@@ -186,7 +192,9 @@ impl Signature {
186192
let (recoverable_sig, _recovery_id) = self.as_signature()?;
187193

188194
let context = Secp256k1::verification_only();
189-
let public_key = context.recover_ecdsa(&message_hash.into(), &recoverable_sig)?;
195+
let public_key = context
196+
.recover_ecdsa(&message_hash.into(), &recoverable_sig)
197+
.map_err(SignatureError::K256Error)?;
190198

191199
Ok(public_key_to_address(public_key))
192200
}
@@ -202,7 +210,8 @@ impl Signature {
202210
bytes[..32].copy_from_slice(&r_bytes);
203211
bytes[32..64].copy_from_slice(&s_bytes);
204212

205-
RecoverableSignature::from_compact(&bytes, recovery_id)?
213+
RecoverableSignature::from_compact(&bytes, recovery_id)
214+
.map_err(SignatureError::K256Error)?
206215
};
207216

208217
Ok((signature, recovery_id))
@@ -211,7 +220,7 @@ impl Signature {
211220
/// Retrieve the recovery ID.
212221
pub fn recovery_id(&self) -> Result<RecoveryId, SignatureError> {
213222
let standard_v = normalize_recovery_id(self.v);
214-
Ok(RecoveryId::from_i32(standard_v)?)
223+
RecoveryId::from_i32(standard_v).map_err(SignatureError::K256Error)
215224
}
216225

217226
/// Copies and serializes `self` into a new `Vec` with the recovery id included
@@ -283,12 +292,13 @@ impl<'a> TryFrom<&'a [u8]> for Signature {
283292
}
284293
}
285294

295+
#[cfg(feature = "std")]
286296
impl FromStr for Signature {
287297
type Err = SignatureError;
288298

289299
fn from_str(s: &str) -> Result<Self, Self::Err> {
290300
let s = s.strip_prefix("0x").unwrap_or(s);
291-
let bytes = hex::decode(s)?;
301+
let bytes = hex::decode(s).map_err(SignatureError::DecodingError)?;
292302
Signature::try_from(&bytes[..])
293303
}
294304
}

scripts/setup.sh

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ rust_version=$(<rust-toolchain)
66
# rustup
77
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $rust_version
88

9+
# cargo hack CLI
10+
cargo install cargo-hack
11+
912
sudo apt update
1013

1114
# TODO: nodejs, npm, yarn

0 commit comments

Comments
 (0)