Skip to content
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

Bandersnatch tweaks after backend update #1482

Merged
merged 4 commits into from
Sep 13, 2023

Conversation

davxy
Copy link
Member

@davxy davxy commented Sep 10, 2023

As per title

@davxy davxy requested a review from a team September 10, 2023 07:48
@davxy davxy self-assigned this Sep 10, 2023
@davxy davxy added the T0-node This PR/Issue is related to the topic “node”. label Sep 10, 2023
return false
};
let preouts: [bandersnatch_vrfs::VrfPreOut; N] =
core::array::from_fn(|i| self.outputs[i].0.clone());
Copy link
Contributor

Choose a reason for hiding this comment

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

How big is the thing being cloned here? I tried to follow the types and manually see how big it is, but there are so many layers of abstraction between what's used here and the types which actually store the raw bytes (and some broken docs.rs builds in between :P) that I just gave up. (As far as I can see this has some inline big ints inside, so I'd like to know how big exactly.) Can you core::mem::size_of in a throwaway #[test] and paste me the result?

Copy link
Member Author

@davxy davxy Sep 10, 2023

Choose a reason for hiding this comment

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

Each element is a Bandersnatch curve group element (aka curve point).

struct Affine {
    x: U256,            // 32 bytes
    y: U256,            // 32 bytes
    infinity: bool,
}

The in memory size for a 64 bit machine is 72 bytes (8 bytes are given to the infinity bool for alignment).


The constructed array size is bounded by the max number we support at the moment (MAX_VRF_IOS = 3).

Copy link
Member Author

@davxy davxy Sep 10, 2023

Choose a reason for hiding this comment

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

@burdges can we implement Copy for VrfInput and VrfPreOut (as the inner types are Copy)?

Copy link

Choose a reason for hiding this comment

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

Alright sure. Arkworks & dalek both have copy types of this size.

In memory, yeah affine curve points are two base field elements plus a flag. This one has a 32 byte base field, and serializes in 33 bytes.

Yes, arkworks has layers itself. And I made it worse for other reasons.

@davxy davxy requested a review from a team September 10, 2023 14:38
.expect("ring-proof serialization can't fail");
.proof
.serialize_compressed(signature.signature.as_mut_slice())
.expect("ring-signature serialization can't fail");
Copy link
Member

Choose a reason for hiding this comment

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

There is the old rule of "proof or remove" ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

bccbf5a

I added some more assertions in the "backend sanity checks" test.
This test basically checks our assumptions about the serialized lengths of some objects.

These serialized lengths are constant and any variation of the sizes is early catched by the test


thin_signature
.proof
.serialize_compressed(signature.signature.0.as_mut_slice())
.expect("serialization can't fail");
Copy link
Member

Choose a reason for hiding this comment

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

Same

Copy link

Choose a reason for hiding this comment

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

ArkScale requires you "audit" arkworks types for this, but doing so is simply a grep command:
https://github.com/w3f/ark-scale/blob/master/src/lib.rs#L126
https://github.com/w3f/ark-scale/blob/master/README.md

Also VrfSignature became a scale type:
https://github.com/w3f/ring-vrf/blob/master/dleq_vrf/src/traits.rs#L97

Copy link

@burdges burdges Sep 12, 2023

Choose a reason for hiding this comment

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

Oh you mean the length, yeah a test for this makes sense.

@davxy davxy requested a review from bkchr September 12, 2023 09:41
@davxy davxy merged commit 61be78c into paritytech:master Sep 13, 2023
8 checks passed
@davxy davxy deleted the bump-bandersnatch-vrfs-version branch September 15, 2023 12:14
bgallois pushed a commit to duniter/duniter-polkadot-sdk that referenced this pull request Mar 25, 2024
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 8, 2024
* sync Westmint to Millau

* "Westend parachains at Millau" dashboard
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 8, 2024
* sync Westmint to Millau

* "Westend parachains at Millau" dashboard
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 8, 2024
* sync Westmint to Millau

* "Westend parachains at Millau" dashboard
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 8, 2024
* sync Westmint to Millau

* "Westend parachains at Millau" dashboard
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
* sync Westmint to Millau

* "Westend parachains at Millau" dashboard
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
* sync Westmint to Millau

* "Westend parachains at Millau" dashboard
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
* sync Westmint to Millau

* "Westend parachains at Millau" dashboard
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
* sync Westmint to Millau

* "Westend parachains at Millau" dashboard
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
* sync Westmint to Millau

* "Westend parachains at Millau" dashboard
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
* sync Westmint to Millau

* "Westend parachains at Millau" dashboard
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 10, 2024
* sync Westmint to Millau

* "Westend parachains at Millau" dashboard
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 10, 2024
* sync Westmint to Millau

* "Westend parachains at Millau" dashboard
bkchr pushed a commit that referenced this pull request Apr 10, 2024
* sync Westmint to Millau

* "Westend parachains at Millau" dashboard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T0-node This PR/Issue is related to the topic “node”.
Projects
Status: done
Development

Successfully merging this pull request may close these issues.

4 participants