Skip to content

Commit

Permalink
refactor: make args simpler to read (#12348)
Browse files Browse the repository at this point in the history
Fixes #11933 and adds some more explicit links to #8829

---------

Co-authored-by: Mitch <mitchell@aztecprotocol.com>
  • Loading branch information
LHerskind and just-mitch authored Feb 27, 2025
1 parent 5cde0a1 commit 98cd1bb
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 96 deletions.
4 changes: 2 additions & 2 deletions l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright 2024 Aztec Labs.
pragma solidity >=0.8.27;

import {IRollup, ChainTips} from "@aztec/core/interfaces/IRollup.sol";
import {IRollup, ChainTips, PublicInputArgs} from "@aztec/core/interfaces/IRollup.sol";
import {
IStaking,
ValidatorInfo,
Expand Down Expand Up @@ -161,7 +161,7 @@ contract Rollup is IStaking, IValidatorSelection, IRollup, RollupCore {
function getEpochProofPublicInputs(
uint256 _start,
uint256 _end,
bytes32[7] calldata _args,
PublicInputArgs calldata _args,
bytes32[] calldata _fees,
bytes calldata _blobPublicInputs,
bytes calldata _aggregationObject
Expand Down
16 changes: 13 additions & 3 deletions l1-contracts/src/core/interfaces/IRollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,20 @@ import {Timestamp, Slot, Epoch} from "@aztec/core/libraries/TimeLib.sol";
import {IRewardDistributor} from "@aztec/governance/interfaces/IRewardDistributor.sol";
import {IERC20} from "@oz/token/ERC20/IERC20.sol";

struct PublicInputArgs {
bytes32 previousArchive;
bytes32 endArchive;
bytes32 previousBlockHash; // @todo #8829 Not needed as public input, unconstrained on L1
bytes32 endBlockHash; // @todo #8829 Not needed as public input, unconstrained on L1
Timestamp endTimestamp;
bytes32 outHash;
address proverId;
}

struct SubmitEpochRootProofArgs {
uint256 start; // inclusive
uint256 end; // inclusive
bytes32[7] args; // @todo These are obhorrent and so easy to mess up with wrong padding.
PublicInputArgs args;
bytes32[] fees;
bytes blobPublicInputs;
bytes aggregationObject;
Expand Down Expand Up @@ -111,7 +121,7 @@ interface IRollupCore {
event L2BlockProposed(
uint256 indexed blockNumber, bytes32 indexed archive, bytes32[] versionedBlobHashes
);
event L2ProofVerified(uint256 indexed blockNumber, bytes32 indexed proverId);
event L2ProofVerified(uint256 indexed blockNumber, address indexed proverId);
event PrunedPending(uint256 provenBlockNumber, uint256 pendingBlockNumber);

function claimSequencerRewards(address _recipient) external returns (uint256);
Expand Down Expand Up @@ -162,7 +172,7 @@ interface IRollup is IRollupCore {
function getEpochProofPublicInputs(
uint256 _start,
uint256 _end,
bytes32[7] calldata _args,
PublicInputArgs calldata _args,
bytes32[] calldata _fees,
bytes calldata _blobPublicInputs,
bytes calldata _aggregationObject
Expand Down
13 changes: 13 additions & 0 deletions l1-contracts/src/core/libraries/Converter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024 Aztec Labs.
pragma solidity >=0.8.27;

library Converter {
function addressToField(address _a) internal pure returns (bytes32) {
return bytes32(uint256(uint160(_a)));
}

function fieldToAddress(bytes32 _f) internal pure returns (address) {
return address(uint160(uint256(_f)));
}
}
44 changes: 23 additions & 21 deletions l1-contracts/src/core/libraries/RollupLibs/EpochProofLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ pragma solidity >=0.8.27;

import {
SubmitEpochRootProofArgs,
PublicInputArgs,
IRollupCore,
EpochRewards,
SubEpochRewards
} from "@aztec/core/interfaces/IRollup.sol";
import {RollupStore, SubmitEpochRootProofArgs} from "@aztec/core/interfaces/IRollup.sol";
import {Constants} from "@aztec/core/libraries/ConstantsGen.sol";
import {Converter} from "@aztec/core/libraries/Converter.sol";
import {Errors} from "@aztec/core/libraries/Errors.sol";
import {Errors} from "@aztec/core/libraries/Errors.sol";
import {STFLib, RollupStore} from "@aztec/core/libraries/RollupLibs/core/STFLib.sol";
Expand Down Expand Up @@ -57,7 +59,7 @@ library EpochProofLib {

handleRewardsAndFees(_args, endEpoch);

emit IRollupCore.L2ProofVerified(_args.end, _args.args[6]);
emit IRollupCore.L2ProofVerified(_args.end, _args.args.proverId);
}

/**
Expand All @@ -77,7 +79,7 @@ library EpochProofLib {
function getEpochProofPublicInputs(
uint256 _start,
uint256 _end,
bytes32[7] calldata _args,
PublicInputArgs calldata _args,
bytes32[] calldata _fees,
bytes calldata _blobPublicInputs,
bytes calldata _aggregationObject
Expand All @@ -99,32 +101,34 @@ library EpochProofLib {
{
bytes32 expectedPreviousArchive = rollupStore.blocks[_start - 1].archive;
require(
expectedPreviousArchive == _args[0],
Errors.Rollup__InvalidPreviousArchive(expectedPreviousArchive, _args[0])
expectedPreviousArchive == _args.previousArchive,
Errors.Rollup__InvalidPreviousArchive(expectedPreviousArchive, _args.previousArchive)
);
}

{
bytes32 expectedEndArchive = rollupStore.blocks[_end].archive;
require(
expectedEndArchive == _args[1],
Errors.Rollup__InvalidArchive(expectedEndArchive, _args[1])
expectedEndArchive == _args.endArchive,
Errors.Rollup__InvalidArchive(expectedEndArchive, _args.endArchive)
);
}

{
bytes32 expectedPreviousBlockHash = rollupStore.blocks[_start - 1].blockHash;
require(
expectedPreviousBlockHash == _args[2],
Errors.Rollup__InvalidPreviousBlockHash(expectedPreviousBlockHash, _args[2])
expectedPreviousBlockHash == _args.previousBlockHash,
Errors.Rollup__InvalidPreviousBlockHash(
expectedPreviousBlockHash, _args.previousBlockHash
)
);
}

{
bytes32 expectedEndBlockHash = rollupStore.blocks[_end].blockHash;
require(
expectedEndBlockHash == _args[3],
Errors.Rollup__InvalidBlockHash(expectedEndBlockHash, _args[3])
expectedEndBlockHash == _args.endBlockHash,
Errors.Rollup__InvalidBlockHash(expectedEndBlockHash, _args.endBlockHash)
);
}
}
Expand All @@ -151,33 +155,33 @@ library EpochProofLib {
// }
{
// previous_archive.root: the previous archive tree root
publicInputs[0] = _args[0];
publicInputs[0] = _args.previousArchive;

// previous_archive.next_available_leaf_index: the previous archive next available index
// normally this should be equal to the block number (since leaves are 0-indexed and blocks 1-indexed)
// but in yarn-project/merkle-tree/src/new_tree.ts we prefill the tree so that block N is in leaf N
publicInputs[1] = bytes32(_start);

// end_archive.root: the new archive tree root
publicInputs[2] = _args[1];
publicInputs[2] = _args.endArchive;

// end_archive.next_available_leaf_index: the new archive next available index
publicInputs[3] = bytes32(_end + 1);

// previous_block_hash: the block hash just preceding this epoch
publicInputs[4] = _args[2];
publicInputs[4] = _args.previousBlockHash;

// end_block_hash: the last block hash in the epoch
publicInputs[5] = _args[3];
publicInputs[5] = _args.endBlockHash;

// end_timestamp: the timestamp of the last block in the epoch
publicInputs[6] = _args[4];
publicInputs[6] = bytes32(Timestamp.unwrap(_args.endTimestamp));

// end_block_number: last block number in the epoch
publicInputs[7] = bytes32(_end);

// out_hash: root of this epoch's l2 to l1 message tree
publicInputs[8] = _args[5];
publicInputs[8] = _args.outHash;
}

uint256 feesLength = Constants.AZTEC_MAX_EPOCH_DURATION * 2;
Expand All @@ -196,7 +200,7 @@ library EpochProofLib {
offset += 1;

// prover_id: id of current epoch's prover
publicInputs[offset] = _args[6];
publicInputs[offset] = Converter.addressToField(_args.proverId);
offset += 1;

{
Expand Down Expand Up @@ -257,8 +261,7 @@ library EpochProofLib {
SubEpochRewards storage $sr = $er.subEpoch[length];

{
// The address is left padded within the bytes32
address prover = address(bytes20(_args.args[6] << 96));
address prover = _args.args.proverId;
require(
!$sr.hasSubmitted[prover], Errors.Rollup__ProverHaveAlreadySubmitted(prover, _endEpoch)
);
Expand Down Expand Up @@ -298,8 +301,7 @@ library EpochProofLib {
v.sequencerFee = fee - burn - v.proverFee;

{
// The address is left padded within the bytes32
v.sequencer = address(bytes20(_args.fees[i * 2] << 96));
v.sequencer = Converter.fieldToAddress(_args.fees[i * 2]);
rollupStore.sequencerRewards[v.sequencer] += (v.sequencerBlockReward + v.sequencerFee);
}
}
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/src/core/libraries/RollupLibs/ExtRollupLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright 2024 Aztec Labs.
pragma solidity >=0.8.27;

import {SubmitEpochRootProofArgs} from "@aztec/core/interfaces/IRollup.sol";
import {SubmitEpochRootProofArgs, PublicInputArgs} from "@aztec/core/interfaces/IRollup.sol";
import {StakingLib} from "./../staking/StakingLib.sol";
import {ValidatorSelectionLib} from "./../ValidatorSelectionLib/ValidatorSelectionLib.sol";
import {BlobLib} from "./BlobLib.sol";
Expand Down Expand Up @@ -36,7 +36,7 @@ library ExtRollupLib {
function getEpochProofPublicInputs(
uint256 _start,
uint256 _end,
bytes32[7] calldata _args,
PublicInputArgs calldata _args,
bytes32[] calldata _fees,
bytes calldata _blobPublicInputs,
bytes calldata _aggregationObject
Expand Down
39 changes: 20 additions & 19 deletions l1-contracts/test/Rollup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
SubmitEpochRootProofArgs,
EthValue,
FeeAssetValue,
FeeAssetPerEthE9
FeeAssetPerEthE9,
PublicInputArgs
} from "@aztec/core/interfaces/IRollup.sol";
import {FeeJuicePortal} from "@aztec/core/FeeJuicePortal.sol";
import {NaiveMerkle} from "./merkle/Naive.sol";
Expand Down Expand Up @@ -581,15 +582,15 @@ contract RollupTest is RollupBase {

BlockLog memory blockLog = rollup.getBlock(0);

bytes32[7] memory args = [
blockLog.archive,
data.archive,
blockLog.blockHash,
data.blockHash,
bytes32(0),
bytes32(0),
bytes32(0)
];
PublicInputArgs memory args = PublicInputArgs({
previousArchive: blockLog.archive,
endArchive: data.archive,
previousBlockHash: blockLog.blockHash,
endBlockHash: data.blockHash,
endTimestamp: Timestamp.wrap(0),
outHash: bytes32(0),
proverId: address(0)
});

bytes32[] memory fees = new bytes32[](Constants.AZTEC_MAX_EPOCH_DURATION * 2);

Expand Down Expand Up @@ -919,15 +920,15 @@ contract RollupTest is RollupBase {
address _coinbase,
uint256 _fee
) internal {
bytes32[7] memory args = [
_prevArchive,
_archive,
_prevBlockHash,
_blockHash,
bytes32(0), // WHAT ?
bytes32(0), // WHAT ?
bytes32(uint256(uint160(bytes20(_prover)))) // Need the address to be left padded within the bytes32
];
PublicInputArgs memory args = PublicInputArgs({
previousArchive: _prevArchive,
endArchive: _archive,
previousBlockHash: _prevBlockHash,
endBlockHash: _blockHash,
endTimestamp: Timestamp.wrap(0),
outHash: bytes32(0),
proverId: _prover
});

bytes32[] memory fees = new bytes32[](Constants.AZTEC_MAX_EPOCH_DURATION * 2);
fees[0] = bytes32(uint256(uint160(bytes20(_coinbase)))); // Need the address to be left padded within the bytes32
Expand Down
22 changes: 12 additions & 10 deletions l1-contracts/test/base/RollupBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ pragma solidity >=0.8.27;
import {DecoderBase} from "./DecoderBase.sol";

import {IInstance} from "@aztec/core/interfaces/IInstance.sol";
import {BlockLog, SubmitEpochRootProofArgs} from "@aztec/core/interfaces/IRollup.sol";
import {
BlockLog, SubmitEpochRootProofArgs, PublicInputArgs
} from "@aztec/core/interfaces/IRollup.sol";
import {Constants} from "@aztec/core/libraries/ConstantsGen.sol";
import {Strings} from "@oz/utils/Strings.sol";
import {NaiveMerkle} from "../merkle/Naive.sol";
Expand Down Expand Up @@ -65,15 +67,15 @@ contract RollupBase is DecoderBase {
BlockLog memory parentBlockLog = rollup.getBlock(startBlockNumber - 1);

// What are these even?
bytes32[7] memory args = [
parentBlockLog.archive,
endFull.block.archive,
parentBlockLog.blockHash,
endFull.block.blockHash,
bytes32(0), // WHAT ?
bytes32(0), // WHAT ?
bytes32(uint256(uint160(bytes20(_prover)))) // Need the address to be left padded within the bytes32
];
PublicInputArgs memory args = PublicInputArgs({
previousArchive: parentBlockLog.archive,
endArchive: endFull.block.archive,
previousBlockHash: parentBlockLog.blockHash,
endBlockHash: endFull.block.blockHash,
endTimestamp: Timestamp.wrap(0), // WHAT ?
outHash: bytes32(0), // WHAT ?
proverId: _prover
});

bytes32[] memory fees = new bytes32[](Constants.AZTEC_MAX_EPOCH_DURATION * 2);
bytes memory blobPublicInputs;
Expand Down
22 changes: 12 additions & 10 deletions l1-contracts/test/fees/FeeRollup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import {Inbox} from "@aztec/core/messagebridge/Inbox.sol";
import {Outbox} from "@aztec/core/messagebridge/Outbox.sol";
import {Errors} from "@aztec/core/libraries/Errors.sol";
import {Rollup, Config, BlockLog} from "@aztec/core/Rollup.sol";
import {IRollup, SubmitEpochRootProofArgs} from "@aztec/core/interfaces/IRollup.sol";
import {
IRollup, SubmitEpochRootProofArgs, PublicInputArgs
} from "@aztec/core/interfaces/IRollup.sol";
import {FeeJuicePortal} from "@aztec/core/FeeJuicePortal.sol";
import {NaiveMerkle} from "../merkle/Naive.sol";
import {MerkleTestUtil} from "../merkle/TestUtil.sol";
Expand Down Expand Up @@ -453,15 +455,15 @@ contract FeeRollupTest is FeeModelTestPoints, DecoderBase {
uint256 cuauhxicalliBalanceBefore = asset.balanceOf(rollup.getCuauhxicalli());
uint256 sequencerRewardsBefore = rollup.getSequencerRewards(coinbase);

bytes32[7] memory args = [
rollup.getBlock(start).archive,
rollup.getBlock(start + epochSize - 1).archive,
rollup.getBlock(start).blockHash,
rollup.getBlock(start + epochSize - 1).blockHash,
bytes32(0),
bytes32(0),
bytes32(0)
];
PublicInputArgs memory args = PublicInputArgs({
previousArchive: rollup.getBlock(start).archive,
endArchive: rollup.getBlock(start + epochSize - 1).archive,
previousBlockHash: rollup.getBlock(start).blockHash,
endBlockHash: rollup.getBlock(start + epochSize - 1).blockHash,
endTimestamp: Timestamp.wrap(0),
outHash: bytes32(0),
proverId: address(0)
});

bytes memory blobPublicInputs;
for (uint256 j = 0; j < epochSize; j++) {
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/archiver/src/archiver/data_retrieval.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Blob, BlobDeserializationError } from '@aztec/blob-lib';
import type { BlobSinkClientInterface } from '@aztec/blob-sink/client';
import type { ViemPublicClient } from '@aztec/ethereum';
import type { EpochProofPublicInputArgs, ViemPublicClient } from '@aztec/ethereum';
import { asyncPool } from '@aztec/foundation/async-pool';
import type { EthAddress } from '@aztec/foundation/eth-address';
import type { ViemSignature } from '@aztec/foundation/eth-signature';
Expand Down Expand Up @@ -406,16 +406,16 @@ export async function getProofFromSubmitProofTx(
{
start: bigint;
end: bigint;
args: readonly [Hex, Hex, Hex, Hex, Hex, Hex, Hex];
args: EpochProofPublicInputArgs;
fees: readonly Hex[];
aggregationObject: Hex;
proof: Hex;
},
];

aggregationObject = Buffer.from(hexToBytes(decodedArgs.aggregationObject));
proverId = Fr.fromHexString(decodedArgs.args[6]);
archiveRoot = Fr.fromHexString(decodedArgs.args[1]);
proverId = Fr.fromHexString(decodedArgs.args.proverId);
archiveRoot = Fr.fromHexString(decodedArgs.args.endArchive);
proof = Proof.fromBuffer(Buffer.from(hexToBytes(decodedArgs.proof)));
} else {
throw new Error(`Unexpected proof method called ${functionName}`);
Expand Down
Loading

0 comments on commit 98cd1bb

Please sign in to comment.