github.com/dominant-strategies/go-quai@v0.28.2/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  import "github.com/holiman/uint256"
    20  
    21  func memorySha3(stack *Stack) (uint64, bool) {
    22  	return calcMemSize64(stack.Back(0), stack.Back(1))
    23  }
    24  
    25  func memoryCallDataCopy(stack *Stack) (uint64, bool) {
    26  	return calcMemSize64(stack.Back(0), stack.Back(2))
    27  }
    28  
    29  func memoryReturnDataCopy(stack *Stack) (uint64, bool) {
    30  	return calcMemSize64(stack.Back(0), stack.Back(2))
    31  }
    32  
    33  func memoryCodeCopy(stack *Stack) (uint64, bool) {
    34  	return calcMemSize64(stack.Back(0), stack.Back(2))
    35  }
    36  
    37  func memoryExtCodeCopy(stack *Stack) (uint64, bool) {
    38  	return calcMemSize64(stack.Back(1), stack.Back(3))
    39  }
    40  
    41  func memoryMLoad(stack *Stack) (uint64, bool) {
    42  	return calcMemSize64WithUint(stack.Back(0), 32)
    43  }
    44  
    45  func memoryMStore8(stack *Stack) (uint64, bool) {
    46  	return calcMemSize64WithUint(stack.Back(0), 1)
    47  }
    48  
    49  func memoryMStore(stack *Stack) (uint64, bool) {
    50  	return calcMemSize64WithUint(stack.Back(0), 32)
    51  }
    52  
    53  func memoryCreate(stack *Stack) (uint64, bool) {
    54  	return calcMemSize64(stack.Back(1), stack.Back(2))
    55  }
    56  
    57  func memoryCreate2(stack *Stack) (uint64, bool) {
    58  	return calcMemSize64(stack.Back(1), stack.Back(2))
    59  }
    60  
    61  func memoryCall(stack *Stack) (uint64, bool) {
    62  	x, overflow := calcMemSize64(stack.Back(5), stack.Back(6))
    63  	if overflow {
    64  		return 0, true
    65  	}
    66  	y, overflow := calcMemSize64(stack.Back(3), stack.Back(4))
    67  	if overflow {
    68  		return 0, true
    69  	}
    70  	if x > y {
    71  		return x, false
    72  	}
    73  	return y, false
    74  }
    75  func memoryDelegateCall(stack *Stack) (uint64, bool) {
    76  	x, overflow := calcMemSize64(stack.Back(4), stack.Back(5))
    77  	if overflow {
    78  		return 0, true
    79  	}
    80  	y, overflow := calcMemSize64(stack.Back(2), stack.Back(3))
    81  	if overflow {
    82  		return 0, true
    83  	}
    84  	if x > y {
    85  		return x, false
    86  	}
    87  	return y, false
    88  }
    89  
    90  func memoryStaticCall(stack *Stack) (uint64, bool) {
    91  	x, overflow := calcMemSize64(stack.Back(4), stack.Back(5))
    92  	if overflow {
    93  		return 0, true
    94  	}
    95  	y, overflow := calcMemSize64(stack.Back(2), stack.Back(3))
    96  	if overflow {
    97  		return 0, true
    98  	}
    99  	if x > y {
   100  		return x, false
   101  	}
   102  	return y, false
   103  }
   104  
   105  func memoryReturn(stack *Stack) (uint64, bool) {
   106  	return calcMemSize64(stack.Back(0), stack.Back(1))
   107  }
   108  
   109  func memoryRevert(stack *Stack) (uint64, bool) {
   110  	return calcMemSize64(stack.Back(0), stack.Back(1))
   111  }
   112  
   113  func memoryLog(stack *Stack) (uint64, bool) {
   114  	return calcMemSize64(stack.Back(0), stack.Back(1))
   115  }
   116  
   117  func memoryETX(stack *Stack) (uint64, bool) {
   118  	x, overflow := calcMemSize64(stack.Back(6), stack.Back(7))
   119  	if overflow {
   120  		return 0, true
   121  	}
   122  	y, overflow := calcMemSize64(stack.Back(8), stack.Back(9))
   123  	if overflow {
   124  		return 0, true
   125  	}
   126  
   127  	z, overflow := uint256.NewInt(0).AddOverflow(uint256.NewInt(x), uint256.NewInt(y))
   128  	if overflow {
   129  		return 0, true
   130  	}
   131  
   132  	return z.Uint64WithOverflow()
   133  }