Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
181 commits
Select commit Hold shift + click to select a range
97e2a01
feat: blob batching methods - nr only
MirandaWood Apr 15, 2025
52801e6
chore: fmt, more tests, rearranging
MirandaWood Apr 16, 2025
35e8be2
feat: BLS12 field, curve methods, blob batching methods, ts only
MirandaWood Apr 16, 2025
db03339
chore: lint, cleanup
MirandaWood Apr 16, 2025
68be71e
chore: remove trusted setup file + test using it (size issues)
MirandaWood Apr 16, 2025
1fa5d49
Revert "chore: remove trusted setup file + test using it (size issues)"
MirandaWood Apr 17, 2025
33d62a7
chore: cleanup packages + increase playground size
MirandaWood Apr 17, 2025
46b8866
feat: address some comments, cleanup
MirandaWood Apr 17, 2025
346ca9a
chore: update some comments
MirandaWood Apr 21, 2025
f655bf5
Merge remote-tracking branch 'origin/mw/blob-batching' into mw/blob-b…
MirandaWood Apr 21, 2025
8d57216
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils' into…
MirandaWood Apr 21, 2025
9490422
chore: renaming, cleanup
MirandaWood Apr 22, 2025
c300c77
chore: renaming, cleanup
MirandaWood Apr 22, 2025
63ffe96
chore: add issue nums (hopefully force ci cache reset)
MirandaWood Apr 22, 2025
606a942
feat: as isNegative to F, rename proof -> Q
MirandaWood Apr 22, 2025
75d6d35
Merge remote-tracking branch 'origin/mw/blob-batching' into mw/blob-b…
MirandaWood Apr 22, 2025
40ffd8b
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils' into…
MirandaWood Apr 22, 2025
951d329
chore: bumped vite kb limit 1700 -> 1720
MirandaWood Apr 22, 2025
307cb09
chore: bumped vite kb limit 1700 -> 1750
MirandaWood Apr 22, 2025
5251cd1
feat: adding helpers, constants, docs, etc. for integration
MirandaWood Apr 24, 2025
de8ec1e
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils' into…
MirandaWood Apr 24, 2025
5f2fe64
feat: WIP batch blobs and validate in rollup
MirandaWood Apr 24, 2025
070cbd2
feat: add more tests, cleanup, remove some warnings
MirandaWood Apr 25, 2025
f9e5364
chore: update to fixed noir version
TomAFrench Apr 29, 2025
201711e
feat: add final accumulator pub inputs for root
MirandaWood May 1, 2025
f0a66a5
chore: temp downgrade bignum until bigcurve works on 0.7+
MirandaWood May 7, 2025
ca0da9d
Merge remote-tracking branch 'origin/mw/blob-batching' into mw/blob-b…
MirandaWood May 7, 2025
d5f11d4
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils' into…
MirandaWood May 7, 2025
34e9e1a
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils-ts' i…
MirandaWood May 7, 2025
d3ac058
chore: rename v -> blob_commitments_hash, move noir ref further up stack
MirandaWood May 13, 2025
6750476
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils' into…
MirandaWood May 13, 2025
8e968ac
chore: rename v to blobCommitmentsHash
MirandaWood May 13, 2025
7cd9b97
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils-ts' i…
MirandaWood May 13, 2025
8a2570f
chore: renaming, reduce root pub inputs, cleanup
MirandaWood May 13, 2025
95ee6bf
chore: add back testing fixtures (too much effort to remove rn)
MirandaWood May 14, 2025
6051d14
chore: add back more testing fixtures
MirandaWood May 14, 2025
b1771c8
feat: WIP integrate batched blobs into l1 contracts + ts
MirandaWood May 15, 2025
f3a244e
Merge remote-tracking branch 'origin/master' into mw/blob-batching
MirandaWood May 15, 2025
dc3a027
chore: revert to bignum master version
MirandaWood May 15, 2025
1fc2c0d
Merge remote-tracking branch 'origin/mw/blob-batching' into mw/blob-b…
MirandaWood May 15, 2025
cda163a
chore: use updated methods from bignum, remove warnings
MirandaWood May 15, 2025
4806435
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils' into…
MirandaWood May 15, 2025
508a11f
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils-ts' i…
MirandaWood May 15, 2025
f92a3d5
chore: update methods to bignum 0.7, cleanup
MirandaWood May 15, 2025
0e45923
Merge remote-tracking branch 'origin/mw/blob-batching-integration' in…
MirandaWood May 15, 2025
cfb8a32
chore: fmt, move to bigcurve mw/bump to avoid private module warnings
MirandaWood May 15, 2025
7986bc4
feat: use branch for visibility warnings, handle blobcommitmentshash …
MirandaWood May 15, 2025
c29f9df
Merge remote-tracking branch 'origin/master' into mw/blob-batching
MirandaWood May 16, 2025
49c7be3
chore: switch bigcurve branch to remove visibility warnings
MirandaWood May 16, 2025
ee900fe
Merge remote-tracking branch 'origin/mw/blob-batching' into mw/blob-b…
MirandaWood May 16, 2025
2216519
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils' into…
MirandaWood May 16, 2025
05cffba
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils-ts' i…
MirandaWood May 16, 2025
d32742e
chore: cleanup, remove warnings
MirandaWood May 16, 2025
cdb2136
Merge remote-tracking branch 'origin/mw/blob-batching-integration' in…
MirandaWood May 16, 2025
dffe9b4
chore: remove logs oops
MirandaWood May 16, 2025
563e765
chore: oops remove more accidentally pushed console logs
MirandaWood May 16, 2025
6e830c7
chore: import fixes and hacks
MirandaWood May 16, 2025
b2f808d
fix: properly handle epoch boundary in l1 pub test
MirandaWood May 16, 2025
2578442
chore: update prover.tomls (i hate past me)
MirandaWood May 16, 2025
a01dc36
chore: cleanup + dummy changes to force n-p recompile for ci
MirandaWood May 19, 2025
c2637c3
chore: account for faster proving in epochs_empty test
MirandaWood May 20, 2025
f662ee3
chore: oops remove logs
MirandaWood May 20, 2025
43720fd
Merge remote-tracking branch 'origin/master' into mw/blob-batching
MirandaWood May 20, 2025
55bc974
Merge remote-tracking branch 'origin/mw/blob-batching' into mw/blob-b…
MirandaWood May 20, 2025
df48994
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils' into…
MirandaWood May 20, 2025
c1e149b
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils-ts' i…
MirandaWood May 20, 2025
df7665b
Merge remote-tracking branch 'origin/mw/blob-batching-integration' in…
MirandaWood May 20, 2025
594fb15
chore: update constants, fixtures, fmt
MirandaWood May 20, 2025
dc1bd18
chore: fmt
MirandaWood May 20, 2025
7a2a1e7
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils-ts' i…
MirandaWood May 20, 2025
af7c56e
Merge remote-tracking branch 'origin/mw/blob-batching-integration' in…
MirandaWood May 20, 2025
6b31327
chore: fmt
MirandaWood May 20, 2025
cb146ae
fix: include is_inf in all serialization so recursion works
MirandaWood May 20, 2025
18db30a
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils' into…
MirandaWood May 20, 2025
1e6391e
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils-ts' i…
MirandaWood May 20, 2025
dbf32e7
Merge remote-tracking branch 'origin/mw/blob-batching-integration' in…
MirandaWood May 20, 2025
98eacb4
chore: update constants
MirandaWood May 20, 2025
3398526
chore: update import
MirandaWood May 20, 2025
e0f687a
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils' into…
MirandaWood May 20, 2025
c8ec933
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils-ts' i…
MirandaWood May 20, 2025
341a96c
Merge remote-tracking branch 'origin/mw/blob-batching-integration' in…
MirandaWood May 20, 2025
5f02ae1
feat: add point compression unit test
MirandaWood May 20, 2025
480b8de
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils' into…
MirandaWood May 20, 2025
51899bd
chore: add fixture test for point compression, bring down new bls met…
MirandaWood May 21, 2025
f5bc35e
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils-ts' i…
MirandaWood May 21, 2025
3bda135
Merge remote-tracking branch 'origin/mw/blob-batching-integration' in…
MirandaWood May 21, 2025
11b0ec9
chore: cleanup, remove new node lint warnings
MirandaWood May 21, 2025
ea162d0
feat: give up on omitting is_inf field for now, cleanup
MirandaWood May 21, 2025
f6cffda
Merge remote-tracking branch 'origin/next' into mw/blob-batching
MirandaWood May 22, 2025
4c5c437
Merge remote-tracking branch 'origin/mw/blob-batching' into mw/blob-b…
MirandaWood May 22, 2025
1b7fbf0
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils' into…
MirandaWood May 22, 2025
c9b39f0
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils-ts' i…
MirandaWood May 22, 2025
9c075ed
Merge remote-tracking branch 'origin/mw/blob-batching-integration' in…
MirandaWood May 22, 2025
e44d07d
chore: update fixtures
MirandaWood May 22, 2025
f392979
chore: update (seemingly unused?) epoch proof fixture
MirandaWood May 22, 2025
0e57a5d
Merge remote-tracking branch 'origin/next' into mw/blob-batching
MirandaWood May 28, 2025
8667c5c
Merge remote-tracking branch 'origin/mw/blob-batching' into mw/blob-b…
MirandaWood May 28, 2025
ff52662
chore: bump bignum
MirandaWood May 28, 2025
0c91085
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils' into…
MirandaWood May 28, 2025
09e638a
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils-ts' i…
MirandaWood May 28, 2025
b96c499
Merge remote-tracking branch 'origin/mw/blob-batching-integration' in…
MirandaWood May 28, 2025
b2c9adb
chore: post merge fixes, bring down small changes
MirandaWood May 28, 2025
6b79af7
Merge remote-tracking branch 'origin/mw/blob-batching-integration' in…
MirandaWood May 28, 2025
76c4a68
chore: remake constants, fixtures, & merge fixes
MirandaWood May 28, 2025
2452b5c
feat: remove old constants, increase timeout
MirandaWood May 28, 2025
3064028
feat: address some comments
MirandaWood May 28, 2025
cef7c07
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils-ts' i…
MirandaWood May 28, 2025
198c2b1
Merge remote-tracking branch 'origin/mw/blob-batching-integration' in…
MirandaWood May 28, 2025
0de32bc
chore: test using toEqual in jest
MirandaWood May 29, 2025
ab5461c
Revert "chore: test using toEqual in jest"
MirandaWood May 29, 2025
b358b3e
chore: test using toEqual in jest
MirandaWood May 29, 2025
fb8e45a
feat: init bigint and buffer, remove static compress
MirandaWood May 29, 2025
be91807
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils-ts' i…
MirandaWood May 29, 2025
5f56855
feat: rename, add constant
MirandaWood May 29, 2025
ff1a70e
Merge remote-tracking branch 'origin/mw/blob-batching-integration' in…
MirandaWood May 29, 2025
5b7d7bd
feat: address comments, remove old notes, update constants
MirandaWood May 29, 2025
28b81d7
feat: check epoch duration, clear old comments + unnec. checks
MirandaWood May 30, 2025
18e3721
feat: rework orch blob accumulation
MirandaWood May 30, 2025
bb69627
chore: import blob-lib into prover-node
MirandaWood May 30, 2025
5cad7c0
chore: delete old blob structs
MirandaWood May 30, 2025
740b952
chore: revert blobcommitment mess (now exists in cleanup PR)
MirandaWood May 30, 2025
8bc413c
Merge remote-tracking branch 'origin/mw/blob-batching-integration-ts-…
MirandaWood May 30, 2025
6f2ee3a
chore: more cleanup
MirandaWood May 30, 2025
c75232b
feat: replace empty blob assumption
MirandaWood May 30, 2025
9e80ff2
feat: address some comments
MirandaWood May 30, 2025
2d1f35e
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils' into…
MirandaWood May 30, 2025
df4c693
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils-ts' i…
MirandaWood May 30, 2025
542e851
Merge remote-tracking branch 'origin/mw/blob-batching-integration' in…
MirandaWood May 30, 2025
b991ad8
feat: integrate bls12 point constant
MirandaWood May 30, 2025
ea19acd
chore: add extra check before blob acc init
MirandaWood Jun 2, 2025
e89fd4a
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils' into…
MirandaWood Jun 2, 2025
92f6e5f
chore: renaming, bring down changes from integration branch, cleanup
MirandaWood Jun 2, 2025
88b4b28
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils' into…
MirandaWood Jun 2, 2025
0ee11fd
chore: cleanup, bring down changes from other PRs
MirandaWood Jun 2, 2025
7429aac
Merge remote-tracking branch 'origin/mw/blob-batching-bls-utils-ts' i…
MirandaWood Jun 2, 2025
bbaa96f
Merge remote-tracking branch 'origin/mw/blob-batching-integration' in…
MirandaWood Jun 2, 2025
ac78bf3
chore: renaming from methods branch
MirandaWood Jun 2, 2025
0716329
Merge remote-tracking branch 'origin/mw/blob-batching-integration' in…
MirandaWood Jun 2, 2025
0d4ebdd
feat: address comments, docs, renaming
MirandaWood Jun 2, 2025
3ae3a8b
chore: update fixtures
MirandaWood Jun 2, 2025
58da20b
feat: blob batching methods (#13583)
MirandaWood Jun 3, 2025
2c45397
feat: blob batching methods (ts) (#13606)
MirandaWood Jun 3, 2025
b05c67e
Merge remote-tracking branch 'origin/next' into mw/blob-batching
MirandaWood Jun 3, 2025
4a6ee02
Merge remote-tracking branch 'origin/mw/blob-batching' into mw/blob-b…
MirandaWood Jun 3, 2025
4c0f1a9
chore: bump bignum post merge
MirandaWood Jun 3, 2025
3c81612
Merge remote-tracking branch 'origin/mw/blob-batching-integration' in…
MirandaWood Jun 3, 2025
1a16d7a
chore: revert fix to epochs test (no longer req)
MirandaWood Jun 3, 2025
a0a2f11
Merge remote-tracking branch 'origin/next' into mw/blob-batching
MirandaWood Jun 3, 2025
42230da
Merge remote-tracking branch 'origin/mw/blob-batching' into mw/blob-b…
MirandaWood Jun 3, 2025
1f912b7
Merge remote-tracking branch 'origin/mw/blob-batching-integration' in…
MirandaWood Jun 3, 2025
4f2320f
chore: bring down next fix from #14722
MirandaWood Jun 3, 2025
5783929
chore: bring down next fix again
MirandaWood Jun 3, 2025
e9726bb
feat: WIP batch blobs and validate in rollup (#13817)
MirandaWood Jun 4, 2025
4caef57
Merge remote-tracking branch 'origin/next' into mw/blob-batching
MirandaWood Jun 4, 2025
295c59d
Merge remote-tracking branch 'origin/mw/blob-batching' into mw/blob-b…
MirandaWood Jun 4, 2025
39ff55d
chore: clarify docs, add issue numbers to todos
MirandaWood Jun 4, 2025
83e7d3a
fix: bad merge
MirandaWood Jun 4, 2025
ae935f2
Merge remote-tracking branch 'origin/mw/blob-batching-integration-ts-…
MirandaWood Jun 4, 2025
3f75d58
feat: WIP integrate batched blobs into l1 contracts + ts (#14329)
MirandaWood Jun 4, 2025
b90b979
feat: improve blob hash calc, add extra blob check + test
MirandaWood Jun 4, 2025
32bf652
feat: move blobCommitmentsHash to blocklog
MirandaWood Jun 4, 2025
f72cf6d
Merge remote-tracking branch 'origin/mw/blob-batching' into mw/blob-b…
MirandaWood Jun 5, 2025
354df99
feat: rearrange blob lib, remove badly merged code
MirandaWood Jun 5, 2025
04d6c18
chore: remove circular depedency in blob-lib
MirandaWood Jun 5, 2025
682e21e
chore: rename getBlobs -> getBlobsPerBlock, remove old methods
MirandaWood Jun 6, 2025
afc7bc6
chore: remove old methods, more cleanup
MirandaWood Jun 6, 2025
1019dd2
chore: update comments
MirandaWood Jun 6, 2025
d798af5
Merge remote-tracking branch 'origin/next' into mw/blob-batching
MirandaWood Jun 6, 2025
980cc32
chore: generate fixtures, update constants post merge
MirandaWood Jun 6, 2025
fdd20d8
Merge remote-tracking branch 'origin/mw/blob-batching' into mw/blob-b…
MirandaWood Jun 6, 2025
fa5dfdd
feat: remove unused properties from Blob class
MirandaWood Jun 9, 2025
969d4bf
Merge remote-tracking branch 'origin/next' into mw/blob-batching
MirandaWood Jun 9, 2025
61a4d76
chore: post merge fixes, update fixtures and constants
MirandaWood Jun 9, 2025
34edef0
feat: bump bigcurve v
MirandaWood Jun 9, 2025
47fa5ae
Merge remote-tracking branch 'origin/mw/blob-batching' into mw/blob-b…
MirandaWood Jun 9, 2025
baf27d6
chore: post merge fix
MirandaWood Jun 9, 2025
64160bd
Merge remote-tracking branch 'origin/next' into mw/blob-batching-fina…
MirandaWood Jun 9, 2025
e1caed2
feat: add bn conversion method, clear old todos
MirandaWood Jun 9, 2025
f0bdc7b
feat: cleanup, address comments
MirandaWood Jun 10, 2025
db0a1eb
Merge remote-tracking branch 'origin/next' into mw/blob-batching-fina…
MirandaWood Jun 11, 2025
d556918
chore: post merge fixes
MirandaWood Jun 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ compiler_version = ">=0.30.0"

[dependencies]
bigint = { tag = "v0.7.3", git = "https://github.com/noir-lang/noir-bignum" }
bigcurve = { tag = "mw/bump", git = "https://github.com/noir-lang/noir_bigcurve" }
bigcurve = { tag = "v0.9.0", git = "https://github.com/noir-lang/noir_bigcurve" }
types = { path = "../types" }
poseidon = { tag = "v0.1.1", git = "https://github.com/noir-lang/poseidon" }
281 changes: 64 additions & 217 deletions noir-projects/noir-protocol-circuits/crates/blob/src/blob.nr
Original file line number Diff line number Diff line change
@@ -1,104 +1,8 @@
use crate::{
blob_public_inputs::{BlobCommitment, BlobPublicInputs, BlockBlobPublicInputs},
config::{D_INV, LOG_FIELDS_PER_BLOB, ROOTS},
};
use crate::config::{D_INV, LOG_FIELDS_PER_BLOB, ROOTS};

use bigint::{BigNum, BLS12_381_Fr as F};
use std::ops::{Mul, Neg};
use types::{
abis::sponge_blob::SpongeBlob,
constants::{BLOBS_PER_BLOCK, FIELDS_PER_BLOB},
hash::poseidon2_hash_subarray,
traits::Empty,
utils::arrays::array_splice,
};

// TODO(MW): remove pub when fully moved to batching
pub(crate) fn convert_blob_fields(
blob_as_fields: [Field; FIELDS_PER_BLOB],
) -> [F; FIELDS_PER_BLOB] {
let mut blob: [F; FIELDS_PER_BLOB] = [F::zero(); FIELDS_PER_BLOB];
for i in 0..FIELDS_PER_BLOB {
blob[i] = F::from(blob_as_fields[i]);
}
blob
}

pub fn check_block_blob_sponge(
blobs_as_fields: [Field; FIELDS_PER_BLOB * BLOBS_PER_BLOCK],
mut sponge_blob: SpongeBlob,
) -> Field {
// Check that we haven't overfilled the blobs
assert(
sponge_blob.expected_fields <= FIELDS_PER_BLOB * BLOBS_PER_BLOCK,
"Attempted to overfill blobs",
);
// Check that the blob is full
assert(
sponge_blob.expected_fields == sponge_blob.fields,
"Incorrect number of tx effects added to blob",
);
let sponge_hash = sponge_blob.squeeze();
let hash = poseidon2_hash_subarray(blobs_as_fields, sponge_blob.fields);
assert(hash == sponge_hash, "Mismatched hashed tx effects");

sponge_hash
}

// TODO(MW): remove pub when fully moved to batching
pub(crate) fn compute_challenge(
hashed_blobs_fields: Field,
kzg_commitment: BlobCommitment,
) -> Field {
let preimage = [hashed_blobs_fields, kzg_commitment.inner[0], kzg_commitment.inner[1]];
let challenge = poseidon::poseidon2::Poseidon2::hash(preimage, 3);
challenge
}
Comment on lines -27 to -56

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

(Apologies to the reviewer - this is going to be a bit of a nightmare to read through!)
These methods have been moved to blob_batching.nr to keep all non-evaluation blob code in one place.


// Note: the kzg_commitment is technically a BLS12-381 point in (Fq, Fq), but
// we don't actually need to operate on it so we've simply encoded it as fitting inside a
// [Field; 2], since two 254-bit fields more-than covers 381+1=382 bits.
// See yarn-project/foundation/src/blob/index.ts -> commitmentToFields() for encoding
// TODO(MW): remove pub when fully moved to batching
pub(crate) fn evaluate_blob(
blob_as_fields: [Field; FIELDS_PER_BLOB],
kzg_commitment: BlobCommitment,
hashed_blobs_fields: Field,
) -> BlobPublicInputs {
let challenge_z: Field = compute_challenge(hashed_blobs_fields, kzg_commitment);
let challenge_z_as_bignum = F::from(challenge_z);
let blob = convert_blob_fields(blob_as_fields);

let y: F = barycentric_evaluate_blob_at_z(challenge_z_as_bignum, blob);

BlobPublicInputs { z: challenge_z, y, kzg_commitment }
}

// Evaluates each blob required for a block
pub fn evaluate_blobs(
blobs_as_fields: [Field; FIELDS_PER_BLOB * BLOBS_PER_BLOCK],
kzg_commitments: [BlobCommitment; BLOBS_PER_BLOCK],
mut sponge_blob: SpongeBlob,
) -> BlockBlobPublicInputs {
// Note that with multiple blobs per block, each blob uses the same hashed_blobs_fields in:
// challenge_z = H(hashed_blobs_fields, kzg_commitment[0], kzg_commitment[1])
// This is ok, because each commitment is unique to the blob, and we need hashed_blobs_fields to encompass
// all fields in the blob, which it does.
let hashed_blobs_fields = check_block_blob_sponge(blobs_as_fields, sponge_blob);
let mut result = BlockBlobPublicInputs::empty();
for i in 0..BLOBS_PER_BLOCK {
let single_blob_fields = array_splice(blobs_as_fields, i * FIELDS_PER_BLOB);
result.inner[i] =
evaluate_blob(single_blob_fields, kzg_commitments[i], hashed_blobs_fields);
if (result.inner[i].is_zero()) & (single_blob_fields[0] == 0) {
// We use empty PIs for empty blobs, to make it simpler to verify on L1.
// Since our fields come from the base rollup, we know they are tightly packed
// and should contain no 0 values among valid values => single_blob_fields[0] == 0.
result.inner[i] = BlobPublicInputs::empty();
}
}
result
}
Comment on lines -58 to -101

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These have been moved to blob_batching.nr (and modified for batching)

use types::constants::FIELDS_PER_BLOB;

/**
* ___d-1
Expand All @@ -120,7 +24,6 @@ pub fn evaluate_blobs(
* @param ys - the many y_i's of the blob.
*
* @return y = p(z)
* TODO(MW): remove pub when fully moved to batching
*/
pub(crate) fn barycentric_evaluate_blob_at_z(z: F, ys: [F; FIELDS_PER_BLOB]) -> F {
// Note: it's more efficient (saving 30k constraints) to compute:
Expand Down Expand Up @@ -403,22 +306,49 @@ unconstrained fn __compute_sum(fracs: [F; FIELDS_PER_BLOB]) -> F {

mod tests {
// TODO(#9982): Replace unconstrained_config with config and import ROOTS - calculating ROOTS in unconstrained is insecure.
use crate::{
blob::{
barycentric_evaluate_blob_at_z, check_block_blob_sponge, evaluate_blob, evaluate_blobs,
},
blob_public_inputs::BlobCommitment,
config::{D, D_INV},
};
use crate::{blob::barycentric_evaluate_blob_at_z, config::{D, D_INV}};
use super::{__compute_partial_sums, __compute_sum};
use bigint::{BigNum, BLS12_381_Fr as F};
use types::{
abis::sponge_blob::SpongeBlob,
constants::{BLOBS_PER_BLOCK, FIELDS_PER_BLOB},
tests::{fixture_builder::FixtureBuilder, utils::pad_end},
traits::Serialize,
constants::FIELDS_PER_BLOB,
tests::fixture_builder::FixtureBuilder,
traits::{Empty, Serialize},
};

// Note: the kzg_commitment is technically a BLS12-381 point in (Fq, Fq), but
// we don't actually need to operate on it so we've simply encoded it as fitting inside a
// [Field; 2], since two 254-bit fields more-than covers 381+1=382 bits.
// See yarn-project/foundation/src/blob/index.ts -> commitmentToFields() for encoding
pub struct TestBlobEvaluationOutputs {
pub z: Field,
pub y: F,
pub c: [Field; 2],
}

impl Empty for TestBlobEvaluationOutputs {
fn empty() -> Self {
Self { z: 0, y: F::zero(), c: [0, 0] }
}
}

fn evaluate_blob(
blob_as_fields: [Field; FIELDS_PER_BLOB],
kzg_commitment: [Field; 2],
hashed_blobs_fields: Field,
) -> TestBlobEvaluationOutputs {
let challenge_z = poseidon::poseidon2::Poseidon2::hash(
[hashed_blobs_fields, kzg_commitment[0], kzg_commitment[1]],
3,
);
let challenge_z_as_bignum = F::from(challenge_z);
let blob = blob_as_fields.map(|b| F::from(b));

let y: F = barycentric_evaluate_blob_at_z(challenge_z_as_bignum, blob);

TestBlobEvaluationOutputs { z: challenge_z, y, c: kzg_commitment }
}

#[test]
unconstrained fn test_one_note() {
let mut tx_data = FixtureBuilder::new();
Expand All @@ -431,9 +361,8 @@ mod tests {
let mut sponge_blob = SpongeBlob::new(blob_fields.len());
sponge_blob.absorb(blob_fields, blob_fields.len());

let kzg_commitment_in = BlobCommitment { inner: [1, 2] }; // this is made-up nonsense.
let padded_blob_fields = pad_end(blob, 0);
let hashed_blob = check_block_blob_sponge(padded_blob_fields, sponge_blob);
let kzg_commitment_in = [1, 2]; // this is made-up nonsense.
let hashed_blob = sponge_blob.squeeze();
let output = evaluate_blob(blob, kzg_commitment_in, hashed_blob);
let challenge_z = F::from(output.z);
let y = output.y;
Expand All @@ -456,37 +385,6 @@ mod tests {
assert_eq(lhs, rhs);
}

// TODO: After reverting some noir changes (see PR#10341) the below no longer works in unconstrained
// This happened previously in commit 893f1eca422d952d672eec75e3c9ff8f149a9ae8 but a sync fixed it.
// It works and passes in constrained, just takes a min longer.
#[test]
fn test_base() {
let mut tx_data = FixtureBuilder::new();
// Add some random bits of state
tx_data.append_note_hashes(50);
tx_data.set_protocol_nullifier();
tx_data.append_nullifiers(50);
tx_data.append_l2_to_l1_msgs(5);
tx_data.append_public_logs(5);
let mut blob: [Field; FIELDS_PER_BLOB] = [0; FIELDS_PER_BLOB];
let blob_fields = tx_data.to_private_to_rollup_accumulated_data().serialize();
for i in 0..blob_fields.len() {
blob[i] = blob_fields[i];
}
let mut sponge_blob = SpongeBlob::new(blob_fields.len());
sponge_blob.absorb(blob_fields, blob_fields.len());

let kzg_commitment_in = BlobCommitment { inner: [1, 2] }; // this is made-up nonsense.
let padded_blob_fields = pad_end(blob, 0);
let hashed_blob = check_block_blob_sponge(padded_blob_fields, sponge_blob);
let output = evaluate_blob(blob, kzg_commitment_in, hashed_blob);
let expected_z = poseidon::poseidon2::Poseidon2::hash(
[sponge_blob.squeeze(), kzg_commitment_in.inner[0], kzg_commitment_in.inner[1]],
3,
);
assert(expected_z == output.z);
}
Comment on lines -459 to -488

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed this test because it did not cover anything not already covered by other single blob tests. The only difference was that it used FixtureBuilder and serialised the result, which we don't need to test here.


// All hardcoded values in this test are taken from yarn-project/foundation/src/blob/blob.test.ts -> 'should evaluate a blob of 400 items'
#[test]
unconstrained fn test_400() {
Expand All @@ -497,15 +395,12 @@ mod tests {
let mut sponge_blob = SpongeBlob::new(400);
sponge_blob.absorb(blob, 400);

let kzg_commitment_in = BlobCommitment {
inner: [
0x00b2803d5fe972914ba3616033e2748bbaa6dbcddefc3721a54895a7a45e7750,
0x0000000000000000000000000000004dd1a971c7e8d8292be943d05bccebcfea,
],
};
let kzg_commitment_in = [
0x00b2803d5fe972914ba3616033e2748bbaa6dbcddefc3721a54895a7a45e7750,
0x0000000000000000000000000000004dd1a971c7e8d8292be943d05bccebcfea,
];

let padded_blob_fields = pad_end(blob, 0);
let hashed_blob = check_block_blob_sponge(padded_blob_fields, sponge_blob);
let hashed_blob = sponge_blob.squeeze();
let output = evaluate_blob(blob, kzg_commitment_in, hashed_blob);

// y is a BLS field with value 0x212c4f0c0ee5e7dd037110686a4639d191dde7b57ab99b51e4b06e7d827b6c4c
Expand All @@ -517,79 +412,31 @@ mod tests {
assert(expected_y == output.y);
}

// All hardcoded values in this test are taken from yarn-project/foundation/src/blob/blob.test.ts -> 'should evaluate full blobs'
// All hardcoded values in this test are taken from yarn-project/foundation/src/blob/blob.test.ts -> 'should evaluate full blob'
#[test]
unconstrained fn test_full_blobs() {
let mut blob: [Field; FIELDS_PER_BLOB * BLOBS_PER_BLOCK] =
[0; FIELDS_PER_BLOB * BLOBS_PER_BLOCK];
for j in 0..BLOBS_PER_BLOCK {
for i in 0..FIELDS_PER_BLOB {
blob[j * FIELDS_PER_BLOB + i] = i as Field + 2;
}
unconstrained fn test_full_blob() {
let mut blob: [Field; FIELDS_PER_BLOB] = [0; FIELDS_PER_BLOB];
for i in 0..FIELDS_PER_BLOB {
blob[i] = i as Field + 2;
}
let mut sponge_blob = SpongeBlob::new(FIELDS_PER_BLOB);
sponge_blob.absorb(blob, FIELDS_PER_BLOB);

let mut sponge_blob = SpongeBlob::new(FIELDS_PER_BLOB * BLOBS_PER_BLOCK);
sponge_blob.absorb(blob, FIELDS_PER_BLOB * BLOBS_PER_BLOCK);

let kzg_commitment_in = BlobCommitment {
inner: [
0x00ac771dea41e29fc2b7016c32731602c0812548ba0f491864a4e03fdb94b8d3,
0x000000000000000000000000000000d195faad1967cdf005acf73088b0e8474a,
],
};
let kzg_commitment_in = [
0x00ac771dea41e29fc2b7016c32731602c0812548ba0f491864a4e03fdb94b8d3,
0x000000000000000000000000000000d195faad1967cdf005acf73088b0e8474a,
];

let output = evaluate_blobs(blob, [kzg_commitment_in; BLOBS_PER_BLOCK], sponge_blob);
let hashed_blob = sponge_blob.squeeze();
let output = evaluate_blob(blob, kzg_commitment_in, hashed_blob);

// y is a BLS field with value 0x52fd4e272015a79f3889cc9ab1d84bee4326de7d8ced52612ecc9ec137bd38ee
// y is a BLS field with value 0x0365494e66a289c4509ecf97af4ff92aa7ecc38f478ced014b6ae860502a1b1c
let expected_y: F = F::from_limbs([
0x26de7d8ced52612ecc9ec137bd38ee,
0x4e272015a79f3889cc9ab1d84bee43,
0x52fd,
0xecc38f478ced014b6ae860502a1b1c,
0x494e66a289c4509ecf97af4ff92aa7,
0x0365,
]);
for j in 0..BLOBS_PER_BLOCK {
assert(expected_y == output.inner[j].y);
}
}

#[test(should_fail_with = "Found non-zero field after breakpoint")]
unconstrained fn test_no_extra_blob_fields() {
let mut blob: [Field; FIELDS_PER_BLOB] = [0; FIELDS_PER_BLOB];
// Fill fields with 50 inputs...
for i in 0..50 {
blob[i] = 3;
}
// ...but the rollup's sponge is only expecting 45...
let mut sponge_blob = SpongeBlob::new(45);
sponge_blob.absorb(blob, 45);

// ...so the below should fail as it detects we are adding effects which did not come from the rollup.
let padded_blob_fields = pad_end(blob, 0);
let _ = check_block_blob_sponge(padded_blob_fields, sponge_blob);
}

#[test(should_fail_with = "Incorrect number of tx effects added to blob")]
unconstrained fn test_absorbed_too_few_blob_fields() {
let mut blob: [Field; FIELDS_PER_BLOB] = [0; FIELDS_PER_BLOB];
// Fill fields with 50 inputs...
for i in 0..50 {
blob[i] = 3;
}
// ...but the rollup's sponge is expecting 100...
let mut sponge_blob = SpongeBlob::new(100);
sponge_blob.absorb(blob, 50);

// ...so the below should fail as it detects we have not added all the tx effects.
let padded_blob_fields = pad_end(blob, 0);
let _ = check_block_blob_sponge(padded_blob_fields, sponge_blob);
}

#[test]
unconstrained fn test_empty_blob() {
let mut blob: [Field; FIELDS_PER_BLOB * BLOBS_PER_BLOCK] =
[0; FIELDS_PER_BLOB * BLOBS_PER_BLOCK];
let mut sponge_blob = SpongeBlob::new(0);
// The below should not throw
let _ = check_block_blob_sponge(blob, sponge_blob);
assert(expected_y == output.y);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved to blob_batching.nr since check_block_blob_sponge lives there now.


#[test]
Expand Down
Loading
Loading