Guest User

Untitled

a guest
Jul 31st, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. pc = uint64(0) // program counter
  2. for ; ; instrCount++ {
  3.  
  4.  
  5.  
  6. // Get the memory location of pc
  7. op = contract.GetOp(pc)
  8. // calculate the new memory size and gas price for the current executing opcode
  9. newMemSize, cost, err = calculateGasAndSize(evm.env, contract, caller, op, statedb, mem, stack)
  10. if err != nil {
  11. return nil, err
  12. }
  13.  
  14. // Use the calculated gas. When insufficient gas is present, use all gas and return an
  15. // Out Of Gas error
  16. if !contract.UseGas(cost) {
  17. return nil, OutOfGasError
  18. }
  19.  
  20. // Resize the memory calculated previously
  21. mem.Resize(newMemSize.Uint64())
  22. // Add a log message
  23. if evm.cfg.Debug {
  24. evm.logger.captureState(pc, op, contract.Gas, cost, mem, stack, contract, evm.env.Depth(), nil)
  25. }
  26.  
  27. if opPtr := evm.jumpTable[op]; opPtr.valid {
  28. if opPtr.fn != nil {
  29. opPtr.fn(instruction{}, &pc, evm.env, contract, mem, stack)
  30. } else {
  31. switch op {
  32. case PC:
  33. opPc(instruction{data: new(big.Int).SetUint64(pc)}, &pc, evm.env, contract, mem, stack)
  34. case JUMP:
  35. if err := jump(pc, stack.pop()); err != nil {
  36. return nil, err
  37. }
  38.  
  39. continue
  40. case JUMPI:
  41. pos, cond := stack.pop(), stack.pop()
  42.  
  43. if cond.Cmp(common.BigTrue) >= 0 {
  44. if err := jump(pc, pos); err != nil {
  45. return nil, err
  46. }
  47.  
  48. continue
  49. }
  50. case RETURN:
  51. offset, size := stack.pop(), stack.pop()
  52. ret := mem.GetPtr(offset.Int64(), size.Int64())
  53.  
  54. return ret, nil
  55. case SUICIDE:
  56. opSuicide(instruction{}, nil, evm.env, contract, mem, stack)
  57.  
  58. fallthrough
  59. case STOP: // Stop the contract
  60. return nil, nil
  61. }
  62. }
  63. } else {
  64. return nil, fmt.Errorf("Invalid opcode %x", op)
  65. }
  66.  
  67. pc++
  68.  
  69. }
Add Comment
Please, Sign In to add comment