Skip to content
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

EstimateGas to handle private transaction gas cost differences #644

Merged
merged 2 commits into from Mar 12, 2019
Merged

EstimateGas to handle private transaction gas cost differences #644

merged 2 commits into from Mar 12, 2019

Conversation

prd-fox
Copy link
Contributor

@prd-fox prd-fox commented Feb 21, 2019

Compare intrinsic gas of public transaction versus the private version that contains the PTM hash instead. If there is a difference, add it on to the execution cost.

Consider the SimpleStorage contract:

pragma solidity ^0.5.0;

contract SimpleStorage {
    uint private storedData;

    constructor(uint initVal) public {
        storedData = initVal;
    }

    function set(uint x) public {
        storedData = x;
    }

    function get() public view returns (uint retVal) {
        return storedData;
    }
}

Calling the set function with the value 1989 produces the data field 60fe47b100000000000000000000000000000000000000000000000000000000000007c5.

This is 36 bytes long, and consists of a lot of 0's (which have a lower gas cost). The intrinsic gas value of the transaction is 21528.

If this were to be sent as a private transaction, this data field would be replaced by the hash the Private Transaction Manager produces, which is 64 bytes long, potentially with no 0's. Assuming the worst case hash with no 0's, the intrinsic gas cost of the transaction becomes 25352.

If we were to use the original gas estimate and send it as a private transaction, it would fail with a not enough gas error.

Since the execution cost of the transaction would not change whether it becomes a public or private transaction, the only difference in gas required comes from the intrinsic gas cost.

This PR adds on the difference between the intrinsic gas costs if the private cost is higher than the public cost. This changes the semantics of the call somewhat from "this is the exact gas cost right now" to "this is the maximum gas cost right now".

that contains the PTM hash instead. If there is a difference, add it on
to the execution cost.
@prd-fox prd-fox changed the title Compare intrinsic gas of public transaction versus the private version EstimateGas to handle private transaction gas cost differences Feb 21, 2019
@jpmsam jpmsam merged commit 2735367 into Consensys:master Mar 12, 2019
@prd-fox prd-fox deleted the estimategas-for-privatetransaction branch March 12, 2019 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants