Consensys / web3js-eea

EEA JavaScript libraries.
Mozilla Public License 2.0
35 stars 40 forks source link

Fix the gas limit of privacy marker transaction #66

Closed MadelineMurray closed 4 years ago

MadelineMurray commented 4 years ago

The public transaction gas usage is calculated in the following way:

Gas usage = TX_BASE_COST + (TX_DATA_ZERO NO_OF_ZEROS) + (TX_DATA_NON_ZERO NO_OF_NON_ZEROS)

where,

TX_BASE_COST = 21000 TX_DATA_ZERO = 4 NO_OF_ZEROS = number of "00" in the hex payload of the transaction TX_DATA_NON_ZERO = 68 pre-istanbul / 16 post-istanbul (as in istanbul hard fork) NO_OF_NON_ZEROS = number of non-"00" in the hex payload of the transaction i.e. number of pairs in the hex that are not "00"

The PMT has 32 bytes of non-zero hex. It therefore consumes:

Gas usage of PMT = 21000 + (4 0) + (68 32) = 21000 + 2176 = 23176

Post-Instanbul the PMT will consume:

Gas usage of PMT post-istanbul = 21000 + (4 0) + (16 32) = 21000 + 512 = 21512

Invoking the Privacy Precompiled Contract consumes 0 gas.

More info: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2028.md

Comments from the original JI https://jira.hyperledger.org/browse/BESU-75:

Madeline Murray - Need to confirm where the extra 2992 is coming from

Madeline Murray - Document where extra gas is coming from.

Also update in Besu and web3js, and web3j

Ivaylo Kirilov September 16, 20the changes required in Besu are documentation related only

Ivaylo Kirilov September 17, 2019, 12:14 AM

fixed in web3j - web3j/web3j#1029

MadelineMurray commented 4 years ago

Investigate and confirm if changes still needed here.

MadelineMurray commented 4 years ago

Is this change also needed in web3js-eea? Or has it been addressed somewhere along the way?