Conflux-Chain / CIPs

Conflux Improvement Proposals (CIPs)
MIT License
26 stars 30 forks source link

Update some error return values. #70

Closed ChenxingLi closed 2 years ago

ChenxingLi commented 3 years ago

1. Return value of estimateGasAndCollateral

Before the change

Revert without reason

{code: -32015, code: "Estimation isn't accurate: transaction is reverted. Execution output ", data: "0x..."}

Revert with reason

{code: -32015, code: "Estimation isn't accurate: transaction is reverted. Execution output Reason provided by the contract: 'ERC20: transfer amount exceeds allowance'", data: "0x..."}

After the change

Revert with reason

{code: -32015, code: "Estimation isn't accurate: transaction is reverted: ERC20: transfer amount exceeds allowance.", data: "0x..."}

Revert without reason, but a sub-call provides a reason.

For example, a contract calls USDT_contract.transferFrom(from, to, value). The function transferFrom will be reverted with reason 'ERC20: transfer amount exceeds allowance'. But the outside function will revert without reason.

{code: -32015, code: "Estimation isn't accurate: transaction is reverted. Innermost error is at cfx:type.contract:achc8nxj7r451c223m18w2dwjnmhkd6rxawrvkvsy2: ERC20: transfer amount exceeds allowance.", data: "0x..."}

Here, cfx:type.contract:achc8nxj7r451c223m18w2dwjnmhkd6rxawrvkvsy2 is the contract address of USDT.

Revert without reason, and a sub-call also provides no reason.

{code: -32015, code: "Estimation isn't accurate: transaction is reverted.", data: "0x..."}

Revert with reason, and a sub-call also gives a reason.

For example, when your contract calls USDT contract via safeTransferFrom function provided by OpenZeppelin, then the USDT contract will revert with reason "ERC20: transfer amount exceeds allowance" and your contract will revert with reason "SafeERC20: low-level call failed".

{code: -32015, code: "Estimation isn't accurate: transaction is reverted: SafeERC20: low-level call failed. Innermost error is at cfx:type.contract:achc8nxj7r451c223m18w2dwjnmhkd6rxawrvkvsy2: ERC20: transfer amount exceeds allowance.", data: "0x..."}

2. Error message in receipt

The error message when a transaction is reverted changes.

Before the change.

"Vm reverted, Reason provided by the contract: 'ERC20: transfer amount exceeds allowance'"

After the change.

"Vm reverted, ERC20: transfer amount exceeds allowance"

3. Trace

The trace of a transaction is a list of actions. If an action is a call result or a create result, it will contain a key called returnData.

Before the change.

If the outcome of call/create result is fail, the returnData must be empty.

After the change.

If the outcome of call/create result is fail, the returnData is a hex encoded string of error message.

Pana commented 3 years ago

There two code field in the example @ChenxingLi