Skip to content

Commit fc9c06d

Browse files
authored
fix: don't add PUSH1-data during contract deployment (ethereum#91)
* fix: don't add PUSH1-data during contract deployment * remove import cycle in tests (ethereum#92)
1 parent 64ec2e8 commit fc9c06d

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

core/vm/instructions.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,11 @@ func opPush1(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]by
934934
copy(value[1:], scope.Contract.Code[chunk*31:endMin])
935935
index := trieUtils.GetTreeKeyCodeChunk(scope.Contract.Address().Bytes(), uint256.NewInt(chunk))
936936
statelessGas := interpreter.evm.Accesses.TouchAddressOnReadAndComputeGas(index)
937-
interpreter.evm.Accesses.SetLeafValue(index, value[:])
937+
if scope.Contract.IsDeployment {
938+
interpreter.evm.Accesses.SetLeafValue(index, nil)
939+
} else {
940+
interpreter.evm.Accesses.SetLeafValue(index, value[:])
941+
}
938942
scope.Contract.UseGas(statelessGas)
939943
}
940944
} else {

trie/verkle.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,13 @@ func deserializeVerkleProof(serialized []byte) (*verkle.Proof, []*verkle.Point,
307307

308308
// Copy the values here so as to avoid an import cycle
309309
const (
310-
PUSH1 = 0x60
311-
PUSH32 = 0x7f
310+
PUSH1 = byte(0x60)
311+
PUSH3 = byte(0x62)
312+
PUSH4 = byte(0x63)
313+
PUSH7 = byte(0x66)
314+
PUSH21 = byte(0x74)
315+
PUSH30 = byte(0x7d)
316+
PUSH32 = byte(0x7f)
312317
)
313318

314319
func ChunkifyCode(code []byte) ([][32]byte, error) {
@@ -348,7 +353,7 @@ func ChunkifyCode(code []byte) ([][32]byte, error) {
348353
// it should be 0 unless a PUSHn overflows.
349354
for ; codeOffset < end; codeOffset++ {
350355
if code[codeOffset] >= PUSH1 && code[codeOffset] <= PUSH32 {
351-
codeOffset += int(code[codeOffset]) - PUSH1 + 1
356+
codeOffset += int(code[codeOffset] - PUSH1 + 1)
352357
if codeOffset+1 >= 31*(i+1) {
353358
codeOffset++
354359
chunkOffset = codeOffset - 31*(i+1)

trie/verkle_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"testing"
2222

2323
"github.com/ethereum/go-ethereum/common"
24-
"github.com/ethereum/go-ethereum/core/vm"
2524
"github.com/gballet/go-verkle"
2625
)
2726

@@ -155,13 +154,13 @@ func TestChunkifyCodeTestnet(t *testing.T) {
155154

156155
func TestChunkifyCodeSimple(t *testing.T) {
157156
code := []byte{
158-
0, byte(vm.PUSH4), 1, 2, 3, 4, byte(vm.PUSH3), 58, 68, 12, byte(vm.PUSH21), 1, 2, 3, 4, 5, 6,
157+
0, PUSH4, 1, 2, 3, 4, PUSH3, 58, 68, 12, PUSH21, 1, 2, 3, 4, 5, 6,
159158
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
160159
// Second 31 bytes
161-
0, byte(vm.PUSH21), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
162-
byte(vm.PUSH7), 1, 2, 3, 4, 5, 6, 7,
160+
0, PUSH21, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
161+
PUSH7, 1, 2, 3, 4, 5, 6, 7,
163162
// Third 31 bytes
164-
byte(vm.PUSH30), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
163+
PUSH30, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
165164
23, 24, 25, 26, 27, 28, 29, 30,
166165
}
167166
t.Logf("code=%x", code)
@@ -218,7 +217,7 @@ func TestChunkifyCodeFuzz(t *testing.T) {
218217
t.Logf("code=%x, chunks=%x\n", code, chunks)
219218

220219
code = []byte{
221-
byte(vm.PUSH4), PUSH32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
220+
PUSH4, PUSH32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
222221
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
223222
}
224223
chunks, err = ChunkifyCode(code)
@@ -237,7 +236,7 @@ func TestChunkifyCodeFuzz(t *testing.T) {
237236
t.Logf("code=%x, chunks=%x\n", code, chunks)
238237

239238
code = []byte{
240-
byte(vm.PUSH4), PUSH32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
239+
PUSH4, PUSH32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
241240
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
242241
}
243242
chunks, err = ChunkifyCode(code)

0 commit comments

Comments
 (0)