Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
bc6756c5
Unverified
Commit
bc6756c5
authored
Oct 05, 2021
by
Maurelian
Committed by
Kelvin Fichter
Nov 10, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore(contracts): Improve the comment explaining the gas burn calculation
parent
3799b760
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
5 deletions
+12
-5
CanonicalTransactionChain.sol
...ntracts/contracts/L1/rollup/CanonicalTransactionChain.sol
+12
-5
No files found.
packages/contracts/contracts/L1/rollup/CanonicalTransactionChain.sol
View file @
bc6756c5
...
@@ -111,6 +111,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
...
@@ -111,6 +111,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
onlyBurnAdmin
onlyBurnAdmin
{
{
enqueueGasCost = _enqueueGasCost;
enqueueGasCost = _enqueueGasCost;
// See the comment in enqueue() for the rationale behind this formula.
enqueueL2GasPrepaid = l2GasDiscountDivisor * _enqueueGasCost;
enqueueL2GasPrepaid = l2GasDiscountDivisor * _enqueueGasCost;
emit L2GasParamsUpdated(
emit L2GasParamsUpdated(
...
@@ -130,6 +131,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
...
@@ -130,6 +131,7 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
onlyBurnAdmin
onlyBurnAdmin
{
{
l2GasDiscountDivisor = _l2GasDiscountDivisor;
l2GasDiscountDivisor = _l2GasDiscountDivisor;
// See the comment in enqueue() for the rationale behind this formula.
enqueueL2GasPrepaid = _l2GasDiscountDivisor * enqueueGasCost;
enqueueL2GasPrepaid = _l2GasDiscountDivisor * enqueueGasCost;
emit L2GasParamsUpdated(
emit L2GasParamsUpdated(
...
@@ -324,11 +326,16 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
...
@@ -324,11 +326,16 @@ contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressRes
// Transactions submitted to the queue lack a method for paying gas fees to the Sequencer.
// Transactions submitted to the queue lack a method for paying gas fees to the Sequencer.
// So we need to prevent spam attacks by ensuring that the cost of enqueueing a transaction
// So we need to prevent spam attacks by ensuring that the cost of enqueueing a transaction
// from L1 to L2 is not underpriced. Therefore, we define 'enqueueL2GasPrepaid' as a
// from L1 to L2 is not underpriced. For transaction with a high L2 gas limit, we do this by
// threshold. If the _gasLimit for the enqueued transaction is above this threshold, then we
// burning some extra gas on L1. Of course there is also some intrinsic cost to enqueueing a
// 'charge' to user by burning additional L1 gas. Since gas is cheaper on L2 than L1, we
// transaction, so we want to make sure not to over-charge (by burning too much L1 gas).
// only need to burn a fraction of the provided L1 gas, which is determined by the
// Therefore, we define 'enqueueL2GasPrepaid' as the L2 gas limit above which we must burn
// l2GasDiscountDivisor.
// additional gas on L1. This threshold is the product of two inputs:
// 1. enqueueGasCost: the base cost of calling this function.
// 2. l2GasDiscountDivisor: the ratio between the cost of gas on L1 and L2. This is a
// positive integer, meaning we assume L2 gas is always less costly.
// The calculation below for gasToConsume can be seen as converting the difference (between
// the specified L2 gas limit and the prepaid L2 gas limit) to an L1 gas amount.
if(_gasLimit > enqueueL2GasPrepaid) {
if(_gasLimit > enqueueL2GasPrepaid) {
uint256 gasToConsume = (_gasLimit - enqueueL2GasPrepaid) / l2GasDiscountDivisor;
uint256 gasToConsume = (_gasLimit - enqueueL2GasPrepaid) / l2GasDiscountDivisor;
uint256 startingGas = gasleft();
uint256 startingGas = gasleft();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment