Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 21 additions & 7 deletions l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ import {
DataStructures,
ExtRollupLib,
IntRollupLib,
EpochRewards
EpochRewards,
FeeAssetPerEthE9,
EthValue,
FeeAssetValue,
PriceLib
} from "./RollupCore.sol";
// solhint-enable no-unused-import

Expand All @@ -54,6 +58,7 @@ contract Rollup is IStaking, IValidatorSelection, IRollup, RollupCore {
using TimeLib for Slot;
using TimeLib for Epoch;
using IntRollupLib for ManaBaseFeeComponents;
using PriceLib for EthValue;

constructor(
IFeeJuicePortal _fpcJuicePortal,
Expand Down Expand Up @@ -440,7 +445,7 @@ contract Rollup is IStaking, IValidatorSelection, IRollup, RollupCore {
override(IRollup)
returns (uint256)
{
return sequencerRewards[_sequencer];
return rollupStore.sequencerRewards[_sequencer];
}

function getCollectiveProverRewardsForEpoch(Epoch _epoch)
Expand All @@ -449,7 +454,7 @@ contract Rollup is IStaking, IValidatorSelection, IRollup, RollupCore {
override(IRollup)
returns (uint256)
{
return epochRewards[_epoch].rewards;
return rollupStore.epochRewards[_epoch].rewards;
}

function getSpecificProverRewardsForEpoch(Epoch _epoch, address _prover)
Expand All @@ -458,7 +463,7 @@ contract Rollup is IStaking, IValidatorSelection, IRollup, RollupCore {
override(IRollup)
returns (uint256)
{
EpochRewards storage er = epochRewards[_epoch];
EpochRewards storage er = rollupStore.epochRewards[_epoch];
uint256 length = er.longestProvenLength;

if (er.subEpoch[length].hasSubmitted[_prover]) {
Expand All @@ -474,11 +479,20 @@ contract Rollup is IStaking, IValidatorSelection, IRollup, RollupCore {
override(IRollup)
returns (bool)
{
return epochRewards[_epoch].subEpoch[_length].hasSubmitted[_prover];
return rollupStore.epochRewards[_epoch].subEpoch[_length].hasSubmitted[_prover];
}

function getProvingCostPerMana() external view override(IRollup) returns (uint256) {
return provingCostPerMana;
function getProvingCostPerManaInEth() external view override(IRollup) returns (EthValue) {
return rollupStore.provingCostPerMana;
}

function getProvingCostPerManaInFeeAsset()
external
view
override(IRollup)
returns (FeeAssetValue)
{
return rollupStore.provingCostPerMana.toFeeAsset(getFeeAssetPerEth());
}

/**
Expand Down
52 changes: 28 additions & 24 deletions l1-contracts/src/core/RollupCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ import {
ValidateHeaderArgs,
Header
} from "@aztec/core/libraries/RollupLibs/ExtRollupLib.sol";
import {
EthValue,
FeeAssetValue,
FeeAssetPerEthE9,
PriceLib
} from "@aztec/core/libraries/RollupLibs/FeeMath.sol";
import {IntRollupLib} from "@aztec/core/libraries/RollupLibs/IntRollupLib.sol";
import {ProposeArgs, ProposeLib} from "@aztec/core/libraries/RollupLibs/ProposeLib.sol";
import {StakingLib} from "@aztec/core/libraries/staking/StakingLib.sol";
Expand Down Expand Up @@ -75,15 +81,15 @@ struct SubmitProofInterim {
uint256 sequencerShare;
bool isFeeCanonical;
bool isRewardDistributorCanonical;
uint256 feeAssetPrice;
FeeAssetPerEthE9 feeAssetPrice;
}

/**
* @title Rollup
* @author Aztec Labs
* @notice Rollup contract that is concerned about readability and velocity of development
* not giving a damn about gas costs.
* @dev WARNING: This contract is VERY close to the size limit (500B at time of writing).
* @dev WARNING: This contract is VERY close to the size limit
*/
contract RollupCore is
EIP712("Aztec Rollup", "1"),
Expand All @@ -97,6 +103,8 @@ contract RollupCore is
using IntRollupLib for uint256;
using IntRollupLib for ManaBaseFeeComponents;

using PriceLib for EthValue;

using TimeLib for Timestamp;
using TimeLib for Slot;
using TimeLib for Epoch;
Expand Down Expand Up @@ -134,10 +142,6 @@ contract RollupCore is
// Testing only. This should be removed eventually.
uint256 private assumeProvenThroughBlockNumber;

mapping(address => uint256) internal sequencerRewards;
mapping(Epoch => EpochRewards) internal epochRewards;
uint256 internal provingCostPerMana = 100;

constructor(
IFeeJuicePortal _fpcJuicePortal,
IRewardDistributor _rewardDistributor,
Expand Down Expand Up @@ -169,16 +173,11 @@ contract RollupCore is
rollupStore.epochProofVerifier = new MockVerifier();
rollupStore.vkTreeRoot = _vkTreeRoot;
rollupStore.protocolContractTreeRoot = _protocolContractTreeRoot;
rollupStore.provingCostPerMana = EthValue.wrap(100);

// Genesis block
rollupStore.blocks[0] = BlockLog({
feeHeader: FeeHeader({
excessMana: 0,
feeAssetPriceNumerator: 0,
manaUsed: 0,
provingCostPerManaNumerator: 0,
congestionCost: 0
}),
feeHeader: FeeHeader({excessMana: 0, feeAssetPriceNumerator: 0, manaUsed: 0, congestionCost: 0}),
archive: bytes32(Constants.GENESIS_ARCHIVE_ROOT),
blockHash: bytes32(Constants.GENESIS_BLOCK_HASH),
slotNumber: Slot.wrap(0)
Expand All @@ -190,6 +189,14 @@ contract RollupCore is
});
}

function setProvingCostPerMana(EthValue _provingCostPerMana)
external
override(IRollupCore)
onlyOwner
{
rollupStore.provingCostPerMana = _provingCostPerMana;
}

function deposit(address _attester, address _proposer, address _withdrawer, uint256 _amount)
external
override(IStakingCore)
Expand Down Expand Up @@ -359,7 +366,7 @@ contract RollupCore is
interim.prover = address(bytes20(_args.args[6] << 96)); // The address is left padded within the bytes32

interim.length = _args.end - _args.start + 1;
EpochRewards storage er = epochRewards[endEpoch];
EpochRewards storage er = rollupStore.epochRewards[endEpoch];
SubEpochRewards storage sr = er.subEpoch[interim.length];
sr.summedCount += 1;

Expand Down Expand Up @@ -390,21 +397,21 @@ contract RollupCore is
// Compute the proving fee in the fee asset
{
// @todo likely better for us to store this if we can pack it better
interim.feeAssetPrice = IntRollupLib.feeAssetPriceModifier(
interim.feeAssetPrice = IntRollupLib.getFeeAssetPerEth(
rollupStore.blocks[_args.start + i - 1].feeHeader.feeAssetPriceNumerator
);
}
interim.proverFee = Math.min(
feeHeader.manaUsed
* Math.mulDiv(provingCostPerMana, interim.feeAssetPrice, 1e9, Math.Rounding.Ceil),
* FeeAssetValue.unwrap(rollupStore.provingCostPerMana.toFeeAsset(interim.feeAssetPrice)),
interim.fee
);

interim.fee -= interim.proverFee;

er.rewards += interim.proverFee;
// The address is left padded within the bytes32
sequencerRewards[address(bytes20(_args.fees[i * 2] << 96))] +=
rollupStore.sequencerRewards[address(bytes20(_args.fees[i * 2] << 96))] +=
(interim.blockRewardSequencer + interim.fee);
}

Expand Down Expand Up @@ -545,8 +552,8 @@ contract RollupCore is
*
* @return The fee asset price
*/
function getFeeAssetPrice() public view override(IRollupCore) returns (uint256) {
return IntRollupLib.feeAssetPriceModifier(
function getFeeAssetPerEth() public view override(IRollupCore) returns (FeeAssetPerEthE9) {
return IntRollupLib.getFeeAssetPerEth(
rollupStore.blocks[rollupStore.tips.pendingBlockNumber].feeHeader.feeAssetPriceNumerator
);
}
Expand Down Expand Up @@ -588,8 +595,8 @@ contract RollupCore is
return ExtRollupLib.getManaBaseFeeComponentsAt(
rollupStore.blocks[blockOfInterest].feeHeader,
getL1FeesAt(_timestamp),
provingCostPerMana,
_inFeeAsset ? getFeeAssetPrice() : 1e9,
rollupStore.provingCostPerMana,
_inFeeAsset ? getFeeAssetPerEth() : FeeAssetPerEthE9.wrap(1e9),
TimeLib.getStorage().epochDuration
);
}
Expand Down Expand Up @@ -749,9 +756,6 @@ contract RollupCore is
_args.oracleInput.feeAssetPriceModifier
),
manaUsed: uint256(bytes32(_args.header[0x0268:0x0288])),
provingCostPerManaNumerator: parentFeeHeader.provingCostPerManaNumerator.clampedAdd(
_args.oracleInput.provingCostModifier
),
congestionCost: _congestionCost
})
});
Expand Down
14 changes: 12 additions & 2 deletions l1-contracts/src/core/interfaces/IRollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
import {
FeeHeader, L1FeeData, ManaBaseFeeComponents
} from "@aztec/core/libraries/RollupLibs/FeeMath.sol";
import {
FeeAssetPerEthE9, EthValue, FeeAssetValue
} from "@aztec/core/libraries/RollupLibs/FeeMath.sol";
import {ProposeArgs} from "@aztec/core/libraries/RollupLibs/ProposeLib.sol";
import {Timestamp, Slot, Epoch} from "@aztec/core/libraries/TimeLib.sol";

Expand Down Expand Up @@ -62,6 +65,9 @@ struct RollupStore {
bytes32 protocolContractTreeRoot;
L1GasOracleValues l1GasOracleValues;
IVerifier epochProofVerifier;
mapping(address => uint256) sequencerRewards;
mapping(Epoch => EpochRewards) epochRewards;
EthValue provingCostPerMana;
}

struct CheatDepositArgs {
Expand Down Expand Up @@ -93,6 +99,8 @@ interface IRollupCore {
function prune() external;
function updateL1GasFeeOracle() external;

function setProvingCostPerMana(EthValue _provingCostPerMana) external;

function propose(
ProposeArgs calldata _args,
Signature[] memory _signatures,
Expand All @@ -111,7 +119,7 @@ interface IRollupCore {
// solhint-disable-next-line func-name-mixedcase
function L1_BLOCK_AT_GENESIS() external view returns (uint256);

function getFeeAssetPrice() external view returns (uint256);
function getFeeAssetPerEth() external view returns (FeeAssetPerEthE9);
function getL1FeesAt(Timestamp _timestamp) external view returns (L1FeeData memory);

function canPrune() external view returns (bool);
Expand Down Expand Up @@ -183,5 +191,7 @@ interface IRollup is IRollupCore {

function getProofSubmissionWindow() external view returns (uint256);

function getProvingCostPerMana() external view returns (uint256);
function getProvingCostPerManaInEth() external view returns (EthValue);

function getProvingCostPerManaInFeeAsset() external view returns (FeeAssetValue);
}
1 change: 0 additions & 1 deletion l1-contracts/src/core/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,5 @@ library Errors {
error ProofCommitmentEscrow__WithdrawRequestNotReady(uint256 current, Timestamp readyAt); // 0xb32ab8a7

// FeeMath
error FeeMath__InvalidProvingCostModifier(); // 0x8b9d62ac
error FeeMath__InvalidFeeAssetPriceModifier(); // 0xf2fb32ad
}
13 changes: 10 additions & 3 deletions l1-contracts/src/core/libraries/RollupLibs/ExtRollupLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import {RollupStore, SubmitEpochRootProofArgs} from "@aztec/core/interfaces/IRol
import {BlockLog, RollupStore} from "@aztec/core/interfaces/IRollup.sol";
import {BlobLib} from "./BlobLib.sol";
import {EpochProofLib} from "./EpochProofLib.sol";
import {FeeMath, ManaBaseFeeComponents, FeeHeader, L1FeeData} from "./FeeMath.sol";
import {
FeeMath,
ManaBaseFeeComponents,
FeeHeader,
L1FeeData,
EthValue,
FeeAssetPerEthE9
} from "./FeeMath.sol";
import {HeaderLib, Header} from "./HeaderLib.sol";
import {ValidationLib, ValidateHeaderArgs} from "./ValidationLib.sol";
// We are using this library such that we can more easily "link" just a larger external library
Expand All @@ -31,8 +38,8 @@ library ExtRollupLib {
function getManaBaseFeeComponentsAt(
FeeHeader storage _parentFeeHeader,
L1FeeData memory _fees,
uint256 _provingCostPerMana,
uint256 _feeAssetPrice,
EthValue _provingCostPerMana,
FeeAssetPerEthE9 _feeAssetPrice,
uint256 _epochDuration
) external view returns (ManaBaseFeeComponents memory) {
return FeeMath.getManaBaseFeeComponentsAt(
Expand Down
Loading