mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add another argument to setimmutable and the AssignImmutable opcode, allowing to modify code at any memory offset.
This commit is contained in:
@@ -91,7 +91,7 @@ BOOST_AUTO_TEST_CASE(all_assembly_items)
|
||||
// PushDeployTimeAddress
|
||||
_assembly.append(PushDeployTimeAddress);
|
||||
// AssignImmutable.
|
||||
// Note that since there is no reference to "someOtherImmutable", this will compile to a simple POP in the hex output.
|
||||
// Note that since there is no reference to "someOtherImmutable", this will just compile to two POPs in the hex output.
|
||||
_assembly.appendImmutableAssignment("someOtherImmutable");
|
||||
_assembly.append(u256(2));
|
||||
_assembly.appendImmutableAssignment("someImmutable");
|
||||
@@ -104,9 +104,9 @@ BOOST_AUTO_TEST_CASE(all_assembly_items)
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
_assembly.assemble().toHex(),
|
||||
"5b6001600220606f73__$bf005014d9d0f534b8fcb268bd84c491a2$__"
|
||||
"60005660676022604573000000000000000000000000000000000000000050"
|
||||
"60028060015250"
|
||||
"5b6001600220607373__$bf005014d9d0f534b8fcb268bd84c491a2$__"
|
||||
"600056606b602260497300000000000000000000000000000000000000005050"
|
||||
"60028181600101525050"
|
||||
"00fe"
|
||||
"7f0000000000000000000000000000000000000000000000000000000000000000"
|
||||
"fe010203044266eeaa"
|
||||
@@ -184,8 +184,10 @@ BOOST_AUTO_TEST_CASE(immutable)
|
||||
shared_ptr<Assembly> _subAsmPtr = make_shared<Assembly>(_subAsm);
|
||||
|
||||
_assembly.append(u256(42));
|
||||
_assembly.append(u256(0));
|
||||
_assembly.appendImmutableAssignment("someImmutable");
|
||||
_assembly.append(u256(23));
|
||||
_assembly.append(u256(0));
|
||||
_assembly.appendImmutableAssignment("someOtherImmutable");
|
||||
|
||||
auto sub = _assembly.appendSubroutine(_subAsmPtr);
|
||||
@@ -198,21 +200,26 @@ BOOST_AUTO_TEST_CASE(immutable)
|
||||
// root.asm
|
||||
// assign "someImmutable"
|
||||
"602a" // PUSH1 42 - value for someImmutable
|
||||
"80" // DUP1
|
||||
"6000" // PUSH1 0 - offset of code into which to insert the immutable
|
||||
"8181" // DUP2 DUP2
|
||||
"6001" // PUSH1 1 - offset of first someImmutable in sub_0
|
||||
"01" // ADD - add offset of immutable to offset of code
|
||||
"52" // MSTORE
|
||||
"80" // DUP1
|
||||
"8181" // DUP2 DUP2
|
||||
"6043" // PUSH1 67 - offset of second someImmutable in sub_0
|
||||
"01" // ADD - add offset of immutable to offset of code
|
||||
"52" // MSTORE
|
||||
"50" // POP
|
||||
"5050" // POP POP
|
||||
// assign "someOtherImmutable"
|
||||
"6017" // PUSH1 23 - value for someOtherImmutable
|
||||
"80" // DUP1
|
||||
"6000" // PUSH1 0 - offset of code into which to insert the immutable
|
||||
"8181" // DUP2 DUP2
|
||||
"6022" // PUSH1 34 - offset of someOtherImmutable in sub_0
|
||||
"01" // ADD - add offset of immutable to offset of code
|
||||
"52" // MSTORE
|
||||
"50" // POP
|
||||
"5050" // POP POP
|
||||
"6063" // PUSH1 0x63 - dataSize(sub_0)
|
||||
"6017" // PUSH1 0x17 - dataOffset(sub_0)
|
||||
"6023" // PUSH1 0x23 - dataOffset(sub_0)
|
||||
"fe" // INVALID
|
||||
// end of root.asm
|
||||
// sub.asm
|
||||
@@ -224,8 +231,10 @@ BOOST_AUTO_TEST_CASE(immutable)
|
||||
_assembly.assemblyString(),
|
||||
" /* \"root.asm\":1:3 */\n"
|
||||
" 0x2a\n"
|
||||
" 0x00\n"
|
||||
" assignImmutable(\"0x26f2c0195e9d408feff3abd77d83f2971f3c9a18d1e8a9437c7835ae4211fc9f\")\n"
|
||||
" 0x17\n"
|
||||
" 0x00\n"
|
||||
" assignImmutable(\"0xc3978657661c4d8e32e3d5f42597c009f0d3859e9f9d0d94325268f9799e2bfb\")\n"
|
||||
" dataSize(sub_0)\n"
|
||||
" dataOffset(sub_0)\n"
|
||||
@@ -242,8 +251,10 @@ BOOST_AUTO_TEST_CASE(immutable)
|
||||
util::jsonCompactPrint(_assembly.assemblyJSON(indices)),
|
||||
"{\".code\":["
|
||||
"{\"begin\":1,\"end\":3,\"name\":\"PUSH\",\"source\":0,\"value\":\"2A\"},"
|
||||
"{\"begin\":1,\"end\":3,\"name\":\"PUSH\",\"source\":0,\"value\":\"0\"},"
|
||||
"{\"begin\":1,\"end\":3,\"name\":\"ASSIGNIMMUTABLE\",\"source\":0,\"value\":\"someImmutable\"},"
|
||||
"{\"begin\":1,\"end\":3,\"name\":\"PUSH\",\"source\":0,\"value\":\"17\"},"
|
||||
"{\"begin\":1,\"end\":3,\"name\":\"PUSH\",\"source\":0,\"value\":\"0\"},"
|
||||
"{\"begin\":1,\"end\":3,\"name\":\"ASSIGNIMMUTABLE\",\"source\":0,\"value\":\"someOtherImmutable\"},"
|
||||
"{\"begin\":1,\"end\":3,\"name\":\"PUSH #[$]\",\"source\":0,\"value\":\"0000000000000000000000000000000000000000000000000000000000000000\"},"
|
||||
"{\"begin\":1,\"end\":3,\"name\":\"PUSH [$]\",\"source\":0,\"value\":\"0000000000000000000000000000000000000000000000000000000000000000\"}"
|
||||
|
||||
Reference in New Issue
Block a user