github.com/ethereum/go-ethereum@v1.16.1/core/vm/memory_table.go (about) 1 // Copyright 2017 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package vm 18 19 func memoryKeccak256(stack *Stack) (uint64, bool) { 20 return calcMemSize64(stack.Back(0), stack.Back(1)) 21 } 22 23 func memoryCallDataCopy(stack *Stack) (uint64, bool) { 24 return calcMemSize64(stack.Back(0), stack.Back(2)) 25 } 26 27 func memoryReturnDataCopy(stack *Stack) (uint64, bool) { 28 return calcMemSize64(stack.Back(0), stack.Back(2)) 29 } 30 31 func memoryCodeCopy(stack *Stack) (uint64, bool) { 32 return calcMemSize64(stack.Back(0), stack.Back(2)) 33 } 34 35 func memoryExtCodeCopy(stack *Stack) (uint64, bool) { 36 return calcMemSize64(stack.Back(1), stack.Back(3)) 37 } 38 39 func memoryMLoad(stack *Stack) (uint64, bool) { 40 return calcMemSize64WithUint(stack.Back(0), 32) 41 } 42 43 func memoryMStore8(stack *Stack) (uint64, bool) { 44 return calcMemSize64WithUint(stack.Back(0), 1) 45 } 46 47 func memoryMStore(stack *Stack) (uint64, bool) { 48 return calcMemSize64WithUint(stack.Back(0), 32) 49 } 50 51 func memoryMcopy(stack *Stack) (uint64, bool) { 52 mStart := stack.Back(0) // stack[0]: dest 53 if stack.Back(1).Gt(mStart) { 54 mStart = stack.Back(1) // stack[1]: source 55 } 56 return calcMemSize64(mStart, stack.Back(2)) // stack[2]: length 57 } 58 59 func memoryCreate(stack *Stack) (uint64, bool) { 60 return calcMemSize64(stack.Back(1), stack.Back(2)) 61 } 62 63 func memoryCreate2(stack *Stack) (uint64, bool) { 64 return calcMemSize64(stack.Back(1), stack.Back(2)) 65 } 66 67 func memoryCall(stack *Stack) (uint64, bool) { 68 x, overflow := calcMemSize64(stack.Back(5), stack.Back(6)) 69 if overflow { 70 return 0, true 71 } 72 y, overflow := calcMemSize64(stack.Back(3), stack.Back(4)) 73 if overflow { 74 return 0, true 75 } 76 if x > y { 77 return x, false 78 } 79 return y, false 80 } 81 82 func memoryDelegateCall(stack *Stack) (uint64, bool) { 83 x, overflow := calcMemSize64(stack.Back(4), stack.Back(5)) 84 if overflow { 85 return 0, true 86 } 87 y, overflow := calcMemSize64(stack.Back(2), stack.Back(3)) 88 if overflow { 89 return 0, true 90 } 91 if x > y { 92 return x, false 93 } 94 return y, false 95 } 96 97 func memoryStaticCall(stack *Stack) (uint64, bool) { 98 x, overflow := calcMemSize64(stack.Back(4), stack.Back(5)) 99 if overflow { 100 return 0, true 101 } 102 y, overflow := calcMemSize64(stack.Back(2), stack.Back(3)) 103 if overflow { 104 return 0, true 105 } 106 if x > y { 107 return x, false 108 } 109 return y, false 110 } 111 112 func memoryReturn(stack *Stack) (uint64, bool) { 113 return calcMemSize64(stack.Back(0), stack.Back(1)) 114 } 115 116 func memoryRevert(stack *Stack) (uint64, bool) { 117 return calcMemSize64(stack.Back(0), stack.Back(1)) 118 } 119 120 func memoryLog(stack *Stack) (uint64, bool) { 121 return calcMemSize64(stack.Back(0), stack.Back(1)) 122 }