-
Notifications
You must be signed in to change notification settings - Fork 2.2k
EIP211: RETURNDATA #4062
EIP211: RETURNDATA #4062
Changes from all commits
3fae652
ec797dd
ce59f0c
f07808e
798322d
d30ddfb
3ee15d0
05e438e
861a9ea
e18d839
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,14 +120,21 @@ void VM::caseCreate() | |
uint64_t initOff = (uint64_t)m_SP[1]; | ||
uint64_t initSize = (uint64_t)m_SP[2]; | ||
|
||
// Clear the return data buffer. This will not free the memory. | ||
m_returnData.clear(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the contract initialization executes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See the last sentence on this line: https://github.com/ethereum/EIPs/pull/211/files#diff-fd8c393953fe66162d8bb518d87bfb57R32 (That's something I learned while doing YP.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implemented. |
||
if (m_ext->balance(m_ext->myAddress) >= endowment && m_ext->depth < 1024) | ||
{ | ||
*m_io_gas_p = m_io_gas; | ||
u256 createGas = *m_io_gas_p; | ||
if (!m_schedule->staticCallDepthLimit()) | ||
createGas -= createGas / 64; | ||
u256 gas = createGas; | ||
m_SPP[0] = (u160)m_ext->create(endowment, gas, bytesConstRef(m_mem.data() + initOff, initSize), m_onOp); | ||
h160 addr; | ||
owning_bytes_ref output; | ||
std::tie(addr, output) = m_ext->create(endowment, gas, bytesConstRef(m_mem.data() + initOff, initSize), m_onOp); | ||
m_SPP[0] = (u160)addr; | ||
m_returnData = output.toBytes(); | ||
*m_io_gas_p -= (createGas - gas); | ||
m_io_gas = uint64_t(*m_io_gas_p); | ||
} | ||
|
@@ -139,14 +146,31 @@ void VM::caseCreate() | |
void VM::caseCall() | ||
{ | ||
m_bounce = &VM::interpretCases; | ||
|
||
// TODO: Please check if that does not actually increases the stack size. | ||
// That was the case before. | ||
unique_ptr<CallParameters> callParams(new CallParameters()); | ||
|
||
// Clear the return data buffer. This will not free the memory. | ||
m_returnData.clear(); | ||
|
||
bytesRef output; | ||
if (caseCallSetup(callParams.get(), output)) | ||
{ | ||
std::pair<bool, owning_bytes_ref> callResult = m_ext->call(*callParams); | ||
callResult.second.copyTo(output); | ||
|
||
m_SPP[0] = callResult.first ? 1 : 0; | ||
bool success = false; | ||
owning_bytes_ref outputRef; | ||
std::tie(success, outputRef) = m_ext->call(*callParams); | ||
outputRef.copyTo(output); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Am I mistaken that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, it's the caller's memory! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Magic. The |
||
|
||
// Here we have 2 options: | ||
// 1. Keep the whole returned memory buffer (owning_bytes_ref): | ||
// higher memory footprint, no memory copy. | ||
// 2. Copy only the return data from the returned memory buffer: | ||
// minimal memory footprint, additional memory copy. | ||
// Option 2 used: | ||
m_returnData = outputRef.toBytes(); | ||
|
||
m_SPP[0] = success ? 1 : 0; | ||
} | ||
else | ||
m_SPP[0] = 0; | ||
|
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.
Not strictly connected to this PR, but probably it would be better to have the offset + size as explicit parameters in
copyDataToMemory
.