memory_table.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 memoryCodeCopy(stack *Stack) *big.Int {
  28. return calcMemSize(stack.Back(0), stack.Back(2))
  29. }
  30. func memoryExtCodeCopy(stack *Stack) *big.Int {
  31. return calcMemSize(stack.Back(1), stack.Back(3))
  32. }
  33. func memoryMLoad(stack *Stack) *big.Int {
  34. return calcMemSize(stack.Back(0), big.NewInt(32))
  35. }
  36. func memoryMStore8(stack *Stack) *big.Int {
  37. return calcMemSize(stack.Back(0), big.NewInt(1))
  38. }
  39. func memoryMStore(stack *Stack) *big.Int {
  40. return calcMemSize(stack.Back(0), big.NewInt(32))
  41. }
  42. func memoryCreate(stack *Stack) *big.Int {
  43. return calcMemSize(stack.Back(1), stack.Back(2))
  44. }
  45. func memoryCall(stack *Stack) *big.Int {
  46. x := calcMemSize(stack.Back(5), stack.Back(6))
  47. y := calcMemSize(stack.Back(3), stack.Back(4))
  48. return math.BigMax(x, y)
  49. }
  50. func memoryCallCode(stack *Stack) *big.Int {
  51. x := calcMemSize(stack.Back(5), stack.Back(6))
  52. y := calcMemSize(stack.Back(3), stack.Back(4))
  53. return math.BigMax(x, y)
  54. }
  55. func memoryDelegateCall(stack *Stack) *big.Int {
  56. x := calcMemSize(stack.Back(4), stack.Back(5))
  57. y := calcMemSize(stack.Back(2), stack.Back(3))
  58. return math.BigMax(x, y)
  59. }
  60. func memoryReturn(stack *Stack) *big.Int {
  61. return calcMemSize(stack.Back(0), stack.Back(1))
  62. }
  63. func memoryLog(stack *Stack) *big.Int {
  64. mSize, mStart := stack.Back(1), stack.Back(0)
  65. return calcMemSize(mStart, mSize)
  66. }