common.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package vm
  2. import (
  3. "math/big"
  4. "github.com/ethereum/go-ethereum/ethutil"
  5. "github.com/ethereum/go-ethereum/logger"
  6. )
  7. var vmlogger = logger.NewLogger("VM")
  8. type Type int
  9. const (
  10. StandardVmTy Type = iota
  11. DebugVmTy
  12. MaxVmTy
  13. )
  14. var (
  15. GasStep = big.NewInt(1)
  16. GasSha = big.NewInt(10)
  17. GasSLoad = big.NewInt(20)
  18. GasSStore = big.NewInt(100)
  19. GasSStoreRefund = big.NewInt(100)
  20. GasBalance = big.NewInt(20)
  21. GasCreate = big.NewInt(100)
  22. GasCall = big.NewInt(20)
  23. GasCreateByte = big.NewInt(5)
  24. GasSha3Byte = big.NewInt(10)
  25. GasSha256Byte = big.NewInt(50)
  26. GasRipemdByte = big.NewInt(50)
  27. GasMemory = big.NewInt(1)
  28. GasData = big.NewInt(5)
  29. GasTx = big.NewInt(500)
  30. GasLog = big.NewInt(32)
  31. GasSha256 = big.NewInt(50)
  32. GasRipemd = big.NewInt(50)
  33. GasEcrecover = big.NewInt(500)
  34. GasMemCpy = big.NewInt(1)
  35. Pow256 = ethutil.BigPow(2, 256)
  36. LogTyPretty byte = 0x1
  37. LogTyDiff byte = 0x2
  38. U256 = ethutil.U256
  39. S256 = ethutil.S256
  40. )
  41. const MaxCallDepth = 1024
  42. func calcMemSize(off, l *big.Int) *big.Int {
  43. if l.Cmp(ethutil.Big0) == 0 {
  44. return ethutil.Big0
  45. }
  46. return new(big.Int).Add(off, l)
  47. }
  48. // Simple helper
  49. func u256(n int64) *big.Int {
  50. return big.NewInt(n)
  51. }
  52. // Mainly used for print variables and passing to Print*
  53. func toValue(val *big.Int) interface{} {
  54. // Let's assume a string on right padded zero's
  55. b := val.Bytes()
  56. if b[0] != 0 && b[len(b)-1] == 0x0 && b[len(b)-2] == 0x0 {
  57. return string(b)
  58. }
  59. return val
  60. }