github.com/ontio/ontology@v1.14.4/vm/evm/memory_table.go (about)

     1  // Copyright (C) 2021 The Ontology 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  package evm
    19  
    20  func memorySha3(stack *Stack) (uint64, bool) {
    21  	return calcMemSize64(stack.Back(0), stack.Back(1))
    22  }
    23  
    24  func memoryCallDataCopy(stack *Stack) (uint64, bool) {
    25  	return calcMemSize64(stack.Back(0), stack.Back(2))
    26  }
    27  
    28  func memoryReturnDataCopy(stack *Stack) (uint64, bool) {
    29  	return calcMemSize64(stack.Back(0), stack.Back(2))
    30  }
    31  
    32  func memoryCodeCopy(stack *Stack) (uint64, bool) {
    33  	return calcMemSize64(stack.Back(0), stack.Back(2))
    34  }
    35  
    36  func memoryExtCodeCopy(stack *Stack) (uint64, bool) {
    37  	return calcMemSize64(stack.Back(1), stack.Back(3))
    38  }
    39  
    40  func memoryMLoad(stack *Stack) (uint64, bool) {
    41  	return calcMemSize64WithUint(stack.Back(0), 32)
    42  }
    43  
    44  func memoryMStore8(stack *Stack) (uint64, bool) {
    45  	return calcMemSize64WithUint(stack.Back(0), 1)
    46  }
    47  
    48  func memoryMStore(stack *Stack) (uint64, bool) {
    49  	return calcMemSize64WithUint(stack.Back(0), 32)
    50  }
    51  
    52  func memoryCreate(stack *Stack) (uint64, bool) {
    53  	return calcMemSize64(stack.Back(1), stack.Back(2))
    54  }
    55  
    56  func memoryCreate2(stack *Stack) (uint64, bool) {
    57  	return calcMemSize64(stack.Back(1), stack.Back(2))
    58  }
    59  
    60  func memoryCall(stack *Stack) (uint64, bool) {
    61  	x, overflow := calcMemSize64(stack.Back(5), stack.Back(6))
    62  	if overflow {
    63  		return 0, true
    64  	}
    65  	y, overflow := calcMemSize64(stack.Back(3), stack.Back(4))
    66  	if overflow {
    67  		return 0, true
    68  	}
    69  	if x > y {
    70  		return x, false
    71  	}
    72  	return y, false
    73  }
    74  func memoryDelegateCall(stack *Stack) (uint64, bool) {
    75  	x, overflow := calcMemSize64(stack.Back(4), stack.Back(5))
    76  	if overflow {
    77  		return 0, true
    78  	}
    79  	y, overflow := calcMemSize64(stack.Back(2), stack.Back(3))
    80  	if overflow {
    81  		return 0, true
    82  	}
    83  	if x > y {
    84  		return x, false
    85  	}
    86  	return y, false
    87  }
    88  
    89  func memoryStaticCall(stack *Stack) (uint64, bool) {
    90  	x, overflow := calcMemSize64(stack.Back(4), stack.Back(5))
    91  	if overflow {
    92  		return 0, true
    93  	}
    94  	y, overflow := calcMemSize64(stack.Back(2), stack.Back(3))
    95  	if overflow {
    96  		return 0, true
    97  	}
    98  	if x > y {
    99  		return x, false
   100  	}
   101  	return y, false
   102  }
   103  
   104  func memoryReturn(stack *Stack) (uint64, bool) {
   105  	return calcMemSize64(stack.Back(0), stack.Back(1))
   106  }
   107  
   108  func memoryRevert(stack *Stack) (uint64, bool) {
   109  	return calcMemSize64(stack.Back(0), stack.Back(1))
   110  }
   111  
   112  func memoryLog(stack *Stack) (uint64, bool) {
   113  	return calcMemSize64(stack.Back(0), stack.Back(1))
   114  }