Skip to content

Commit

Permalink
feat(api-server): add yParity for non-legacy txs (matter-labs#3246)
Browse files Browse the repository at this point in the history
## What ❔

Closes matter-labs#3245

## Why ❔

See matter-labs#3245 for more details. TLDR better compatibility with ETH spec.

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] Code has been formatted via `zkstack dev fmt` and `zkstack dev
lint`.
  • Loading branch information
itegulov authored Nov 11, 2024
1 parent fd913fe commit 6ea36d1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
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

0 comments on commit 6ea36d1

Please sign in to comment.