-
Notifications
You must be signed in to change notification settings - Fork 0
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
Integrate kairos-tx
with smart contract events
#73
Comments
The first idea was to integrate Integrating CES with diff --git a/kairos-tx/Cargo.toml b/kairos-tx/Cargo.toml
index a2838c7..dac3a89 100644
--- a/kairos-tx/Cargo.toml
+++ b/kairos-tx/Cargo.toml
@@ -9,7 +9,9 @@ license.workspace = true
[dependencies]
num-traits = "0.2"
rasn = { version = "0.12", default-features = false, features = ["macros"] }
+casper-event-standard = { version = "0.5.0", optional = true }
[features]
default = ["std"]
std = []
+ces = ["casper-event-standard"]
diff --git a/kairos-tx/src/asn.rs b/kairos-tx/src/asn.rs
index 383c720..8a67ca8 100644
--- a/kairos-tx/src/asn.rs
+++ b/kairos-tx/src/asn.rs
@@ -6,6 +6,7 @@ use crate::error::TxError;
// Expose types for the public API.
pub use rasn::types::{Integer, OctetString};
+use casper_event_standard::Event;
use num_traits::cast::ToPrimitive;
use rasn::types::AsnType;
use rasn::{Decode, Encode};
@@ -59,6 +60,7 @@ impl TryFrom<Nonce> for u64 {
}
#[derive(AsnType, Encode, Decode, Debug)]
+#[cfg_attr(feature = "ces", derive(Event))]
#[non_exhaustive]
pub struct SigningPayload {
pub nonce: Nonce, So far so good, but we have to derive
Macro is expecting named fields, so derive doesn't work for enum too:
To solve this we could implement 4 traits for each type incompatible with macro:
At this point I am sure we should go with better and easier idea: include transaction details in the smart contract event as the bytes. I am going to submit PR for that, cc @jonas089. |
@koxu1996 So we just serialize the event metadata to Bytes before we emit it? I always preferred that so I agree :). |
But then we aren't really using ASN, one would have to construct the ASN format from standardized metadata, correct? |
@jonas089 serialized transaction data - which is constructed from ASN.1 - would be included as bytes in Deposit event, for example: #[derive(Event)]
pub struct Deposit {
// ...
pub tx: Vec<u8>,
} Those |
I see, so it is a nested struct for serialized ASN data. So we have 2 options:
and you prefer 1.? |
Because the contract needs to read and validate the transaction data as you mentioned before, so does it deserialize the ASN struct? |
@jonas089 Smart contract must deserialize transaction data to confirm that given details are correct, e.g. L1 transferred amount is equal to amount specified inside |
I'm just wondering how expensive deserialization is / if it is more expensive than serialization |
Maybe a host function for deserialization could make sense in the future, but for now we can just do it in the contract and adjust the chainspec if necessary. |
I don't think this will be ever a bottleneck. Btw., I just tested |
While using Compilation error:
Update: This is not issue with |
Using Compilation error:
Fortunately fixing this is simple - I will hide filesystem functions in Update: fix submitted #78. |
Not a big fan of serializing/deserializing. I think the implementation the traits for |
@marijanp There is no serialization involved. Deserialization will be used for L2 transaction validation - you can see prototype here.
In the first comment I explained why we do NOT want to derive Event for transaction structs, and lack of support for enum was just one of the examples. The final conclusion was:
So deposit event will look like this:
Where |
What I mean is why do you even consider to add the Maybe it's better to duplicate the nonce field in each I'm suggesting rethinking the whole type hierarchy that we have, and then making our lives easier by just being able to derive |
As discussed during the latest Smart Contract deep dive, we should include details of L2 transaction in deposit event:
SigningPayload
fromkairos-tx
,Furthermore, smart contract must check that given transaction details are correct, i.e.:
That would allow to us to fully trust deposit events, without additional interactions with L1.
The text was updated successfully, but these errors were encountered: