<commit_before>/**
 * This is the Ethereum interface that is exposed to the WASM instance which
 * enables to interact with the Ethereum Environment
 */

const Vertex = require('merkle-trie')
const Address = require('./deps/address.js')
const U256 = require('./deps/u256.js')
const fs = require('fs')
const path = require('path')

const U128_SIZE_BYTES = 16
const ADDRESS_SIZE_BYTES = 20
const U256_SIZE_BYTES = 32

// The interface exposed to the WebAessembly Core
module.exports = class Interface {
  constructor (kernel) {
    this.kernel = kernel
    const shimBin = fs.readFileSync(path.join(__dirname, '/wasm/interface.wasm'))
    const shimMod = WebAssembly.Module(shimBin)
    this.shims = WebAssembly.Instance(shimMod, {
      'interface': {
        'useGas': this._useGas.bind(this),
        'getGasLeftHigh': this._getGasLeftHigh.bind(this),
        'getGasLeftLow': this._getGasLeftLow.bind(this),
        'call': this._call.bind(this)
      }
    })
  }

  static get name () {
    return 'ethereum'
  }

  get exports () {
    let exportMethods = [
      // include all the public methods according to the Ethereum Environment Interface (EEI) r1
      'getAddress',
      'getBalance',
      'getTxOrigin',
      'getCaller',
      'getCallValue',
      'getCallDataSize',
      'callDataCopy',
      'callDataCopy256',
      'getCodeSize',
      'codeCopy',
      'getExternalCodeSize',
      'externalCodeCopy',
      'getTxGasPrice',
      'getBlockHash',
      'getBlockCoinbase',
      'getBlockTimestamp',
      'getBlockNumber',
      'getBlockDifficulty',
      'getBlockGasLimit',
      'log',
      'create',
      'callCode',
      'callDelegate',
      'storageStore',
      'storageLoad',
      'return',
      'selfDestruct'
    ]
    let ret = {}
    exportMethods.forEach((method) => {
      ret[method] = this[method].bind(this)
    })

    // add shims
    ret.useGas = this.shims.exports.useGas
    ret.getGasLeft = this.shims.exports.getGasLeft
    ret.call = this.shims.exports.call
    return ret
  }

  setModule (mod) {
    this.module = mod
  }

  /**
   * Subtracts an amount to the gas counter
   * @param {integer} amount the amount to subtract to the gas counter
   */
  _useGas (high, low) {
    this.takeGas(from64bit(high, low))
  }

  /**
   * Returns the current amount of gas
   * @return {integer}
   */
  _getGasLeftHigh () {
    return Math.floor(this.kernel.environment.gasLeft / 4294967296)
  }

  /**
   * Returns the current amount of gas
   * @return {integer}
   */
  _getGasLeftLow () {
    return this.kernel.environment.gasLeft
  }

  /**
   * Gets address of currently executing account and loads it into memory at
   * the given offset.
   * @param {integer} offset
   */
  getAddress (offset) {
    this.takeGas(2)

    this.setMemory(offset, ADDRESS_SIZE_BYTES, this.kernel.environment.address.toMemory())
  }

  /**
   * Gets balance of the given account and loads it into memory at the given
   * offset.
   * @param {integer} addressOffset the memory offset to laod the address
   * @param {integer} resultOffset
   */
  getBalance (addressOffset, offset, cbIndex) {
    this.takeGas(20)

    const path = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'balance']
    const opPromise = this.kernel.environment.state.get(path)
      .then(vertex => new U256(vertex.value))
      .catch(() => new U256(0))<commit_msg>get balance should read the state from root<commit_after>/**
 * This is the Ethereum interface that is exposed to the WASM instance which
 * enables to interact with the Ethereum Environment
 */

const Vertex = require('merkle-trie')
const Address = require('./deps/address.js')
const U256 = require('./deps/u256.js')
const fs = require('fs')
const path = require('path')

const U128_SIZE_BYTES = 16
const ADDRESS_SIZE_BYTES = 20
const U256_SIZE_BYTES = 32

// The interface exposed to the WebAessembly Core
module.exports = class Interface {
  constructor (kernel) {
    this.kernel = kernel
    const shimBin = fs.readFileSync(path.join(__dirname, '/wasm/interface.wasm'))
    const shimMod = WebAssembly.Module(shimBin)
    this.shims = WebAssembly.Instance(shimMod, {
      'interface': {
        'useGas': this._useGas.bind(this),
        'getGasLeftHigh': this._getGasLeftHigh.bind(this),
        'getGasLeftLow': this._getGasLeftLow.bind(this),
        'call': this._call.bind(this)
      }
    })
  }

  static get name () {
    return 'ethereum'
  }

  get exports () {
    let exportMethods = [
      // include all the public methods according to the Ethereum Environment Interface (EEI) r1
      'getAddress',
      'getBalance',
      'getTxOrigin',
      'getCaller',
      'getCallValue',
      'getCallDataSize',
      'callDataCopy',
      'callDataCopy256',
      'getCodeSize',
      'codeCopy',
      'getExternalCodeSize',
      'externalCodeCopy',
      'getTxGasPrice',
      'getBlockHash',
      'getBlockCoinbase',
      'getBlockTimestamp',
      'getBlockNumber',
      'getBlockDifficulty',
      'getBlockGasLimit',
      'log',
      'create',
      'callCode',
      'callDelegate',
      'storageStore',
      'storageLoad',
      'return',
      'selfDestruct'
    ]
    let ret = {}
    exportMethods.forEach((method) => {
      ret[method] = this[method].bind(this)
    })

    // add shims
    ret.useGas = this.shims.exports.useGas
    ret.getGasLeft = this.shims.exports.getGasLeft
    ret.call = this.shims.exports.call
    return ret
  }

  setModule (mod) {
    this.module = mod
  }

  /**
   * Subtracts an amount to the gas counter
   * @param {integer} amount the amount to subtract to the gas counter
   */
  _useGas (high, low) {
    this.takeGas(from64bit(high, low))
  }

  /**
   * Returns the current amount of gas
   * @return {integer}
   */
  _getGasLeftHigh () {
    return Math.floor(this.kernel.environment.gasLeft / 4294967296)
  }

  /**
   * Returns the current amount of gas
   * @return {integer}
   */
  _getGasLeftLow () {
    return this.kernel.environment.gasLeft
  }

  /**
   * Gets address of currently executing account and loads it into memory at
   * the given offset.
   * @param {integer} offset
   */
  getAddress (offset) {
    this.takeGas(2)

    this.setMemory(offset, ADDRESS_SIZE_BYTES, this.kernel.environment.address.toMemory())
  }

  /**
   * Gets balance of the given account and loads it into memory at the given
   * offset.
   * @param {integer} addressOffset the memory offset to laod the address
   * @param {integer} resultOffset
   */
  getBalance (addressOffset, offset, cbIndex) {
    this.takeGas(20)

    const path = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'balance']
    const opPromise = this.kernel.environment.state.root.get(path)
      .then(vertex => new U256(vertex.value))
      .catch(() => new U256(0))
{'fraction_non_alphanumeric': 0.12014082440956432, 'fraction_numerical': 0.012908904210063077, 'mean_word_length': 2.849802371541502, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2304806', 'n_tokens_mistral': 2264, 'n_tokens_neox': 2143, 'n_words': 530}