github.com/klaytn/klaytn@v1.12.1/blockchain/vm/memory_table.go (about)

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