Skip to content
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

feat(api-server): add yParity for non-legacy txs #3246

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions core/lib/dal/src/models/storage_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,13 @@ impl StorageApiTransaction {
.or_else(|| self.max_fee_per_gas.clone())
.unwrap_or_else(BigDecimal::zero),
};
// Legacy transactions are not supposed to have `yParity` and are reliant on `v` instead.
// Other transactions are required to have `yParity` which replaces the deprecated `v` value
// (still included for backwards compatibility).
let y_parity = match self.tx_format {
None | Some(0) => None,
_ => signature.as_ref().map(|s| U64::from(s.v())),
};
let mut tx = api::Transaction {
hash: H256::from_slice(&self.tx_hash),
nonce: U256::from(self.nonce.unwrap_or(0) as u64),
Expand All @@ -553,6 +560,7 @@ impl StorageApiTransaction {
gas_price: Some(bigdecimal_to_u256(gas_price)),
gas: bigdecimal_to_u256(self.gas_limit.unwrap_or_else(BigDecimal::zero)),
input: serde_json::from_value(self.calldata).expect("incorrect calldata in Postgres"),
y_parity,
v: signature.as_ref().map(|s| U64::from(s.v())),
r: signature.as_ref().map(|s| U256::from(s.r())),
s: signature.as_ref().map(|s| U256::from(s.s())),
Expand Down
3 changes: 3 additions & 0 deletions core/lib/types/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ pub struct Transaction {
pub gas: U256,
/// Input data
pub input: Bytes,
/// The parity (0 for even, 1 for odd) of the y-value of the secp256k1 signature
#[serde(rename = "yParity", default, skip_serializing_if = "Option::is_none")]
pub y_parity: Option<U64>,
/// ECDSA recovery id
#[serde(default, skip_serializing_if = "Option::is_none")]
pub v: Option<U64>,
Expand Down
8 changes: 8 additions & 0 deletions core/lib/types/src/l2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,13 @@ impl From<L2Tx> for api::Transaction {
} else {
(None, None, None)
};
// Legacy transactions are not supposed to have `yParity` and are reliant on `v` instead.
// Other transactions are required to have `yParity` which replaces the deprecated `v` value
// (still included for backwards compatibility).
let y_parity = match tx.common_data.transaction_type {
TransactionType::LegacyTransaction => None,
_ => v,
};

Self {
hash: tx.hash(),
Expand All @@ -409,6 +416,7 @@ impl From<L2Tx> for api::Transaction {
max_fee_per_gas: Some(tx.common_data.fee.max_fee_per_gas),
gas: tx.common_data.fee.gas_limit,
input: Bytes(tx.execute.calldata),
y_parity,
v,
r,
s,
Expand Down
Loading