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

feat: global variables in public noir #917

Merged
merged 14 commits into from
Jul 3, 2023
Merged

Conversation

LHerskind
Copy link
Contributor

@LHerskind LHerskind commented Jun 27, 2023

Description

Fixes #832.

Note that this is not adding a check for consistency between the global variables used in the public execution and the base rollup, so sequencer can at this point lie his ass off.

The sequencer prepares global variables, but currently the timestamp is not meaningfully constrained and can be antyhing, will be constrained through #830 separately, which also need to modify the value inputted.

Checklist:

  • I have reviewed my diff in github, line by line.
  • Every change is related to the PR description.
  • I have linked this pull request to the issue(s) that it resolves.
  • There are no unexpected formatting changes, superfluous debug logs, or commented-out code.
  • The branch has been merged or rebased against the head of its merge target.
  • I'm happy for the PR to be merged at the reviewer's next convenience.

Copy link
Member

@Maddiaa0 Maddiaa0 left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -30,6 +30,10 @@ export class GlobalVariables {
return new GlobalVariables(...GlobalVariables.getFields(fields));
}

static empty(): GlobalVariables {
Copy link
Member

Choose a reason for hiding this comment

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

ik this is already merged, but should we rename GlobalVariables to GlobalContextVariables?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GlobalBlockContextVariables or maybe GlobalBlockVariables? Context is not super descriptive around what context it is.

Copy link
Contributor

Choose a reason for hiding this comment

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

"Global" and "Block" seem opposite? Global would mean always true whereas block variables to me would be things that change per block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are "global" from the POV of noir similarly to how they are in solidity. But some of them change depending on the individual block, so naming might be a little weird.

Copy link
Member

Choose a reason for hiding this comment

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

I like global block variables

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will address in a separate pr as it is used a lot of places and don't want to pollute this one.

@@ -28,8 +28,8 @@ contract Child {
// Nested public functions always get called with MAX_ARGS, since we don't have the ABI available
// during execution time to know how many args are expected, hence the _padding argument. We should
// be able to remove it when we migrate to brillig.
open fn pubValue(_inputs: PublicContextInputs, base_value: Field, _padding: [Field; abi::MAX_ARGS - 1]) -> pub Field {
base_value + 42
open fn pubValue(inputs: PublicContextInputs, base_value: Field, _padding: [Field; abi::MAX_ARGS - 1]) -> pub Field {
Copy link
Member

Choose a reason for hiding this comment

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

maybe we should make this a seperate test/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Were thinking that it was fine as this since we were anyway just returning random values, so might as well return the values from the struct.

Copy link
Member

@Maddiaa0 Maddiaa0 left a comment

Choose a reason for hiding this comment

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

lgtm

@LHerskind LHerskind force-pushed the lh/globals-noir-public branch 2 times, most recently from 41222b2 to bef50ae Compare June 30, 2023 10:08
@LHerskind LHerskind marked this pull request as ready for review June 30, 2023 10:08
new_l2_to_l1_msgs_to_insert[i] = compute_l2_to_l1_hash<NT>(storage_contract_address,
fr(1), // rollup version id
private_call_public_inputs.version,
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

@@ -30,6 +30,10 @@ export class GlobalVariables {
return new GlobalVariables(...GlobalVariables.getFields(fields));
}

static empty(): GlobalVariables {
Copy link
Contributor

Choose a reason for hiding this comment

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

"Global" and "Block" seem opposite? Global would mean always true whereas block variables to me would be things that change per block.

@@ -266,7 +267,14 @@ describe('L1Publisher integration', () => {
await makeBloatedProcessedTx(128 * i + 96),
await makeBloatedProcessedTx(128 * i + 128),
];
const [block] = await builder.buildL2Block(1 + i, txs, l1ToL2Messages);
// @todo @LHerskind fix time.
Copy link
Contributor

Choose a reason for hiding this comment

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

this stale?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, its part of a separate pr that is to fix #830, to be fixed in #948

Copy link
Member

@Maddiaa0 Maddiaa0 left a comment

Choose a reason for hiding this comment

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

answered question from last week plus repitions can be decreased in solo block builder test. Over all looks great though

@@ -30,6 +30,10 @@ export class GlobalVariables {
return new GlobalVariables(...GlobalVariables.getFields(fields));
}

static empty(): GlobalVariables {
Copy link
Member

Choose a reason for hiding this comment

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

I like global block variables

});

it('builds an L2 block using mock simulator', async () => {
// Assemble a fake transaction
const txs = await buildMockSimulatorInputs();

// Actually build a block!
const [l2Block, proof] = await builder.buildL2Block(blockNumber, txs, mockL1ToL2Messages);
const globalVariables = new GlobalVariables(chainId, version, new Fr(blockNumber), Fr.ZERO);
Copy link
Member

Choose a reason for hiding this comment

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

This seems able to go within beforeEach

@LHerskind LHerskind force-pushed the lh/globals-noir-public branch from 53f1386 to cd2621b Compare July 3, 2023 08:47
@Maddiaa0 Maddiaa0 enabled auto-merge (squash) July 3, 2023 08:56
@Maddiaa0 Maddiaa0 merged commit 145e34e into master Jul 3, 2023
@Maddiaa0 Maddiaa0 deleted the lh/globals-noir-public branch July 3, 2023 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Access chainid, block number, timestamp and version from noir
3 participants