fix usage of tx return value

pull/5370/head
yann300 2 years ago committed by Aniket
parent b61a8f3e57
commit fc11863c66
  1. 2
      apps/remix-ide/src/blockchain/blockchain.js
  2. 4
      apps/remix-ide/src/blockchain/providers/worker-vm.ts
  3. 4
      libs/remix-lib/src/execution/txExecution.ts
  4. 2
      libs/remix-lib/src/execution/txListener.ts
  5. 2
      libs/remix-simulator/src/VmProxy.ts
  6. 15
      libs/remix-simulator/src/methods/transactions.ts

@ -733,7 +733,7 @@ export class Blockchain extends Plugin {
execResult = await this.web3().eth.getExecutionResultFromSimulator(txResult.transactionHash)
if (execResult) {
// if it's not the VM, we don't have return value. We only have the transaction, and it does not contain the return value.
returnValue = execResult ? execResult.returnValue : toBuffer(addHexPrefix(txResult.result) || '0x0000000000000000000000000000000000000000000000000000000000000000')
returnValue = execResult ? toBuffer(execResult.returnValue) : toBuffer(addHexPrefix(txResult.result) || '0x0000000000000000000000000000000000000000000000000000000000000000')
const compiledContracts = await this.call('compilerArtefacts', 'getAllContractDatas')
const vmError = txExecution.checkVMError(execResult, compiledContracts)
if (vmError.error) {

@ -15,10 +15,6 @@ self.onmessage = (e: MessageEvent) => {
{
if (provider) {
provider.sendAsync(data.query, (error, result) => {
result = JSON.parse(JSON.stringify(result, (key, value) => {
if (typeof value === 'bigint') return bigIntToHex(value)
return value
}))
self.postMessage({
cmd: 'sendAsyncResult',
error,

@ -89,7 +89,7 @@ export function checkVMError (execResult, compiledContracts) {
ret.error = true
} else if (exceptionError === errorCode.REVERT) {
const returnData = execResult.returnValue
const returnDataHex = returnData.slice(0, 4).toString('hex')
const returnDataHex = returnData.slice(2, 10)
let customError
if (compiledContracts) {
let decodedCustomErrorInputsClean
@ -159,7 +159,7 @@ export function checkVMError (execResult, compiledContracts) {
// It is the hash of Error(string)
if (returnData && (returnDataHex === '08c379a0')) {
const abiCoder = new ethers.utils.AbiCoder()
const reason = abiCoder.decode(['string'], returnData.slice(4))[0]
const reason = abiCoder.decode(['string'], '0x' + returnData.slice(10))[0]
msg = `\tThe transaction has been reverted to the initial state.\nReason provided by the contract: "${reason}".`
} else {
msg = '\tThe transaction has been reverted to the initial state.\nNote: The called function should be payable if you send value and the value you send should be less than your current balance.'

@ -64,7 +64,7 @@ export class TxListener {
let execResult
if (this.executionContext.isVM()) {
execResult = await this.executionContext.web3().eth.getExecutionResultFromSimulator(txResult.transactionHash)
returnValue = execResult.returnValue
returnValue = toBuffer(execResult.returnValue)
} else {
returnValue = toBuffer(addHexPrefix(txResult.result))
}

@ -191,7 +191,7 @@ export class VmProxy {
this.vmTraces[this.processingHash].return = toChecksumAddress(address)
this.txsReceipt[this.processingHash].contractAddress = toChecksumAddress(address)
} else if (data.execResult.returnValue) {
this.vmTraces[this.processingHash].return = bufferToHex(data.execResult.returnValue)
this.vmTraces[this.processingHash].return = data.execResult.returnValue
} else {
this.vmTraces[this.processingHash].return = '0x'
}

@ -16,7 +16,7 @@ export type VMExecResult = {
gas: bigint
gasRefund: bigint
logs: Log[]
returnValue: Buffer
returnValue: string
}
export class Transactions {
@ -87,13 +87,14 @@ export class Transactions {
this.vmContext.addBlock(result.block)
const hash = '0x' + result.tx.hash().toString('hex')
this.vmContext.trackTx(hash, result.block, result.tx)
const returnValue = `0x${result.result.execResult.returnValue.toString('hex') || '0'}`
const execResult: VMExecResult = {
exceptionError: result.result.execResult.exceptionError,
executionGasUsed: result.result.execResult.executionGasUsed,
gas: result.result.execResult.gas,
gasRefund: result.result.execResult.gasRefund,
logs: result.result.execResult.logs,
returnValue: result.result.execResult.returnValue
returnValue
}
this.vmContext.trackExecResult(hash, execResult)
return cb(null, result.transactionHash)
@ -159,9 +160,9 @@ export class Transactions {
if (error) return cb(error)
if ((result as any).receipt === '0x0') {
try {
const msg = result.execResult.returnValue
const msg = `0x${result.execResult.returnValue.toString('hex') || '0'}`
const abiCoder = new ethers.utils.AbiCoder()
const reason = abiCoder.decode(['string'], msg.slice(4))[0]
const reason = abiCoder.decode(['string'], '0x' + msg.slice(10))[0]
return cb('revert ' + reason)
} catch (e) {
return cb(e.message)
@ -200,23 +201,23 @@ export class Transactions {
const tag = payload.params[0].timestamp // e2e reference
processTx(this.txRunnerInstance, payload, true, (error, result) => {
processTx(this.txRunnerInstance, payload, true, (error, result: VMxecutionResult) => {
if (!error && result) {
this.vmContext.addBlock(result.block)
const hash = '0x' + result.tx.hash().toString('hex')
this.vmContext.trackTx(hash, result.block, result.tx)
const returnValue = `0x${result.result.execResult.returnValue.toString('hex') || '0'}`
const execResult: VMExecResult = {
exceptionError: result.result.execResult.exceptionError,
executionGasUsed: result.result.execResult.executionGasUsed,
gas: result.result.execResult.gas,
gasRefund: result.result.execResult.gasRefund,
logs: result.result.execResult.logs,
returnValue: result.result.execResult.returnValue
returnValue: returnValue
}
this.vmContext.trackExecResult(hash, execResult)
this.tags[tag] = result.transactionHash
// calls are not supposed to return a transaction hash. we do this for keeping track of it and allowing debugging calls.
const returnValue = `0x${result.result.execResult.returnValue.toString('hex') || '0'}`
return cb(null, returnValue)
}
cb(error)

Loading…
Cancel
Save