github.com/amazechain/amc@v0.1.3/internal/vm/memory_table.go (about)

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