[ewasm] Properly touch memory in EwasmInterpreter

This commit is contained in:
Alex Beregszaszi 2020-10-27 20:11:03 +00:00
parent 9dc5ceae94
commit 6b2942e7f0

View File

@ -298,9 +298,7 @@ u256 EwasmBuiltinInterpreter::evalEthBuiltin(string const& _fun, vector<uint64_t
} }
else if (_fun == "getExternalBalance") else if (_fun == "getExternalBalance")
{ {
// TODO this does not read the address, but is consistent with readAddress(arg[0]);
// EVM interpreter implementation.
// If we take the address into account, this needs to use readAddress.
writeU128(arg[1], m_state.balance); writeU128(arg[1], m_state.balance);
return 0; return 0;
} }
@ -316,8 +314,9 @@ u256 EwasmBuiltinInterpreter::evalEthBuiltin(string const& _fun, vector<uint64_t
} }
else if (_fun == "call") else if (_fun == "call")
{ {
// TODO read args from memory readAddress(arg[1]);
// TODO use readAddress to read address. readU128(arg[2]);
accessMemory(arg[3], arg[4]);
logTrace(evmasm::Instruction::CALL, {}); logTrace(evmasm::Instruction::CALL, {});
return arg[0] & 1; return arg[0] & 1;
} }
@ -336,22 +335,23 @@ u256 EwasmBuiltinInterpreter::evalEthBuiltin(string const& _fun, vector<uint64_t
return m_state.calldata.size(); return m_state.calldata.size();
else if (_fun == "callCode") else if (_fun == "callCode")
{ {
// TODO read args from memory readAddress(arg[1]);
// TODO use readAddress to read address. readU128(arg[2]);
accessMemory(arg[3], arg[4]);
logTrace(evmasm::Instruction::CALLCODE, {}); logTrace(evmasm::Instruction::CALLCODE, {});
return arg[0] & 1; return arg[0] & 1;
} }
else if (_fun == "callDelegate") else if (_fun == "callDelegate")
{ {
// TODO read args from memory readAddress(arg[1]);
// TODO use readAddress to read address. accessMemory(arg[2], arg[3]);
logTrace(evmasm::Instruction::DELEGATECALL, {}); logTrace(evmasm::Instruction::DELEGATECALL, {});
return arg[0] & 1; return arg[0] & 1;
} }
else if (_fun == "callStatic") else if (_fun == "callStatic")
{ {
// TODO read args from memory readAddress(arg[1]);
// TODO use readAddress to read address. accessMemory(arg[2], arg[3]);
logTrace(evmasm::Instruction::STATICCALL, {}); logTrace(evmasm::Instruction::STATICCALL, {});
return arg[0] & 1; return arg[0] & 1;
} }
@ -393,8 +393,8 @@ u256 EwasmBuiltinInterpreter::evalEthBuiltin(string const& _fun, vector<uint64_t
} }
else if (_fun == "create") else if (_fun == "create")
{ {
// TODO access memory readU128(arg[0]);
// TODO use writeAddress to store resulting address accessMemory(arg[1], arg[2]);
logTrace(evmasm::Instruction::CREATE, {}); logTrace(evmasm::Instruction::CREATE, {});
writeAddress(arg[3], h160(h256(0xcccccc + arg[1]))); writeAddress(arg[3], h160(h256(0xcccccc + arg[1])));
return 1; return 1;
@ -406,7 +406,7 @@ u256 EwasmBuiltinInterpreter::evalEthBuiltin(string const& _fun, vector<uint64_t
} }
else if (_fun == "externalCodeCopy") else if (_fun == "externalCodeCopy")
{ {
// TODO use readAddress to read address. readAddress(arg[0]);
if (accessMemory(arg[1], arg[3])) if (accessMemory(arg[1], arg[3]))
// TODO this way extcodecopy and codecopy do the same thing. // TODO this way extcodecopy and codecopy do the same thing.
copyZeroExtended( copyZeroExtended(
@ -429,9 +429,18 @@ u256 EwasmBuiltinInterpreter::evalEthBuiltin(string const& _fun, vector<uint64_t
} }
else if (_fun == "log") else if (_fun == "log")
{ {
accessMemory(arg[0], arg[1]);
uint64_t numberOfTopics = arg[2]; uint64_t numberOfTopics = arg[2];
if (numberOfTopics > 4) if (numberOfTopics > 4)
throw ExplicitlyTerminated(); throw ExplicitlyTerminated();
if (numberOfTopics > 0)
readBytes32(arg[3]);
if (numberOfTopics > 1)
readBytes32(arg[4]);
if (numberOfTopics > 2)
readBytes32(arg[5]);
if (numberOfTopics > 3)
readBytes32(arg[6]);
logTrace(evmasm::logInstruction(numberOfTopics), {}); logTrace(evmasm::logInstruction(numberOfTopics), {});
return 0; return 0;
} }
@ -473,7 +482,7 @@ u256 EwasmBuiltinInterpreter::evalEthBuiltin(string const& _fun, vector<uint64_t
} }
else if (_fun == "selfDestruct") else if (_fun == "selfDestruct")
{ {
// TODO use readAddress to read address. readAddress(arg[0]);
logTrace(evmasm::Instruction::SELFDESTRUCT, {}); logTrace(evmasm::Instruction::SELFDESTRUCT, {});
throw ExplicitlyTerminated(); throw ExplicitlyTerminated();
} }