Add another argument to setimmutable and the AssignImmutable opcode, allowing to modify code at any memory offset.

This commit is contained in:
Daniel Kirchner
2020-10-15 18:14:41 +02:00
parent 00fb152316
commit 0dca223b45
12 changed files with 58 additions and 32 deletions
+4 -1
View File
@@ -674,15 +674,18 @@ LinkerObject const& Assembly::assemble() const
case AssignImmutable:
for (auto const& offset: immutableReferencesBySub[i.data()].second)
{
ret.bytecode.push_back(uint8_t(Instruction::DUP1));
ret.bytecode.push_back(uint8_t(Instruction::DUP2));
ret.bytecode.push_back(uint8_t(Instruction::DUP2));
// TODO: should we make use of the constant optimizer methods for pushing the offsets?
bytes offsetBytes = toCompactBigEndian(u256(offset));
ret.bytecode.push_back(uint8_t(Instruction::PUSH1) - 1 + offsetBytes.size());
ret.bytecode += offsetBytes;
ret.bytecode.push_back(uint8_t(Instruction::ADD));
ret.bytecode.push_back(uint8_t(Instruction::MSTORE));
}
immutableReferencesBySub.erase(i.data());
ret.bytecode.push_back(uint8_t(Instruction::POP));
ret.bytecode.push_back(uint8_t(Instruction::POP));
break;
case PushDeployTimeAddress:
ret.bytecode.push_back(uint8_t(Instruction::PUSH20));