Skip to content

Send all gas on byzantium#3599

Merged
chriseth merged 1 commit intodevelopfrom
sendAllGasOnByzantium
Mar 5, 2018
Merged

Send all gas on byzantium#3599
chriseth merged 1 commit intodevelopfrom
sendAllGasOnByzantium

Conversation

@chriseth
Copy link
Contributor

Depends on #3569

m_context << dupInstruction(m_context.baseToCurrentStackOffset(gasStackPos));
else if (m_context.experimentalFeatureActive(ExperimentalFeature::V050))
else if (m_context.evmVersion().canOverchargeGasForCall())
// Send all gas (requires tangerine whistle EVM)
Copy link
Contributor

@axic axic Feb 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about actually adding tanginewhistle as a level? Should be pretty straightfoward, one place to change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do that. It was between homestead and byzantium, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I'll also add spurious dragon.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could be used for the code size limit and the exp repricing check if we implement it.

@axic
Copy link
Contributor

axic commented Feb 26, 2018

The send-all-gas change looks good.

@chriseth chriseth force-pushed the sendAllGasOnByzantium branch 2 times, most recently from d8fe874 to 9e4a911 Compare March 2, 2018 11:26
m_context << u256(retSize) << Instruction::ADD << Instruction::MSTORE;
// Touch the end of the output area so that we do not pay for memory resize during the call
// (which we would have to subtract from the gas left)
// We could also just use MLOAD; POP right before the gas calculation, but the optimizer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even this comment is outdated at this point, since mload was changed in the optimiser :)

// We could also just use MLOAD; POP right before the gas calculation, but the optimizer
// would remove that, so we use MSTORE here.
if (!_functionType.gasSet() && retSize > 0)
if (!m_context.evmVersion().canOverchargeGasForCall())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this code piece may still be useful if there is out of gas condition, it stops at memory expansion and not at the time of the return of the call (it is an edge case though).

Also not sure this doesn't depend on hasReturndata the option?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure I understand. The problem is that the CALL opcode performs memory expansion for the return area. If I remember correctly, the CALL opcode first performs memory expansion to accomodate both the argument and the return data memory area. After that, pre-tangerine-whistle VMs would check if there is still enough gas left to send the specified amount with the call. Post-tangerine-whistle VMs would not fail if this check is negative, but just send as much gas as is still left.

"it stops .. not at the time of the return of the call" - as far as I know, this can never happen, since the memory is expanded before the call is performed. Moving this to after the call was one of the early suggestions as part of EIP5.

This should be unrelated to hasReturndata.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to check this again also discussed with @chfast. Apparently memory expansion happens before the call and the remainder gas is taken as you've said. My comment is invalid then.

Also not including this code should make no difference in behaviour but should save gas by not doing it manually.

@chriseth chriseth force-pushed the sendAllGasOnByzantium branch from 9e4a911 to e472893 Compare March 5, 2018 11:16
@chriseth
Copy link
Contributor Author

chriseth commented Mar 5, 2018

Changed the backticks.

@axic
Copy link
Contributor

axic commented Mar 5, 2018

Tests fail on gas disagreement:

/home/travis/build/ethereum/solidity/test/libsolidity/GasMeter.cpp(99): error in "function_calls": check gas.value == m_gasUsed failed [41801 != 41991]
/home/travis/build/ethereum/solidity/test/libsolidity/GasMeter.cpp(99): error in "multiple_external_functions": check gas.value == m_gasUsed failed [41801 != 41991]
/home/travis/build/ethereum/solidity/test/libsolidity/GasMeter.cpp(99): error in "multiple_external_functions": check gas.value == m_gasUsed failed [21769 != 21919]
/home/travis/build/ethereum/solidity/test/libsolidity/GasMeter.cpp(99): error in "exponent_size": check gas.value == m_gasUsed failed [21752 != 21832]
/home/travis/build/ethereum/solidity/test/libsolidity/GasMeter.cpp(99): error in "exponent_size": check gas.value == m_gasUsed failed [21740 != 21860]
/home/travis/build/ethereum/solidity/test/libsolidity/GasMeter.cpp(99): error in "balance_gas": check gas.value == m_gasUsed failed [21729 != 22109]
/home/travis/build/ethereum/solidity/test/libsolidity/GasMeter.cpp(99): error in "extcodesize_gas": check gas.value == m_gasUsed failed [21486 != 22166]

@chriseth
Copy link
Contributor Author

chriseth commented Mar 5, 2018

@axic I think this is an error in travis, because it is not present in circle

@chriseth chriseth force-pushed the sendAllGasOnByzantium branch from e472893 to 83fcf00 Compare March 5, 2018 18:32
@chriseth
Copy link
Contributor Author

chriseth commented Mar 5, 2018

The error is already in develop, not in this branch. I think it came with "evmVersion".

@chriseth chriseth merged commit be797cb into develop Mar 5, 2018
@axic axic deleted the sendAllGasOnByzantium branch March 5, 2018 20:22
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

Comments