-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: cast mktx raw signaturee #10377
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
Open
Ayushdubey86
wants to merge
8
commits into
foundry-rs:master
Choose a base branch
from
Ayushdubey86:feat-cast-mktx-raw-signaturee
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
301e94d
(cast mktx --raw-unsigned): support signing with provided v, r, s
Ayushdubey86 7b500f6
Update revert_handlers.rs
Ayushdubey86 fd3ec0e
Update error.rs
Ayushdubey86 e77a35f
Update error.rs
Ayushdubey86 15aee50
Merge branch 'master' into feat-cast-mktx-raw-signaturee
Ayushdubey86 f9f3790
Merge branch 'master' into feat-cast-mktx-raw-signaturee
Ayushdubey86 601401c
Merge branch 'master' into feat-cast-mktx-raw-signaturee
Ayushdubey86 9242493
Merge branch 'master' into feat-cast-mktx-raw-signaturee
Ayushdubey86 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
use crate::tx::{self, CastTxBuilder}; | ||
use alloy_network::{eip2718::Encodable2718, EthereumWallet, TransactionBuilder}; | ||
use alloy_primitives::hex; | ||
use alloy_primitives::{hex, Address, Bytes, U256, U64}; | ||
use alloy_rlp::{Decodable, RlpDecodable, RlpEncodable}; | ||
use alloy_signer::Signer; | ||
use clap::Parser; | ||
use eyre::{OptionExt, Result}; | ||
|
@@ -50,6 +51,25 @@ pub struct MakeTxArgs { | |
/// Relaxes the wallet requirement. | ||
#[arg(long, requires = "from")] | ||
raw_unsigned: bool, | ||
|
||
#[arg(long, value_name = "V")] | ||
v: Option<u64>, | ||
|
||
#[arg(long, value_name = "R")] | ||
r: Option<String>, | ||
|
||
#[arg(long, value_name = "S")] | ||
s: Option<String>, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, RlpDecodable, RlpEncodable)] | ||
pub struct UnsignedTransaction { | ||
pub nonce: U256, | ||
pub gas_price: U256, | ||
pub gas_limit: U256, | ||
pub to: Address, | ||
pub value: U256, | ||
pub data: Bytes, | ||
} | ||
|
||
#[derive(Debug, Parser)] | ||
|
@@ -70,7 +90,13 @@ pub enum MakeTxSubcommands { | |
|
||
impl MakeTxArgs { | ||
pub async fn run(self) -> Result<()> { | ||
let Self { to, mut sig, mut args, command, tx, path, eth, raw_unsigned } = self; | ||
let Self { mut to, mut sig, mut args, command, tx, path, eth, raw_unsigned, v, r, s } = | ||
self; | ||
|
||
if !raw_unsigned && to.is_none() && !args.is_empty() { | ||
let to_str = args.remove(0); | ||
to = Some(NameOrAddress::from_str(&to_str)?); | ||
} | ||
|
||
let blob_data = if let Some(path) = path { Some(std::fs::read(path)?) } else { None }; | ||
|
||
|
@@ -100,15 +126,50 @@ impl MakeTxArgs { | |
.with_blob_data(blob_data)?; | ||
|
||
if raw_unsigned { | ||
// Build unsigned raw tx | ||
let from = eth.wallet.from.ok_or_eyre("missing `--from` address")?; | ||
let raw_tx = tx_builder.build_unsigned_raw(from).await?; | ||
let raw_unsigned_hex = tx_builder.build_unsigned_raw(from).await?; | ||
|
||
if let (Some(v), Some(r_hex), Some(s_hex)) = (v, r.as_ref(), s.as_ref()) { | ||
let raw_unsigned_bytes = hex::decode(raw_unsigned_hex.trim_start_matches("0x"))?; | ||
let mut buf = raw_unsigned_bytes.as_slice(); | ||
let unsigned_tx: UnsignedTransaction = UnsignedTransaction::decode(&mut buf)?; | ||
|
||
let r_bytes = hex::decode(r_hex.trim_start_matches("0x"))?; | ||
let s_bytes = hex::decode(s_hex.trim_start_matches("0x"))?; | ||
|
||
if r_bytes.len() != 32 || s_bytes.len() != 32 { | ||
eyre::bail!("r and s must be 32 bytes each"); | ||
} | ||
|
||
let r = U256::from_be_slice(&r_bytes); | ||
let s = U256::from_be_slice(&s_bytes); | ||
let v = U64::from(v); | ||
|
||
let mut out = Vec::new(); | ||
let fields: &[&dyn alloy_rlp::Encodable] = &[ | ||
&unsigned_tx.nonce, | ||
&unsigned_tx.gas_price, | ||
&unsigned_tx.gas_limit, | ||
&unsigned_tx.to, | ||
&unsigned_tx.value, | ||
&unsigned_tx.data, | ||
&v, | ||
&r, | ||
&s, | ||
]; | ||
|
||
alloy_rlp::encode_list::<&dyn alloy_rlp::Encodable, dyn alloy_rlp::Encodable>( | ||
Comment on lines
+130
to
+161
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can removed entirely this should be much simpler, just checking if the signature is there , decode it and then encode with signature: |
||
fields, &mut out, | ||
); | ||
|
||
sh_println!("0x{}", hex::encode(out))?; | ||
} else { | ||
sh_println!("{}", raw_unsigned_hex)?; | ||
} | ||
|
||
sh_println!("{raw_tx}")?; | ||
return Ok(()); | ||
} | ||
|
||
// Retrieve the signer, and bail if it can't be constructed. | ||
let signer = eth.wallet.signer().await?; | ||
let from = signer.address(); | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 should be a single argument that tis the hex encoded signature