memory_table.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 memoryCreate2(stack *Stack) *big.Int {
  49. return calcMemSize(stack.Back(1), stack.Back(2))
  50. }
  51. func memoryCall(stack *Stack) *big.Int {
  52. x := calcMemSize(stack.Back(5), stack.Back(6))
  53. y := calcMemSize(stack.Back(3), stack.Back(4))
  54. return math.BigMax(x, y)
  55. }
  56. func memoryDelegateCall(stack *Stack) *big.Int {
  57. x := calcMemSize(stack.Back(4), stack.Back(5))
  58. y := calcMemSize(stack.Back(2), stack.Back(3))
  59. return math.BigMax(x, y)
  60. }
  61. func memoryStaticCall(stack *Stack) *big.Int {
  62. x := calcMemSize(stack.Back(4), stack.Back(5))
  63. y := calcMemSize(stack.Back(2), stack.Back(3))
  64. return math.BigMax(x, y)
  65. }
  66. func memoryReturn(stack *Stack) *big.Int {
  67. return calcMemSize(stack.Back(0), stack.Back(1))
  68. }
  69. func memoryRevert(stack *Stack) *big.Int {
  70. return calcMemSize(stack.Back(0), stack.Back(1))
  71. }
  72. func memoryLog(stack *Stack) *big.Int {
  73. mSize, mStart := stack.Back(1), stack.Back(0)
  74. return calcMemSize(mStart, mSize)
  75. }