-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
alloy-consensus crate #83
Conversation
ty ty i will update here soon |
726a92b
to
c7d7de5
Compare
wip: port ser tests feature: Parity::chain_id test: normalize 27/28 fix: properly normalize in recovery fix: serde works now refactor wip: lots of stuff refactor: push signature into core primitives feat: seal feat: seal fix: k256 feature in network feature: rlp for TxLegacy feature: block wip test fix: payload lenght feat: sealable feature: Tx types tests: they pass???? refactor: envelope module refactor: TxType refactor: simpler rlp enc/decode for envelope fix: todo feature: enable sign_transaction feat: some froms and some cleanup lint: clippy fix: test feature fix: network receipt bounds receipt.rs restore providers
7c1b541
to
87ee3b5
Compare
match self.chain_id() { | ||
Some(tx_chain_id) => { | ||
if tx_chain_id != chain_id { | ||
return Err(crate::Error::TransactionChainIdMismatch { | ||
signer: chain_id, | ||
tx: tx_chain_id, | ||
}); | ||
} | ||
} | ||
None => { | ||
self.set_chain_id(chain_id); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can simplify with
let Some(tx_chain_id) = self.chain_id() { else self.set_chain_Id(chain_id); return Ok(()) };
and pull the error check outside
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't think it makes it any simpler
let chain_id = self.chain_id(); | ||
if let Some(chain_id) = chain_id { | ||
tx.set_chain_id_checked(chain_id)?; | ||
} | ||
let mut sig = self.sign_hash(tx.signature_hash()).await?; | ||
if let Some(chain_id) = chain_id.or_else(|| tx.chain_id()) { | ||
sig = sig.with_chain_id(chain_id); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great!
tx.chain_id = Some(1); | ||
let sig_1 = sign_tx_test(&mut tx, None).await.unwrap(); | ||
let expected = "c9cf86333bcb065d140032ecaab5d9281bde80f21b9687b3e94161de42d51895727a108a0b8d101465414033c3f705a9c7b826e596766046ee1183dbc8aeaa6825".parse().unwrap(); | ||
assert_eq!(sig_1, expected); | ||
assert_ne!(sig_1, sig_none); | ||
|
||
tx.chain_id = Some(2); | ||
let sig_2 = sign_tx_test(&mut tx, None).await.unwrap(); | ||
assert_ne!(sig_2, sig_1); | ||
assert_ne!(sig_2, sig_none); | ||
|
||
// Sets chain ID. | ||
tx.chain_id = None; | ||
let sig_none_none = sign_tx_test(&mut tx, None).await.unwrap(); | ||
assert_eq!(sig_none_none, sig_none); | ||
|
||
tx.chain_id = None; | ||
let sig_none_1 = sign_tx_test(&mut tx, Some(1)).await.unwrap(); | ||
assert_eq!(sig_none_1, sig_1); | ||
|
||
tx.chain_id = None; | ||
let sig_none_2 = sign_tx_test(&mut tx, Some(2)).await.unwrap(); | ||
assert_eq!(sig_none_2, sig_2); | ||
|
||
// Errors on mismatch. | ||
tx.chain_id = Some(2); | ||
let error = sign_tx_test(&mut tx, Some(1)).await.unwrap_err(); | ||
let expected_error = crate::Error::TransactionChainIdMismatch { signer: 1, tx: 2 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great!
crates/signer-aws/src/signer.rs
Outdated
#[cfg(TODO)] // TODO: TypedTransaction | ||
#[instrument(err)] | ||
async fn sign_transaction(&self, tx: &TypedTransaction) -> Result<Signature> { | ||
let mut tx_with_chain = tx.clone(); | ||
let chain_id = tx_with_chain.chain_id().map(|id| id.as_u64()).unwrap_or(self.chain_id); | ||
tx_with_chain.set_chain_id(chain_id); | ||
|
||
let sighash = tx_with_chain.sighash(); | ||
self.sign_digest_with_eip155(sighash, chain_id).await | ||
self.sign_digest_inner(hash).await.map_err(alloy_signer::Error::other) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did we lose tx signing on aws signer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uses default impl just like wallet
crates/signer-trezor/src/signer.rs
Outdated
#[inline] | ||
async fn sign_transaction(&self, tx: &TypedTransaction) -> Result<Signature> { | ||
#[cfg(TODO)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
work in progress
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #100 as a possible solution
Would love if we can use this to remove a bunch of the Reth storage types. Might mean either manual impls of the Compact trait, or derives on newtypes. Either way would simplify things on Reth side. A fast follow to this PR should remove final Ethers usage from Header etc. types from Anvil. |
* feat: implement sign_transaction on Trezor * fix: dyn trait upcasting is not stable yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all of this looks reasonable to me.
it's a lot of code, most of it comes from reth directly. imo it's fine (for now) that we have them duplicated, but want to upstream this to reth soonish.
didn't review the trait abstractions too closely, because I think those are still highly unstable, but the approach is fine.
we have a lot of room for follow ups, for example, extracting constants
crates/eips/src/eip4844.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed with @prestwich we want to move a lot of these into a alloy-eip-constants crate or something similar, so revm can easily import those and we don't have them in two places
pub struct BlockResponse<N: Network> { | ||
#[serde(flatten)] | ||
header: N::HeaderResponse, | ||
transactions: TransactionList<N::TransactionResponse>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this probably doesn't work for Uncle blocks, so we either need a type for the uncle requests which is just N::HeaderResponse or do some serde magic here, using a dedicated UncleResponse is probably better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good w me - let's get this in so we can finish the anvil core transition
Cargo.toml
Outdated
k256 = { version = "0.13.2", default-features = false, features = ["ecdsa", "std"] } | ||
sha2 = { version = "0.10.8", default-features = false, features = ["std"] } | ||
spki = { version = "0.7.2", default-features = false, features = ["std"] } | ||
c-kzg = "0.4.0" # for eip-4844 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally this would be optional but maybe not possible here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the workspace dependencies, but anyway it's unused
tempfile = "3.8" | ||
|
||
[patch.crates-io] | ||
alloy-primitives = { git = "https://github.com/alloy-rs/core" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this will need a 0.6 release
crates/eips/src/eip2718.rs
Outdated
|
||
/// True if the envelope is the legacy variant. | ||
fn is_legacy(&self) -> bool { | ||
self.type_flag().is_none() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this also be for Some(0)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess so, added in 1a240d0
// TODO: Remove in favor of dyn trait upcasting (1.76+) | ||
#[doc(hidden)] | ||
impl<S: 'static> dyn Transaction<Signature = S> { | ||
pub fn __downcast_ref<T: std::any::Any>(&self) -> Option<&T> { | ||
if std::any::Any::type_id(self) == std::any::TypeId::of::<T>() { | ||
unsafe { Some(&*(self as *const _ as *const T)) } | ||
} else { | ||
None | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI @prestwich this was needed for the trezor signer
Motivation
Have signature type support the JSON v and yParity formats
Solution
Signature keeps vrs AND an ecdsa::Signature in memory.
PR Checklist