Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into mw/blob-circuit-2
Browse files Browse the repository at this point in the history
  • Loading branch information
MirandaWood committed Nov 28, 2024
2 parents ccb82b2 + 9e19244 commit fe6fa68
Show file tree
Hide file tree
Showing 19 changed files with 325 additions and 265 deletions.
4 changes: 2 additions & 2 deletions barretenberg/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/AztecProtocol/barretenberg
branch = master
commit = 515858041cc07a84ffd7dd15c8ae6eea502914d7
parent = f081d8013ce37a2109750424d1ed615411d9056a
commit = f61941ed102bef94fd78470362b4345ecd535bab
parent = 3392629818e6d51c01ca4c75c1ad916bb4b4fdb1
method = merge
cmdver = 0.4.6
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/bb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ std::string honk_vk_to_json(std::vector<bb::fr>& data)
}

/**
* @brief Proves and Verifies an ACIR circuit
* @brief Proves and verifies an ACIR circuit
*
* Communication:
* - proc_exit: A boolean value is returned indicating whether the proof is valid.
Expand Down
45 changes: 26 additions & 19 deletions l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
bytes32 _blobsHash,
DataStructures.ExecutionFlags memory _flags
) external view override(IRollup) {
uint256 manaBaseFee = getManaBaseFee(true);
uint256 manaBaseFee = getManaBaseFeeAt(_currentTime, true);
HeaderLib.Header memory header = HeaderLib.decode(_header);
_validateHeader(header, _signatures, _digest, _currentTime, manaBaseFee, _blobsHash, _flags);
}
Expand Down Expand Up @@ -555,7 +555,8 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
HeaderLib.Header memory header = HeaderLib.decode(_args.header);

setupEpoch();
ManaBaseFeeComponents memory components = getManaBaseFeeComponents(true);
ManaBaseFeeComponents memory components =
getManaBaseFeeComponentsAt(Timestamp.wrap(block.timestamp), true);
uint256 manaBaseFee = FeeMath.summedBaseFee(components);
_validateHeader({
_header: header,
Expand Down Expand Up @@ -642,13 +643,13 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
);
}

/**
* @notice Gets the current l1 fees
*
* @return The current l1 fees
*/
function getCurrentL1Fees() public view override(IRollup) returns (L1FeeData memory) {
Slot slot = getCurrentSlot();
function getL1FeesAt(Timestamp _timestamp)
public
view
override(IRollup)
returns (L1FeeData memory)
{
Slot slot = getSlotAt(_timestamp);
if (slot < l1GasOracleValues.slotOfChange) {
return l1GasOracleValues.pre;
}
Expand All @@ -662,9 +663,13 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
*
* @return The mana base fee
*/
function getManaBaseFee(bool _inFeeAsset) public view override(IRollup) returns (uint256) {
ManaBaseFeeComponents memory components = getManaBaseFeeComponents(_inFeeAsset);
return components.summedBaseFee();
function getManaBaseFeeAt(Timestamp _timestamp, bool _inFeeAsset)
public
view
override(IRollup)
returns (uint256)
{
return getManaBaseFeeComponentsAt(_timestamp, _inFeeAsset).summedBaseFee();
}

/**
Expand All @@ -679,25 +684,27 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
*
* @return The mana base fee components
*/
function getManaBaseFeeComponents(bool _inFeeAsset)
function getManaBaseFeeComponentsAt(Timestamp _timestamp, bool _inFeeAsset)
public
view
override(ITestRollup)
returns (ManaBaseFeeComponents memory)
{
FeeHeader storage parentFeeHeader = blocks[tips.pendingBlockNumber].feeHeader;
// If we can prune, we use the proven block, otherwise the pending block
uint256 blockOfInterest =
canPruneAtTime(_timestamp) ? tips.provenBlockNumber : tips.pendingBlockNumber;

FeeHeader storage parentFeeHeader = blocks[blockOfInterest].feeHeader;
uint256 excessMana = (parentFeeHeader.excessMana + parentFeeHeader.manaUsed).clampedAdd(
-int256(FeeMath.MANA_TARGET)
);

// L1FeeData memory fees = ;
uint256 dataCost = Math.mulDiv(
3 * BLOB_GAS_PER_BLOB, getCurrentL1Fees().blobFee, FeeMath.MANA_TARGET, Math.Rounding.Ceil
);
uint256 dataCost =
Math.mulDiv(3 * BLOB_GAS_PER_BLOB, getL1FeesAt(_timestamp).blobFee, FeeMath.MANA_TARGET, Math.Rounding.Ceil);
uint256 gasUsed = FeeMath.L1_GAS_PER_BLOCK_PROPOSED + 3 * GAS_PER_BLOB_POINT_EVALUATION
+ FeeMath.L1_GAS_PER_EPOCH_VERIFIED / EPOCH_DURATION;
uint256 gasCost =
Math.mulDiv(gasUsed, getCurrentL1Fees().baseFee, FeeMath.MANA_TARGET, Math.Rounding.Ceil);
Math.mulDiv(gasUsed, getL1FeesAt(_timestamp).baseFee, FeeMath.MANA_TARGET, Math.Rounding.Ceil);
uint256 provingCost = FeeMath.provingCostPerMana(
blocks[tips.pendingBlockNumber].feeHeader.provingCostPerManaNumerator
);
Expand Down
6 changes: 3 additions & 3 deletions l1-contracts/src/core/interfaces/IRollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface ITestRollup {
function setVkTreeRoot(bytes32 _vkTreeRoot) external;
function setProtocolContractTreeRoot(bytes32 _protocolContractTreeRoot) external;
function setAssumeProvenThroughBlockNumber(uint256 _blockNumber) external;
function getManaBaseFeeComponents(bool _inFeeAsset)
function getManaBaseFeeComponentsAt(Timestamp _timestamp, bool _inFeeAsset)
external
view
returns (ManaBaseFeeComponents memory);
Expand Down Expand Up @@ -123,8 +123,8 @@ interface IRollup {
returns (bytes32);
function getBlock(uint256 _blockNumber) external view returns (BlockLog memory);
function getFeeAssetPrice() external view returns (uint256);
function getManaBaseFee(bool _inFeeAsset) external view returns (uint256);
function getCurrentL1Fees() external view returns (L1FeeData memory);
function getManaBaseFeeAt(Timestamp _timestamp, bool _inFeeAsset) external view returns (uint256);
function getL1FeesAt(Timestamp _timestamp) external view returns (L1FeeData memory);

function archive() external view returns (bytes32);
function archiveAt(uint256 _blockNumber) external view returns (bytes32);
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/test/Rollup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ contract RollupTest is DecoderBase, TimeFns {
}

function _updateHeaderBaseFee(bytes memory _header) internal view returns (bytes memory) {
uint256 baseFee = rollup.getManaBaseFee(true);
uint256 baseFee = rollup.getManaBaseFeeAt(Timestamp.wrap(block.timestamp), true);
assembly {
mstore(add(_header, add(0x20, 0x0228)), baseFee)
}
Expand Down
101 changes: 97 additions & 4 deletions l1-contracts/test/fees/FeeRollup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {IRewardDistributor} from "@aztec/governance/interfaces/IRewardDistributo
import {OracleInput} from "@aztec/core/libraries/FeeMath.sol";
import {ProposeArgs, OracleInput, ProposeLib} from "@aztec/core/libraries/ProposeLib.sol";
import {IERC20} from "@oz/token/ERC20/IERC20.sol";
import {FeeMath} from "@aztec/core/libraries/FeeMath.sol";

import {
FeeHeader as FeeHeaderModel,
Expand Down Expand Up @@ -79,6 +80,8 @@ contract FakeCanonical {
contract FeeRollupTest is FeeModelTestPoints, DecoderBase {
using SlotLib for Slot;
using EpochLib for Epoch;
using FeeMath for uint256;
using FeeMath for ManaBaseFeeComponents;
// We need to build a block that we can submit. We will be using some values from
// the empty blocks, but otherwise populate using the fee model test points.

Expand Down Expand Up @@ -171,7 +174,11 @@ contract FeeRollupTest is FeeModelTestPoints, DecoderBase {
+ point.outputs.mana_base_fee_components_in_fee_asset.congestion_cost
);

assertEq(manaBaseFee, rollup.getManaBaseFee(true), "mana base fee mismatch");
assertEq(
manaBaseFee,
rollup.getManaBaseFeeAt(Timestamp.wrap(block.timestamp), true),
"mana base fee mismatch"
);

uint256 manaSpent = point.block_header.mana_spent;

Expand Down Expand Up @@ -213,12 +220,92 @@ contract FeeRollupTest is FeeModelTestPoints, DecoderBase {
});
}

function test__FeeModelPrune() public {
// Submit a few blocks, then compute what the fees would be with/without a potential prune
// and ensure that they match what happens.
Slot nextSlot = Slot.wrap(1);
for (uint256 i = 0; i < SLOT_DURATION / 12 * 5; i++) {
_loadL1Metadata(i);

if (rollup.getCurrentSlot() == nextSlot) {
TestPoint memory point = points[nextSlot.unwrap() - 1];
Block memory b = getBlock();

rollup.propose(
ProposeArgs({
header: b.header,
archive: b.archive,
blockHash: b.blockHash,
oracleInput: OracleInput({
provingCostModifier: point.oracle_input.proving_cost_modifier,
feeAssetPriceModifier: point.oracle_input.fee_asset_price_modifier
}),
txHashes: b.txHashes
}),
b.signatures,
b.body
);
nextSlot = nextSlot + Slot.wrap(1);
}
}

FeeHeader memory parentFeeHeaderNoPrune =
rollup.getBlock(rollup.getPendingBlockNumber()).feeHeader;
uint256 excessManaNoPrune = (
parentFeeHeaderNoPrune.excessMana + parentFeeHeaderNoPrune.manaUsed
).clampedAdd(-int256(FeeMath.MANA_TARGET));

FeeHeader memory parentFeeHeaderPrune = rollup.getBlock(rollup.getProvenBlockNumber()).feeHeader;
uint256 excessManaPrune = (parentFeeHeaderPrune.excessMana + parentFeeHeaderPrune.manaUsed)
.clampedAdd(-int256(FeeMath.MANA_TARGET));

assertGt(excessManaNoPrune, excessManaPrune, "excess mana should be lower if we prune");

// Find the point in time where we can prune. We can be smarter, but I'm not trying to be smart here
// trying to be foolproof, for I am a fool.
uint256 timeOfPrune = block.timestamp;
while (!rollup.canPruneAtTime(Timestamp.wrap(timeOfPrune))) {
timeOfPrune += SLOT_DURATION;
}

ManaBaseFeeComponents memory componentsPrune =
rollup.getManaBaseFeeComponentsAt(Timestamp.wrap(timeOfPrune), true);

// If we assume that everything is proven, we will see what the fee would be if we did not prune.
rollup.setAssumeProvenThroughBlockNumber(10000);
ManaBaseFeeComponents memory componentsNoPrune =
rollup.getManaBaseFeeComponentsAt(Timestamp.wrap(timeOfPrune), true);

// The congestion multipliers should be different, with the no-prune being higher
// as it is based on the accumulated excess mana.
assertGt(
componentsNoPrune.congestionMultiplier,
componentsPrune.congestionMultiplier,
"congestion multiplier should be higher if we do not prune"
);

assertEq(
componentsPrune.congestionMultiplier,
FeeMath.congestionMultiplier(excessManaPrune),
"congestion multiplier mismatch for prune"
);
assertEq(
componentsNoPrune.congestionMultiplier,
FeeMath.congestionMultiplier(excessManaNoPrune),
"congestion multiplier mismatch for no-prune"
);
}

function test_FeeModelEquivalence() public {
Slot nextSlot = Slot.wrap(1);
Epoch nextEpoch = Epoch.wrap(1);

// Loop through all of the L1 metadata
for (uint256 i = 0; i < l1Metadata.length; i++) {
// Predict what the fee will be before we jump in time!
uint256 baseFeePrediction =
rollup.getManaBaseFeeAt(Timestamp.wrap(l1Metadata[i].timestamp), true);

_loadL1Metadata(i);

// For every "new" slot we encounter, we construct a block using current L1 Data
Expand All @@ -227,11 +314,13 @@ contract FeeRollupTest is FeeModelTestPoints, DecoderBase {
if (rollup.getCurrentSlot() == nextSlot) {
TestPoint memory point = points[nextSlot.unwrap() - 1];

L1FeeData memory fees = rollup.getCurrentL1Fees();
L1FeeData memory fees = rollup.getL1FeesAt(Timestamp.wrap(block.timestamp));
uint256 feeAssetPrice = rollup.getFeeAssetPrice();

ManaBaseFeeComponents memory components = rollup.getManaBaseFeeComponents(false);
ManaBaseFeeComponents memory componentsFeeAsset = rollup.getManaBaseFeeComponents(true);
ManaBaseFeeComponents memory components =
rollup.getManaBaseFeeComponentsAt(Timestamp.wrap(block.timestamp), false);
ManaBaseFeeComponents memory componentsFeeAsset =
rollup.getManaBaseFeeComponentsAt(Timestamp.wrap(block.timestamp), true);
BlockLog memory parentBlockLog = rollup.getBlock(nextSlot.unwrap() - 1);

Block memory b = getBlock();
Expand All @@ -255,6 +344,10 @@ contract FeeRollupTest is FeeModelTestPoints, DecoderBase {

BlockLog memory blockLog = rollup.getBlock(nextSlot.unwrap());

assertEq(
baseFeePrediction, componentsFeeAsset.summedBaseFee(), "base fee prediction mismatch"
);

assertEq(
componentsFeeAsset.congestionCost,
blockLog.feeHeader.congestionCost,
Expand Down
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/AztecProtocol/aztec-nr
branch = master
commit = 10eb08d76cc3bb7cc4cd4d3ef64a42b702f4c5b9
commit = 9e8a380f05a851ae84c456b7debe658414971a20
method = merge
cmdver = 0.4.6
parent = c5a4ee5304750adab8295dd15fa1682d0e9d24a8
parent = d157084819c626ca76e78a9f92bbfa7f41123227
27 changes: 8 additions & 19 deletions noir/noir-repo/compiler/noirc_evaluator/src/ssa/ir/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,7 @@ pub(crate) enum Instruction {
///
/// Where we save the result of !then_condition so that we have the same
/// ValueId for it each time.
IfElse {
then_condition: ValueId,
then_value: ValueId,
else_condition: ValueId,
else_value: ValueId,
},
IfElse { then_condition: ValueId, then_value: ValueId, else_value: ValueId },

/// Creates a new array or slice.
///
Expand Down Expand Up @@ -524,14 +519,11 @@ impl Instruction {
assert_message: assert_message.clone(),
}
}
Instruction::IfElse { then_condition, then_value, else_condition, else_value } => {
Instruction::IfElse {
then_condition: f(*then_condition),
then_value: f(*then_value),
else_condition: f(*else_condition),
else_value: f(*else_value),
}
}
Instruction::IfElse { then_condition, then_value, else_value } => Instruction::IfElse {
then_condition: f(*then_condition),
then_value: f(*then_value),
else_value: f(*else_value),
},
Instruction::MakeArray { elements, typ } => Instruction::MakeArray {
elements: elements.iter().copied().map(f).collect(),
typ: typ.clone(),
Expand Down Expand Up @@ -590,10 +582,9 @@ impl Instruction {
| Instruction::RangeCheck { value, .. } => {
f(*value);
}
Instruction::IfElse { then_condition, then_value, else_condition, else_value } => {
Instruction::IfElse { then_condition, then_value, else_value } => {
f(*then_condition);
f(*then_value);
f(*else_condition);
f(*else_value);
}
Instruction::MakeArray { elements, typ: _ } => {
Expand Down Expand Up @@ -756,7 +747,7 @@ impl Instruction {
None
}
}
Instruction::IfElse { then_condition, then_value, else_condition, else_value } => {
Instruction::IfElse { then_condition, then_value, else_value } => {
let typ = dfg.type_of_value(*then_value);

if let Some(constant) = dfg.get_numeric_constant(*then_condition) {
Expand All @@ -775,13 +766,11 @@ impl Instruction {

if matches!(&typ, Type::Numeric(_)) {
let then_condition = *then_condition;
let else_condition = *else_condition;

let result = ValueMerger::merge_numeric_values(
dfg,
block,
then_condition,
else_condition,
then_value,
else_value,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,8 @@ fn simplify_slice_push_back(
let mut value_merger =
ValueMerger::new(dfg, block, &mut slice_sizes, unknown, None, call_stack);

let new_slice = value_merger.merge_values(
len_not_equals_capacity,
len_equals_capacity,
set_last_slice_value,
new_slice,
);
let new_slice =
value_merger.merge_values(len_not_equals_capacity, set_last_slice_value, new_slice);

SimplifyResult::SimplifiedToMultiple(vec![new_slice_length, new_slice])
}
Expand Down
Loading

0 comments on commit fe6fa68

Please sign in to comment.