-
Notifications
You must be signed in to change notification settings - Fork 109
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
Runtime field count #352
Runtime field count #352
Conversation
IMO this is a 'nice to have'. It should get reviewed by all me, @ppopth and @GottfriedHerold . I can do a first review next week. |
I'm not quite convinced that the c-kzg = { git = "https://github.com/ethereum/c-kzg-4844", rev = "fa3c62989527073fdce8b2138bb27a52bb2407c5" , features = ["mainnet-spec"]}
c_kzg_min = { package = "c-kzg", git = "https://github.com/ethereum//c-kzg-4844", rev = "fa3c62989527073fdce8b2138bb27a52bb2407c5", features = ["minimal-spec"], optional = true } I think, this one is unnecessary because you can just use one crate for both mainnet and minimal, instead of using two. You can probably put the mainnet in one module and the minimal in another module. Can you give a reason why you think we should eliminate the For the stack overflow problem in Rust, I think we don't have to remove the Blob definition. It's better to keep it as is. If some bindings have the problem with it, they can just ignore it and redefine that type. For example, the Rust binding can redefine the Blob type as some kind of Please correct me if I'm wrong. |
Simplicity.
While this PR will result in less stack usage, the stack overflow problem with the rust bindings has been fixed: Regarding the blob definition, I really wish we could keep this type but I don't think there's a strong reason it needs to exist. For example, nowhere in the C library (excluding the C tests) do we instantiate a blob. Only pointers are used. We could create a blob type like:
Sure, I suppose that's possible but it sounds a bit more complicated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me.
In terms of API I would rename KZGSettings as a context using ctx
for it and make it the first parameter as it's pretty standard in cryptographic libraries but that's another PR or RFC.
I've been wanting to rename |
This would be very useful for us in testing, a lot of our end to end tests rely on running minimal configs, so the ability to toggle the blob sizes would be very helpful for us and make maintaining the test infrastructure for blobs much easier. |
Changing the base branch to a new
This allows us to see the "final product" without breaking |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a meta-comment but since this PR will get reviewed by a bunch of people, I think it would be a good idea to make it more pleasant to review.
In particular, ef592fc is the core of the feature but it actually does three things at once:
- refactors FIELD_ELEMENTS_PER_BLOB
- refactors
Polynomial
- refactors
Blob
It would be great if the branch could be rebased such that these three operations are performed in separate commits. IMO it would make this PR easier to review.
a0043b1
to
2df642d
Compare
The rebase (splitting changes into smaller commits) is still a work in progress. Will finish tomorrow morning. |
Done an initial review and this looks really good! Thanks! I pushed three commits. @jtraglia wanna review them and then squash them and rebase the PR so that it's clean again? It would be great if @GottfriedHerold and @ppopth can also give it a review as well. |
Your changes look great, thanks for that 🥇 |
3e0aa50
to
c8b7d59
Compare
Rebased and force-pushed as per our TG conversation. I also pushed the pre-rebased branch at https://github.com/asn-d6/c-kzg-4844/tree/pr352_pre_rebase (the one with the three extra commits) in case you want to diff it with the force-pushed code to make sure I didn't screw up the rebase. |
This may be a dump question, but why don't we put the size of polynomials and blobs into a field of a struct? typedef struct {
fr_t *evals;
uint64_t size;
} Polynomial; and typedef struct {
uint8_t *bytes;
uint64_t size;
} Blob; I understand that all the polynomials and the blobs have the same size, but, by doing this, all the polynomials and the blobs will be self-contained and don't depend on external objects like KZGSettings. Previously we didn't keep the size and we used This may need more assertions that the size of polynomials and blobs are equal to the global setting, but this may be worth it. |
So we did try this with polynomials (see this commit), but decided against it for a few reasons. I prefer the way it is now, but I'm open to using
|
Yep agreed. I was part of this entire refactoring-then-rerefactoring operation, and I agree that the status quo (without |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, the changes look good to me.
* Two remarks about n1/n2 requirements. * Move n1/n2 checks to inner function so they behave the same. * A remark about the file's position before/after.
Thanks @GottfriedHerold. How do these (2328ac5) changes look? I also moved the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks!
I looked at pawanjay176/lighthouse@a2c780a already. It seems to me that the commit makes things simpler because it changes from pub struct Kzg<P: KzgPreset> {
trusted_setup: P::KzgSettings,
} to pub struct Kzg {
trusted_setup: KzgSettings,
} I think the latter can be done without this PR. As I mentioned in #352 (comment), both mainnet and minimal presets can be combined into one crate which makes the latter possible.
In the binding, you can do something like enum KzgSettings {
Mainnet(...),
Minimal(...),
} Now in the lighthouse, you can do the latter.
I think this is not an issue. The idea of duplicating codes is very common. We do it all the time when we use generics (like in Rust and C++). |
With this PR, one build of c-kzg-4844 will work with both mainnet and minimal trusted setups. If merged, I will update the bindings in separate PRs. Until then, the CI tests for the bindings are expected to fail.
FIELD_ELEMENTS_PER_BLOB
macro (which was either 4096 or 4).kzg_settings->field_elements_per_blob
after loading the trusted setup.Blob
andPolynomial
.typedef uint8_t Blob
because that could be confusing.LIB_PREFIX
hack for supporting both builds.For the tests:
MAINNET
andMINIMAL
macros to determine which to test.