[−][src]Trait plasma_cash_tokens::PlasmaCashTxn
Plasma Cash Transaction trait for a given Token.
All the methods a Plasma Cash Transaction must implement to allow transaction and history verification logic to work. This allows custom transactions to be defined that allow significant customization of the semantics of transactions while conforming to the Plasma Cash specification, which creates safety in the Layer 1 ⇋ Layer 2 bridge.
Note
The design of this trait was such that it could be flexible enough to support both transparent and encrypted transactions. When used with encrypted transactions, there may be a logical difference in handling transactions verification between publicly accessible information and privledged parties to the transaction, so that should be taken into account when using this API.
Example
Users of this API should should define this e.g.
struct Transaction { ... } impl PlasmaCashTxn for Transaction { ... }
Associated Types
Loading content...Required methods
ⓘImportant traits for BitVec<C, T>fn token_id(&self) -> BitVec
Needed to obtain the key for a Merkle Proof.
fn valid(&self) -> bool
Transaction is well-formed (implementation-specific).
Note
This might be used for certain use-cases to verify zk proofs, whereas other use cases might have only signature validation.
fn leaf_hash(&self) -> Self::HashType
Return "Leaf Hash" of this transaction.
Note
The "Leaf Hash" may be the encoded transaction structure directly, or it may be a publicly accessible committment, as required for certain applications such as Zero Knowledge Proofs.
Implementation is left up to the end user, but this must return a consistent hash for use in the Sparse Merkle Tree data structure that Plasma Cash is standardized around for it's key: value txn datastore.
It does not have to match the hash function used for SMT proofs, but it must
be consistent and of the same size as the hashes returned by hash_fn()
for
the smt proof validation to work.
fn empty_leaf_hash() -> Self::HashType
Returns an empty leaf hash.
Used for proofs of exclusion in txn trie.
fn hash_fn() -> fn(_: &[u8]) -> Self::HashType
Function used to verify proofs.
fn compare(&self, other: &Self) -> TxnCmp
Returns the relationship of another transaction (other) to this one (self).
See TxnCmp enum definition for more information.
Provided methods
fn get_root(
&self,
proof: Vec<Self::HashType>
) -> Result<Self::HashType, &'static str>
&self,
proof: Vec<Self::HashType>
) -> Result<Self::HashType, &'static str>
Obtain the root hash following the SMT algorithm.
Note
Proof must be in un-compressed form (proof.len() == smt.depth()
)