-
Notifications
You must be signed in to change notification settings - Fork 310
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
feat: tightly pack public logs inside blobs #11752
base: master
Are you sure you want to change the base?
Conversation
...col-circuits/crates/private-kernel-lib/src/components/tail_output_composer/meter_gas_used.nr
Outdated
Show resolved
Hide resolved
Changes to circuit sizes
🧾 Summary (100% most significant diffs)
Full diff report 👇
|
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.
As discussed, private logs are always padded to the fixed length, so there won't be trailing 0s.
// As above, but counts from the end of the array. | ||
// Useful for finding trailing zeroes in arrays which may have valid empty values. | ||
// e.g. removing trailing 0s from [1, 0, 2, 0, 0, 0] -> [1, 0, 2] | ||
// TODO: can be removed if logs cannot contain valid 0s. |
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.
Can remove this TODO (and the one below) as logs will always contain valid 0s!
T: Empty + Eq, | ||
{ | ||
/// Safety: this value is constrained in the below loop | ||
let length = unsafe { find_index_hint_from_end(array, |elem: T| is_empty(elem)) }; |
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 should be find_index_hint_from_end(array, |elem: T| !is_empty(elem))
Think it's more intuitive, and matches other libraries' similar functions, to find the index of the element that makes the callback return true.
let lastZeroIndex = 0; | ||
for (let i = this.toFields().length - 1; i >= 0; i--) { | ||
if (!this.toFields()[i].isZero() && lastZeroIndex == 0) { | ||
lastZeroIndex = i + 1; | ||
break; | ||
} | ||
} |
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.
let lastZeroIndex = 0; | |
for (let i = this.toFields().length - 1; i >= 0; i--) { | |
if (!this.toFields()[i].isZero() && lastZeroIndex == 0) { | |
lastZeroIndex = i + 1; | |
break; | |
} | |
} | |
const fields = this.toFields(); | |
const lastNonZeroIndex = fields.findLast(f => !f.isZero()); | |
return fields.slice(0, lastNonZeroIndex + 1); |
This PR removes trailing zeroes from logs appended to the blobs to save on field space.
e.g. before this PR, a public log would be appended like:
but now is appended as:
with a length prefix.
In ts, we add back the trailing zeroes when constructing tx effects from the blob, so if they are required there should be no issue.
Also, in some logs there are valid zeroes inside the log. The method does not remove these. e.g. a public log like:
is appended as:
then reconstructed to the original log once in ts.