memory_table.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. package vm
  17. import (
  18. "math/big"
  19. "github.com/ethereum/go-ethereum/common/math"
  20. )
  21. func memorySha3(stack *Stack) *big.Int {
  22. return calcMemSize(stack.Back(0), stack.Back(1))
  23. }
  24. func memoryCallDataCopy(stack *Stack) *big.Int {
  25. return calcMemSize(stack.Back(0), stack.Back(2))
  26. }
  27. func memoryReturnDataCopy(stack *Stack) *big.Int {
  28. return calcMemSize(stack.Back(0), stack.Back(2))
  29. }
  30. func memoryCodeCopy(stack *Stack) *big.Int {
  31. return calcMemSize(stack.Back(0), stack.Back(2))
  32. }
  33. func memoryExtCodeCopy(stack *Stack) *big.Int {
  34. return calcMemSize(stack.Back(1), stack.Back(3))
  35. }
  36. func memoryMLoad(stack *Stack) *big.Int {
  37. return calcMemSize(stack.Back(0), big.NewInt(32))
  38. }
  39. func memoryMStore8(stack *Stack) *big.Int {
  40. return calcMemSize(stack.Back(0), big.NewInt(1))
  41. }
  42. func memoryMStore(stack *Stack) *big.Int {
  43. return calcMemSize(stack.Back(0), big.NewInt(32))
  44. }
  45. func memoryCreate(stack *Stack) *big.Int {
  46. return calcMemSize(stack.Back(1), stack.Back(2))
  47. }
  48. func memoryCall(stack *Stack) *big.Int {
  49. x := calcMemSize(stack.Back(5), stack.Back(6))
  50. y := calcMemSize(stack.Back(3), stack.Back(4))
  51. return math.BigMax(x, y)
  52. }
  53. func memoryCallCode(stack *Stack) *big.Int {
  54. x := calcMemSize(stack.Back(5), stack.Back(6))
  55. y := calcMemSize(stack.Back(3), stack.Back(4))
  56. return math.BigMax(x, y)
  57. }
  58. func memoryDelegateCall(stack *Stack) *big.Int {
  59. x := calcMemSize(stack.Back(4), stack.Back(5))
  60. y := calcMemSize(stack.Back(2), stack.Back(3))
  61. return math.BigMax(x, y)
  62. }
  63. func memoryStaticCall(stack *Stack) *big.Int {
  64. x := calcMemSize(stack.Back(4), stack.Back(5))
  65. y := calcMemSize(stack.Back(2), stack.Back(3))
  66. return math.BigMax(x, y)
  67. }
  68. func memoryReturn(stack *Stack) *big.Int {
  69. return calcMemSize(stack.Back(0), stack.Back(1))
  70. }
  71. func memoryRevert(stack *Stack) *big.Int {
  72. return calcMemSize(stack.Back(0), stack.Back(1))
  73. }
  74. func memoryLog(stack *Stack) *big.Int {
  75. mSize, mStart := stack.Back(1), stack.Back(0)
  76. return calcMemSize(mStart, mSize)
  77. }