Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Fix STATICCALL #4200

Merged
merged 7 commits into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions libevm/VMCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,25 @@ void VM::caseCall()

bool VM::caseCallSetup(CallParameters *callParams, bytesRef& o_output)
{
// Make sure the params were properly initialized.
assert(callParams->valueTransfer == 0);
assert(callParams->apparentValue == 0);

m_runGas = toInt63(m_schedule->callGas);

callParams->staticCall = (m_OP == Instruction::STATICCALL || m_ext->staticCall);

bool const haveValueArg = m_OP == Instruction::CALL || m_OP == Instruction::CALLCODE;

Address destinationAddr = asAddress(m_SP[1]);
if (m_OP == Instruction::CALL && !m_ext->exists(destinationAddr))
if (m_SP[2] > 0 || m_schedule->zeroValueTransferChargesNewAccountGas())
m_runGas += toInt63(m_schedule->callNewAccountGas);

if ((m_OP == Instruction::CALL || m_OP == Instruction::CALLCODE) && m_SP[2] > 0)
if (haveValueArg && m_SP[2] > 0)
m_runGas += toInt63(m_schedule->callValueTransferGas);

size_t sizesOffset = (m_OP == Instruction::DELEGATECALL || m_OP == Instruction::STATICCALL) ? 2 : 3;
size_t const sizesOffset = haveValueArg ? 3 : 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you forget a ! here or was there a bug before?

Copy link
Member Author

Choose a reason for hiding this comment

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

I also swapped the 2 and 3.

u256 inputOffset = m_SP[sizesOffset];
u256 inputSize = m_SP[sizesOffset + 1];
u256 outputOffset = m_SP[sizesOffset + 2];
Expand Down Expand Up @@ -248,27 +254,24 @@ bool VM::caseCallSetup(CallParameters *callParams, bytesRef& o_output)
ON_OP();
updateIOGas();

if (m_OP != Instruction::DELEGATECALL && m_SP[2] > 0)
if (haveValueArg && m_SP[2] > 0)
callParams->gas += m_schedule->callStipend;

callParams->codeAddress = destinationAddr;

unsigned inOutOffset = 0;
if (m_OP == Instruction::DELEGATECALL || m_OP == Instruction::STATICCALL)
{
callParams->apparentValue = m_ext->value;
callParams->valueTransfer = 0;
}
else
if (haveValueArg)
{
callParams->apparentValue = callParams->valueTransfer = m_SP[2];
inOutOffset = 1;
callParams->valueTransfer = m_SP[2];
callParams->apparentValue = m_SP[2];
}
else if (m_OP == Instruction::DELEGATECALL)
// Forward VALUE.
callParams->apparentValue = m_ext->value;

uint64_t inOff = (uint64_t)m_SP[inOutOffset + 2];
uint64_t inSize = (uint64_t)m_SP[inOutOffset + 3];
uint64_t outOff = (uint64_t)m_SP[inOutOffset + 4];
uint64_t outSize = (uint64_t)m_SP[inOutOffset + 5];
uint64_t inOff = (uint64_t)inputOffset;
uint64_t inSize = (uint64_t)inputSize;
uint64_t outOff = (uint64_t)outputOffset;
uint64_t outSize = (uint64_t)outputSize;

if (m_ext->balance(m_ext->myAddress) >= callParams->valueTransfer && m_ext->depth < 1024)
{
Expand All @@ -279,7 +282,6 @@ bool VM::caseCallSetup(CallParameters *callParams, bytesRef& o_output)
o_output = bytesRef(m_mem.data() + outOff, outSize);
return true;
}
else
return false;
return false;
}

2 changes: 1 addition & 1 deletion test/jsontests
Submodule jsontests updated 101 files