-
Notifications
You must be signed in to change notification settings - Fork 50
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
Effective gas implementation #290
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😸
nice ^^ :D |
; get value above 256 bits | ||
${_effGasPriceShifted >> 256} => D | ||
; compute ARITH | ||
${_effGasPriceShifted} => E :ARITH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have out of arith counters check for this code?
(or any other counters (steps, binary?) given that this adds quite a bit of computation)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree we should add an arith checker at beginning of process-tx.zkasm
${_effGasPriceShifted / 256} => A :MSTORE(txGasPrice) | ||
${_effGasPriceShifted % 256} => C | ||
; compute ARITH | ||
E :ARITH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I still don't quite understand how this works, so correct where if I'm wrong.
I believe the purpose of this ARITH is to contstrain the free calculations above (_effGasPriceShifted / 256
and _effGasPriceShifted % 256
)
This ARITH
line calculates AB + C
and updates E
and D
.
What would stop malicious prover to return arbitrary value into A
instead of _effGasPriceShifted / 256
? This ARITH doesn't seem to constrain neither of registers values (unlike the first ARITH above?)
(for C
it is more clear, it is at least checked for <256 afterwards)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I think I understand now: it takes into account previous values of E and D and checks result of ARITH against them, because this expression doesn't have an assignment to register.
main/process-tx.zkasm
Outdated
@@ -68,9 +70,34 @@ endCheckChainId: | |||
:CALL(isColdAddress) ; add tx.origin to touched addresses | |||
0 :MSTORE(depth) ; Initial depth is 0 | |||
|
|||
;; Set gasPrice global var | |||
;; Set gasPrice global var depending on effectivePercentage [0-255] -> txGasPrice = Floor((gasPrice * (effectivePercentage + 1)) / 256) | |||
; _effGasPriceShifted = gasPrice * (effectivePercentage + 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cosmetic: this comment is duplicated on line 83, maybe it's not needed here
main/process-tx.zkasm
Outdated
;; Set gasPrice global var | ||
;; Set gasPrice global var depending on effectivePercentage [0-255] -> txGasPrice = Floor((gasPrice * (effectivePercentage + 1)) / 256) | ||
; _effGasPriceShifted = gasPrice * (effectivePercentage + 1) | ||
; A => gasPrice |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cosmetic: notation with =>
is confusing here, because meaning is opposite of zkasm syntax
; A => gasPrice | |
; A = gasPrice |
main/process-tx.zkasm
Outdated
$ => A :MLOAD(txGasPriceRLP) | ||
A :MSTORE(txGasPrice) | ||
; B => effectivePercentage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
; B => effectivePercentage | |
; B = effectivePercentage |
main/process-tx.zkasm
Outdated
A :MSTORE(txGasPrice) | ||
; B => effectivePercentage | ||
$ => B :MLOAD(effectivePercentageRLP) | ||
; B => [0, 255] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cosmetic: if the comment supposed to explain the effect of the following line
; B => [0, 255] | |
; B = [1, 256] |
d09f1c5
to
33034b9
Compare
33034b9
to
ac51215
Compare
@@ -285,6 +285,11 @@ vREADTx: | |||
A :MSTORE(txV) | |||
C + D => C :CALL(addBatchHashData) | |||
|
|||
;; read effective percentage | |||
effectivePercentageTx: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This label is never called. Is this just a documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it is there for clarity
@@ -285,6 +285,11 @@ vREADTx: | |||
A :MSTORE(txV) | |||
C + D => C :CALL(addBatchHashData) | |||
|
|||
;; read effective percentage | |||
effectivePercentageTx: | |||
1 => D :CALL(getTxBytes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description of getTxBytes
does not say what C
is used for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C
description is at the very beginning of the rlp-processing: https://github.com/0xPolygonHermez/zkevm-rom/blob/main/main/load-tx-rlp.zkasm#L28
; compute ARITH | ||
E :ARITH | ||
; check divisor > remainder | ||
C => A |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To confirm: LT
treats arguments as unsigned. I.e. this will work in case C
is "negative".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the usage of LT
covered by CNT_BINARY - 100
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LT uses 1 binary, so yes.
LT treats arguments as unsigned, it compares two 256 bit scalars. To treat them as signed, we also have the registry SLT
.
In case C
is "negative" it will be treated as a Scalar
Effective gas price implementation.
In order to be more precise with gasPrice and low tx fees, the sequencer is able to propose a reduction of the signed gasPrice. This param,
effectiveGasPrice
, is passed at the last bytes of the encoded tx and present in thebatchL2Data
. The finaleffectiveGasPrice
is compute as:effectiveGasPrice = floor((gasPrice * (effectivePercentage + 1)) / 256)
txGasPrice
is replaced byeffectiveGasPrice
among tx processing