Skip to content

Commit

Permalink
Merge pull request #1319 from eqlabs/fix-1316
Browse files Browse the repository at this point in the history
fix: RPC v0.4 is missing tx changes from v0.3
  • Loading branch information
kkovaacs authored Aug 16, 2023
2 parents ea5ec23 + e158111 commit 44f83f6
Show file tree
Hide file tree
Showing 18 changed files with 1,274 additions and 28 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- RPC v0.4 `starknet_getTransactionByHash` uses the wrong error code for `TXN_HASH_NOT_FOUND`
- Querying `starknet_getClassAt` and `starknet_getClassHashAt` by block hash incorrectly returns contract not found
- On Starknet 0.12.2 pathfinder now provides consistent pending data.
- On Starknet 0.12.2 pathfinder now provides consistent pending data
- RPC v0.4 Declare v0 and Invoke v0 contain the nonce field

## [0.7.1] - 2023-08-08

Expand Down
21 changes: 20 additions & 1 deletion crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ pub mod event;
pub mod hash;
mod header;
mod macros;
pub mod prelude;
pub mod state_update;
pub mod test_utils;
pub mod transaction;
pub mod trie;

pub use state_update::StateUpdate;
Expand Down Expand Up @@ -52,6 +54,10 @@ impl EntryPoint {
input,
))))
}

/// The constructor [EntryPoint], defined as the truncated keccak of b"constructor".
pub const CONSTRUCTOR: Self =
entry_point!("0x028FFE4FF0F226A9107253E17A904099AA4F63A02A5621DE0576E5AA71BC5194");
}

impl StateCommitment {
Expand Down Expand Up @@ -121,7 +127,7 @@ macros::i64_backed_u64::serdes!(TransactionIndex);
pub struct GasPrice(pub u128);

/// Starknet transaction version.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize, Default)]
pub struct TransactionVersion(pub H256);

impl TransactionVersion {
Expand Down Expand Up @@ -453,6 +459,19 @@ pub fn calculate_class_commitment_leaf_hash(

#[cfg(test)]
mod tests {
#[test]
fn constructor_entry_point() {
use crate::truncated_keccak;
use crate::EntryPoint;
use sha3::{Digest, Keccak256};

let mut keccak = Keccak256::default();
keccak.update(b"constructor");
let expected = EntryPoint(truncated_keccak(<[u8; 32]>::from(keccak.finalize())));

assert_eq!(EntryPoint::CONSTRUCTOR, expected);
}

mod starknet_version {
use super::super::StarknetVersion;

Expand Down
44 changes: 44 additions & 0 deletions crates/common/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
pub use crate::BlockHash;
pub use crate::BlockHeader;
pub use crate::BlockNumber;
pub use crate::BlockTimestamp;
pub use crate::ByteCodeOffset;
pub use crate::CallParam;
pub use crate::CallResultValue;
pub use crate::CasmHash;
pub use crate::ChainId;
pub use crate::ClassCommitment;
pub use crate::ClassCommitmentLeafHash;
pub use crate::ClassHash;
pub use crate::ConstructorParam;
pub use crate::ContractAddress;
pub use crate::ContractAddressSalt;
pub use crate::ContractClass;
pub use crate::ContractNonce;
pub use crate::ContractRoot;
pub use crate::ContractStateHash;
pub use crate::EntryPoint;
pub use crate::EthereumAddress;
pub use crate::EventCommitment;
pub use crate::EventData;
pub use crate::EventKey;
pub use crate::Fee;
pub use crate::FromSliceError;
pub use crate::GasPrice;
pub use crate::L1ToL2MessageNonce;
pub use crate::L1ToL2MessagePayloadElem;
pub use crate::L2ToL1MessagePayloadElem;
pub use crate::SequencerAddress;
pub use crate::SierraHash;
pub use crate::StarknetVersion;
pub use crate::StateCommitment;
pub use crate::StateUpdate;
pub use crate::StorageAddress;
pub use crate::StorageCommitment;
pub use crate::StorageValue;
pub use crate::TransactionCommitment;
pub use crate::TransactionHash;
pub use crate::TransactionIndex;
pub use crate::TransactionNonce;
pub use crate::TransactionSignatureElem;
pub use crate::TransactionVersion;
125 changes: 125 additions & 0 deletions crates/common/src/transaction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
use crate::prelude::*;

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Transaction {
pub hash: TransactionHash,
pub variant: TransactionVariant,
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum TransactionVariant {
DeclareV0(DeclareTransactionV0V1),
DeclareV1(DeclareTransactionV0V1),
DeclareV2(DeclareTransactionV2),
// Regenesis: deploy is a legacy variant and can be removed after regenesis.
Deploy(DeployTransaction),
DeployAccount(DeployAccountTransaction),
InvokeV0(InvokeTransactionV0),
InvokeV1(InvokeTransactionV1),
L1Handler(L1HandlerTransaction),
}

impl From<DeclareTransactionV2> for TransactionVariant {
fn from(value: DeclareTransactionV2) -> Self {
Self::DeclareV2(value)
}
}
impl From<DeployTransaction> for TransactionVariant {
fn from(value: DeployTransaction) -> Self {
Self::Deploy(value)
}
}
impl From<DeployAccountTransaction> for TransactionVariant {
fn from(value: DeployAccountTransaction) -> Self {
Self::DeployAccount(value)
}
}
impl From<InvokeTransactionV0> for TransactionVariant {
fn from(value: InvokeTransactionV0) -> Self {
Self::InvokeV0(value)
}
}
impl From<InvokeTransactionV1> for TransactionVariant {
fn from(value: InvokeTransactionV1) -> Self {
Self::InvokeV1(value)
}
}
impl From<L1HandlerTransaction> for TransactionVariant {
fn from(value: L1HandlerTransaction) -> Self {
Self::L1Handler(value)
}
}

#[derive(Clone, Default, Debug, PartialEq, Eq)]
pub struct DeclareTransactionV0V1 {
pub class_hash: ClassHash,
pub max_fee: Fee,
pub nonce: TransactionNonce,
pub sender_address: ContractAddress,
pub signature: Vec<TransactionSignatureElem>,
}

#[derive(Clone, Default, Debug, PartialEq, Eq)]
pub struct DeclareTransactionV2 {
pub class_hash: ClassHash,
pub max_fee: Fee,
pub nonce: TransactionNonce,
pub sender_address: ContractAddress,
pub signature: Vec<TransactionSignatureElem>,
pub compiled_class_hash: CasmHash,
}

#[derive(Clone, Default, Debug, PartialEq, Eq)]
pub struct DeployTransaction {
pub contract_address: ContractAddress,
pub contract_address_salt: ContractAddressSalt,
pub class_hash: ClassHash,
pub constructor_calldata: Vec<ConstructorParam>,
pub version: TransactionVersion,
}

#[derive(Clone, Default, Debug, PartialEq, Eq)]
pub struct DeployAccountTransaction {
pub contract_address: ContractAddress,
pub max_fee: Fee,
pub version: TransactionVersion,
pub signature: Vec<TransactionSignatureElem>,
pub nonce: TransactionNonce,
pub contract_address_salt: ContractAddressSalt,
pub constructor_calldata: Vec<CallParam>,
pub class_hash: ClassHash,
}

#[derive(Clone, Default, Debug, PartialEq, Eq)]
pub struct InvokeTransactionV0 {
pub calldata: Vec<CallParam>,
pub sender_address: ContractAddress,
pub entry_point_selector: EntryPoint,
pub entry_point_type: Option<EntryPointType>,
pub max_fee: Fee,
pub signature: Vec<TransactionSignatureElem>,
}

#[derive(Clone, Default, Debug, PartialEq, Eq)]
pub struct InvokeTransactionV1 {
pub calldata: Vec<CallParam>,
pub sender_address: ContractAddress,
pub max_fee: Fee,
pub signature: Vec<TransactionSignatureElem>,
pub nonce: TransactionNonce,
}

#[derive(Clone, Default, Debug, PartialEq, Eq)]
pub struct L1HandlerTransaction {
pub contract_address: ContractAddress,
pub entry_point_selector: EntryPoint,
pub nonce: TransactionNonce,
pub calldata: Vec<CallParam>,
pub version: TransactionVersion,
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum EntryPointType {
External,
L1Handler,
}
Loading

0 comments on commit 44f83f6

Please sign in to comment.