Skip to content

Move transaction builder and transparent types to anoma#1

Open
Scar26 wants to merge 8 commits intomurisi:murisi/masp-incentivefrom
Scar26:scar/masp-incentives
Open

Move transaction builder and transparent types to anoma#1
Scar26 wants to merge 8 commits intomurisi:murisi/masp-incentivefrom
Scar26:scar/masp-incentives

Conversation

@Scar26
Copy link
Copy Markdown

@Scar26 Scar26 commented Jul 4, 2022

No description provided.

@Scar26 Scar26 force-pushed the scar/masp-incentives branch from f620cac to e15cb2c Compare July 6, 2022 11:44
Copy link
Copy Markdown
Owner

@murisi murisi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR! I think your movement of some Transaction construction code makes sense. I wonder whether we should do more of this...

Comment thread masp_primitives/src/convert.rs Outdated
pub struct AllowedConversion {
/// The asset type that the note represents
assets: Amount,
pub assets: Amount,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't making the assets field public would allow users of this interface to break its invariants? Specifically, I'm scared that people could modify assets whilst leaving generator unchanged which would mean that assets would cease to correspond to generator. I guess you probably want just a getter function...

Clone, Debug, PartialEq, BorshSerialize, BorshDeserialize, Serialize, Deserialize, Eq, Hash
)]
pub struct Amount(BTreeMap<AssetType, i64>);
pub struct Amount(pub(crate) BTreeMap<AssetType, i64>);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the invariants of Amount is that its BTreeMap never contains an entry whose value equals 0. Forcing this canonicity simplifies the implementation of Eq and asset_types() for Amount. I'm scared that increasing the visibility of Amount's BTreeMap might allow users in the crate to put Amount into an invalid state. Maybe we could instead add a constructor accepting a BTreeMap?

Comment thread masp_primitives/src/transaction/mod.rs Outdated
/// A Zcash transaction.
#[derive(Debug, Serialize, Deserialize, Clone, Hash, Eq, PartialOrd)]
pub struct Transaction {
pub struct Transaction<Ti: TxIn, To: TxOut> {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see how a generically parameterized Transaction might be of greater use to other parties, but on the hand in Anoma we only instantiate this struct in one way (right?) and I would guess that transaction formats/encodings are likely to be unique to each blockchain project.

I liked how you moved builder.rs to the anoma/anoma repo, I wonder if we could just move the entire transaction folder (apart from Amount) there if possible? I think that doing this might increase this branch's likelihood of approval from the maintainers (given that this crate's main purpose is to provide cryptographic circuits)...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True for our use in anoma, we don't really need generic arguments for transparent inputs and outputs. To that effect I can also see moving Transaction to anoma as it's also tied to how we structure transactions in anoma. But I think it would still make sense to keep spend, output and convert descriptions in masp as they are part of the spec and necessary for any third party integration. Thoughts?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your idea of keeping spend, output, and convert in the MASP crate is another valid approach that also makes sense. I'd say, do whatever yields the simplest code.

AssetType::new(b"XAN").unwrap()
}
#[test]
fn test_homomorphism() {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do we now test that Amounts operations (for example AddAsign) do indeed preserve the homomorphism (i.e. that the commitment of assets always equals generator)? I guess we just need to make sure that this memorization optimization preserves the correctness of the original implementation...

);
}
#[test]
fn test_serialization() {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably also check that the serialization and deserialization functions are indeed inverses of each other somewhere...

Comment thread masp_primitives/src/asset_type.rs Outdated
/// Attempt to construct an asset type from an existing asset identifier
pub fn from_identifier(identifier: &[u8; ASSET_IDENTIFIER_LENGTH]) -> Option<AssetType> {
// Attempt to hash to point
println!("{:?}", identifier);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about printing to STDOUT here... This might cause issues (i.e. messing up UI or formatting) when this function is used in the anoma crate.

}

impl AllowedConversion {
pub fn new(values: Vec<(AssetType, i64)>) -> Self {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if this vector contains the same AssetType twice? In the case that the behavior makes conceptual sense, maybe we should document it? If the behavior doesn't make sense, maybe we should use an alternative type for values that does not allow duplicate keys (AssetTypes). Do whatever is simplest...

Scar26 added 8 commits July 21, 2022 20:44
Signed-off-by: Scar26 <mmatty26@gmail.com>
Signed-off-by: Scar26 <mmatty26@gmail.com>
Signed-off-by: Scar26 <mmatty26@gmail.com>
Signed-off-by: Scar26 <mmatty26@gmail.com>
Signed-off-by: Scar26 <mmatty26@gmail.com>
Add getter for AllowedConversion.assets
Add constructor for Amount
Signed-off-by: Scar26 <mmatty26@gmail.com>
Signed-off-by: Scar26 <mmatty26@gmail.com>
@Scar26 Scar26 force-pushed the scar/masp-incentives branch from 9ff2ae2 to 04e85e0 Compare July 21, 2022 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants