Skip to content

feat(txe): auto-generate oracle serialization roundtrip tests - #24138

Merged
nchamo merged 5 commits into
merge-train/fairies-v5from
nchamo/oracle-tests
Jun 19, 2026
Merged

feat(txe): auto-generate oracle serialization roundtrip tests#24138
nchamo merged 5 commits into
merge-train/fairies-v5from
nchamo/oracle-tests

Conversation

@nchamo

@nchamo nchamo commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Motivation

#23537 introduced oracle tests that verify serialization across Noir and TS. They were manual, so we had to write one for every oracle. Worse, when two oracles used the same types we ended up testing the same serialization twice, by hand.

Our change

This PR adds a #[auto_serialization_test] macro that generates those tests automatically, one per oracle. Instead of writing a test each time, we define which values to test for a given type once, and every oracle using that type is covered. Types with more than one serialization shape are handled too: an Option, for example, is tested in both its some and none forms.

Notes

I first tried folding this into a single macro that would emit both the oracle function and its test, instead of pairing #[auto_serialization_test] with #[oracle(...)]. It didn't work: #[oracle(...)] is a special built-in Noir attribute rather than a regular comptime macro, so I run into different issues.

Next steps

This PR only covers simple types. Follow-ups will add the harder ones until every oracle is tested, at which point CI can start failing when an oracle isn't. That will let us drop the serialization tests we currently add by hand, in both Noir and TS, for each new oracle type.

@nchamo nchamo added the ci-draft Run CI on draft PRs. label Jun 16, 2026
@nchamo nchamo self-assigned this Jun 16, 2026
@nchamo
nchamo requested a review from mverzilli June 16, 2026 17:26
@nchamo
nchamo marked this pull request as ready for review June 16, 2026 17:26
@nchamo
nchamo requested a review from nventuro as a code owner June 16, 2026 17:26
@vezenovm

Copy link
Copy Markdown
Contributor

It didn't work: #[oracle(...)] is a special built-in Noir attribute rather than a regular comptime macro, so I run into different issues.

A separate solution to reduce macro declarations, we could probably simplify the test macro into a single module macro:

#[auto_serialization_tests]
pub mod avm;

Should be able to call into the same macros written here just for oracle functions within a module.

storage_write_opcode(storage_slot, value);
}

#[auto_serialization_test]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we should be able to have a single macro on the module. I see we missed some tests not being marked here like aztec_avm_transactionFee

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.

Actually, that is intended in this case. TXE doesn't implement all oracle AVM oracles because they are not all needed. So I can't (and don't need to) test all of them

But I didn't know I could do that, TIL. Will look more into it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps we could filter by attribute name as well (e.g., w/ a hard coded excluded txe oracles). We could then still contain all oracle test generation from a single macro.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this actually is aligned with a discussion I had with @nventuro somewhere else: maybe we should restructure the codebase so that we have feature/oracles instead of oracle/feature.nr and feature/ importing those.

if we had avm/oracles.nr or avm/oracles/mod.nr making auto_serialization_test a mod attribute would fit nicely without further work

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.

I decided to go with @vezenovm 's suggestion with a list of excluded oracles. Since this is only the first step, there are many oracles we are not implementing yet, simply because we can't. Didn't want to move them around just for that reason, made sense to simply exclude them. Once we are done with all oracles, we can revisit this

Comment thread noir-projects/aztec-nr/aztec/src/macros/oracle_testing.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/macros/oracle_testing.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/macros/oracle_testing.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/macros/oracle_testing.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/macros/oracle_testing.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/macros/oracle_testing.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/macros/oracle_testing.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/macros/oracle_testing.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/macros/oracle_testing.nr
Comment thread noir-projects/aztec-nr/aztec/src/macros/oracle_testing.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/macros/oracle_testing.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/macros/oracle_testing.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/macros/oracle_testing.nr Outdated
Comment thread yarn-project/txe/src/oracle/test-resolver/default_fixtures.test.ts Outdated
Comment thread yarn-project/txe/src/oracle/test-resolver/default_fixtures.ts Outdated
Comment thread yarn-project/txe/src/oracle/test-resolver/default_fixtures.ts Outdated
Comment thread yarn-project/txe/src/oracle/test-resolver/default_fixtures.ts
Comment on lines +91 to +101
interface Scenario {
value: unknown;
name?: string;
}

function unnamed(value: unknown): Scenario {
return { value };
}
function named(value: unknown, name: string): Scenario {
return { value, name };
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe making name mandatory and defaulting to default could remove some complexity?

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.

I don't think so. It would be pretty much the same

Comment thread yarn-project/txe/src/oracle/test-resolver/resolver.ts Outdated

@mverzilli mverzilli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Super useful! Two main objections, in order of personal importance:

  1. Comments are excessive, in most cases reading them actively confused me, where reading code would have sufficed. I was battling hard against my brain just filtering them out.
  2. I second Maxim, would be nice to only have to write the autoserialize attribute once per module. If we want to leave avm oracles out of this without incurring in a huge change, maybe we can start by segregating avm oracles to their own module?

// TODO: implement once we support more complex types
quote { emit_public_log_opcode },
quote { returndata_copy_opcode },
// TODO: requires fix on registry

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 were uncovered by the tests, so they work! The registry implements a return type different from the actual Noir oracle functions. I will fix that in another PR, didn't want to make the PR bigger

@AztecBot

Copy link
Copy Markdown
Collaborator

Flakey Tests

🤖 says: This CI run detected 4 tests that failed, but were tolerated due to a .test_patterns.yml entry.

\033FLAKED\033 (8;;http://ci.aztec-labs.com/30bb3cd568ad39a8�30bb3cd568ad39a88;;�): yarn-project/end-to-end/scripts/run_test.sh ha src/composed/ha/e2e_ha_full.parallel.test.ts "should not delete recent duties via cleanupOldDuties when node clock is ahead" (40s) (code: 0)
\033FLAKED\033 (8;;http://ci.aztec-labs.com/9cbada064f8fdde0�9cbada064f8fdde08;;�): yarn-project/end-to-end/scripts/run_test.sh ha src/composed/ha/e2e_ha_full.parallel.test.ts "should not be affected by process.env.TZ changes" (40s) (code: 0)
\033FLAKED\033 (8;;http://ci.aztec-labs.com/13cf9db664d51043�13cf9db664d510438;;�): yarn-project/kv-store/scripts/run_test.sh src/bench/sqlite-opfs-encrypted/map_bench.test.ts (2s) (code: 0)
\033FLAKED\033 (8;;http://ci.aztec-labs.com/c1c733629173be8e�c1c733629173be8e8;;�): yarn-project/kv-store/scripts/run_test.sh src/sqlite-opfs/internal/ordered-binary-browser.test.ts (2s) (code: 0)

@nchamo
nchamo requested review from mverzilli and vezenovm June 18, 2026 19:36

@mverzilli mverzilli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!

@nchamo
nchamo merged commit e0f5759 into merge-train/fairies-v5 Jun 19, 2026
12 checks passed
@nchamo
nchamo deleted the nchamo/oracle-tests branch June 19, 2026 15:34
rangozd pushed a commit to rangozd/aztec-packages that referenced this pull request Aug 5, 2026
BEGIN_COMMIT_OVERRIDE
feat(txe): auto-generate oracle serialization roundtrip tests (AztecProtocol#24138)
END_COMMIT_OVERRIDE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-draft Run CI on draft PRs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants