Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(builder): handling of errors when deploying contracts (create2) #839

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

saeta-eth
Copy link
Contributor

@saeta-eth saeta-eth commented Mar 25, 2024

This PR aims to show the error when a contract reverts during deployment. It will handle deployments with CREATE2.

Closes https://linear.app/usecannon/issue/CAN-204/verify-contract-create-transaction-before-sending-to-network

Copy link

changeset-bot bot commented Mar 25, 2024

⚠️ No Changeset found

Latest commit: d46835f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

nx-cloud bot commented Mar 25, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit d46835f. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

Copy link
Contributor

@mjlescano mjlescano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! A thing to note is that when executing the transaction after failure without using CREATE2 to be available to parse the error, there's a slight chance that the execution doesn't fail on this case, depending the users' implementation. And the user would end up deploying a contract without using CREATE2, and not sure what would happen with the build.

There's a non chance of this, but could happen.

Copy link
Contributor

@dbeal-eth dbeal-eth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have a test verifying that this decoding functionality works?

is it possible that, rather than utilizing low level error decoding capabilities, we detect any error that cannon has awareness of, even in other contracts, so far?

ideally we use the CannonTraceError, which prints out error and stack trace using data from all contracts in the project

The problem right now is that the "error" may be unknown if the constructor is executed and we havent imported the contract ABI yet.

@saeta-eth saeta-eth changed the title fix(cli): handle create2 revert fix(builder): handling of errors when deploying contracts (create2) May 22, 2024
@saeta-eth
Copy link
Contributor Author

do we have a test verifying that this decoding functionality works?

is it possible that, rather than utilizing low level error decoding capabilities, we detect any error that cannon has awareness of, even in other contracts, so far?

ideally we use the CannonTraceError, which prints out error and stack trace using data from all contracts in the project

The problem right now is that the "error" may be unknown if the constructor is executed and we havent imported the contract ABI yet.

Yes, I have tested it, and it worked as expected. The main issue is that we can't decode the error if the transaction reverts because the Arachnid deployer doesn't return the underlying error. The Arachnid deployer returns 0x if the deployment reverts, and we can't decode it to get the real underlying error.

@dbeal-eth
Copy link
Contributor

do we have a test verifying that this decoding functionality works?
is it possible that, rather than utilizing low level error decoding capabilities, we detect any error that cannon has awareness of, even in other contracts, so far?
ideally we use the CannonTraceError, which prints out error and stack trace using data from all contracts in the project
The problem right now is that the "error" may be unknown if the constructor is executed and we havent imported the contract ABI yet.

Yes, I have tested it, and it worked as expected. The main issue is that we can't decode the error if the transaction reverts because the Arachnid deployer doesn't return the underlying error. The Arachnid deployer returns 0x if the deployment reverts, and we can't decode it to get the real underlying error.

while it is true that arachnid does not return the ultimate error, if we print out the txn trace, the error should be visible in the second layer of the trace, right?

@saeta-eth
Copy link
Contributor Author

do we have a test verifying that this decoding functionality works?
is it possible that, rather than utilizing low level error decoding capabilities, we detect any error that cannon has awareness of, even in other contracts, so far?
ideally we use the CannonTraceError, which prints out error and stack trace using data from all contracts in the project
The problem right now is that the "error" may be unknown if the constructor is executed and we havent imported the contract ABI yet.

Yes, I have tested it, and it worked as expected. The main issue is that we can't decode the error if the transaction reverts because the Arachnid deployer doesn't return the underlying error. The Arachnid deployer returns 0x if the deployment reverts, and we can't decode it to get the real underlying error.

while it is true that arachnid does not return the ultimate error, if we print out the txn trace, the error should be visible in the second layer of the trace, right?

Based on some tests I conducted, there is no second layer of the trace. It's traced until the '0x'. That's why I implemented this workaround to get the underlying revert reason. Do you have another idea in mind?

Here is an example of how they look:

Without this code:


  CALL 0x4e59b44847b379578588920ca78fbf26c0b4956c.0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470608060405260405162000fcf38038062000fcf8339810160408190526200002691620002b0565b82826003620000368382620003b1565b506004620000458282620003b1565b505050620000626200005c620000cd60201b60201c565b620000d1565b80600003620000b85760405162461bcd60e51b815260206004820152601a60248201527f496e697469616c20737570706c792063616e6e6f74206265203000000000000060448201526064015b60405180910390fd5b620000c4338262000123565b505050620004a5565b3390565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6001600160a01b0382166200017b5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401620000af565b80600260008282546200018f91906200047d565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b505050565b634e487b7160e01b600052604160045260246000fd5b600082601f8301126200021357600080fd5b81516001600160401b0380821115620002305762000230620001eb565b604051601f8301601f19908116603f011681019082821181831017156200025b576200025b620001eb565b816040528381526020925086838588010111156200027857600080fd5b600091505b838210156200029c57858201830151818301840152908201906200027d565b600093810190920192909252949350505050565b600080600060608486031215620002c657600080fd5b83516001600160401b0380821115620002de57600080fd5b620002ec8783880162000201565b945060208601519150808211156200030357600080fd5b50620003128682870162000201565b925050604084015190509250925092565b600181811c908216806200033857607f821691505b6020821081036200035957634e487b7160e01b600052602260045260246000fd5b50919050565b601f821115620001e657600081815260208120601f850160051c81016020861015620003885750805b601f850160051c820191505b81811015620003a95782815560010162000394565b505050505050565b81516001600160401b03811115620003cd57620003cd620001eb565b620003e581620003de845462000323565b846200035f565b602080601f8311600181146200041d5760008415620004045750858301515b600019600386901b1c1916600185901b178555620003a9565b600085815260208120601f198616915b828110156200044e578886015182559484019460019091019084016200042d565b50858210156200046d5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b808201808211156200049f57634e487b7160e01b600052601160045260246000fd5b92915050565b610b1a80620004b56000396000f3fe608060405234801561001057600080fd5b50600436106100f55760003560e01c8063715018a611610097578063a457c2d711610066578063a457c2d7146101eb578063a9059cbb146101fe578063dd62ed3e14610211578063f2fde38b1461022457600080fd5b8063715018a6146101ab5780638da5cb5b146101b557806394bf804d146101d057806395d89b41146101e357600080fd5b806323b872dd116100d357806323b872dd1461014d578063313ce56714610160578063395093511461016f57806370a082311461018257600080fd5b806306fdde03146100fa578063095ea7b31461011857806318160ddd1461013b575b600080fd5b610102610237565b60405161010f9190610941565b60405180910390f35b61012b6101263660046109ab565b6102c9565b604051901515815260200161010f565b6002545b60405190815260200161010f565b61012b61015b3660046109d5565b6102e3565b6040516012815260200161010f565b61012b61017d3660046109ab565b610307565b61013f610190366004610a11565b6001600160a01b031660009081526020819052604090205490565b6101b3610329565b005b6005546040516001600160a01b03909116815260200161010f565b6101b36101de366004610a33565b61033d565b610102610353565b61012b6101f93660046109ab565b610362565b61012b61020c3660046109ab565b6103e2565b61013f61021f366004610a5f565b6103f0565b6101b3610232366004610a11565b61041b565b60606003805461024690610a89565b80601f016020809104026020016040519081016040528092919081815260200182805461027290610a89565b80156102bf5780601f10610294576101008083540402835291602001916102bf565b820191906000526020600020905b8154815290600101906020018083116102a257829003601f168201915b5050505050905090565b6000336102d7818585610494565b60019150505b92915050565b6000336102f18582856105b8565b6102fc858585610632565b506001949350505050565b6000336102d781858561031a83836103f0565b6103249190610ac3565b610494565b6103316107d6565b61033b6000610830565b565b6103456107d6565b61034f8183610882565b5050565b60606004805461024690610a89565b6000338161037082866103f0565b9050838110156103d55760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084015b60405180910390fd5b6102fc8286868403610494565b6000336102d7818585610632565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6104236107d6565b6001600160a01b0381166104885760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016103cc565b61049181610830565b50565b6001600160a01b0383166104f65760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084016103cc565b6001600160a01b0382166105575760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016103cc565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60006105c484846103f0565b9050600019811461062c578181101561061f5760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e636500000060448201526064016103cc565b61062c8484848403610494565b50505050565b6001600160a01b0383166106965760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b60648201526084016103cc565b6001600160a01b0382166106f85760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b60648201526084016103cc565b6001600160a01b038316600090815260208190526040902054818110156107705760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b60648201526084016103cc565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a361062c565b6005546001600160a01b0316331461033b5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016103cc565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6001600160a01b0382166108d85760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f20616464726573730060448201526064016103cc565b80600260008282546108ea9190610ac3565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b600060208083528351808285015260005b8181101561096e57858101830151858201604001528201610952565b506000604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b03811681146109a657600080fd5b919050565b600080604083850312156109be57600080fd5b6109c78361098f565b946020939093013593505050565b6000806000606084860312156109ea57600080fd5b6109f38461098f565b9250610a016020850161098f565b9150604084013590509250925092565b600060208284031215610a2357600080fd5b610a2c8261098f565b9392505050565b60008060408385031215610a4657600080fd5b82359150610a566020840161098f565b90509250929050565b60008060408385031215610a7257600080fd5b610a7b8361098f565b9150610a566020840161098f565b600181811c90821680610a9d57607f821691505b602082108103610abd57634e487b7160e01b600052602260045260246000fd5b50919050565b808201808211156102dd57634e487b7160e01b600052601160045260246000fdfea2646970667358221220fbd8b57fdb3adc9c40d37fc70b3dd4c08393b99cea28e151c78eb0bc970979fb64736f6c63430008150033000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005546f6b656e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003544b4e0000000000000000000000000000000000000000000000000000000000 => 0x (30,000,000 gas)
    CREATE
    at handleTxnError (/usr/local/lib/node_modules/@usecannon/cli/node_modules/@usecannon/builder/dist/src/error/index.js:144:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async handleTxnError (/usr/local/lib/node_modules/@usecannon/cli/node_modules/@usecannon/builder/dist/src/error/index.js:106:9)
    at async handleTxnError (/usr/local/lib/node_modules/@usecannon/cli/node_modules/@usecannon/builder/dist/src/error/index.js:106:9)
    at async handleTxnError (/usr/local/lib/node_modules/@usecannon/cli/node_modules/@usecannon/builder/dist/src/error/index.js:106:9)
    at async Object.estimateGas (/usr/local/lib/node_modules/@usecannon/cli/node_modules/@usecannon/builder/dist/src/error/index.js:45:21)
    at async prepareTransactionRequest (/usr/local/lib/node_modules/@usecannon/cli/node_modules/viem/_cjs/actions/wallet/prepareTransactionRequest.js:119:23)
    at async Object.prepareTransactionRequest (/usr/local/lib/node_modules/@usecannon/cli/node_modules/@usecannon/builder/dist/src/error/index.js:64:28)
    at async Object.exec (/usr/local/lib/node_modules/@usecannon/cli/node_modules/@usecannon/builder/dist/src/steps/deploy.js:221:37)
    at async /usr/local/lib/node_modules/@usecannon/cli/node_modules/viem/_cjs/utils/promise/withTimeout.js:21:25 {
  code: 'NONCE_EXPIRED',
  error: { code: 3, message: 'execution reverted', data: '0x' }
}

With this code:

CannonTraceError: transaction reverted in contract unknown: Error("Initial supply cannot be 0")

  CREATE
    at handleTxnError (/Users/slorenzo/Desktop/dev/cannon/packages/builder/dist/src/error/index.js:144:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async handleTxnError (/Users/slorenzo/Desktop/dev/cannon/packages/builder/dist/src/error/index.js:106:9)
    at async handleTxnError (/Users/slorenzo/Desktop/dev/cannon/packages/builder/dist/src/error/index.js:106:9)
    at async handleTxnError (/Users/slorenzo/Desktop/dev/cannon/packages/builder/dist/src/error/index.js:106:9)
    at async Object.estimateGas (/Users/slorenzo/Desktop/dev/cannon/packages/builder/dist/src/error/index.js:45:21)
    at async prepareTransactionRequest (/Users/slorenzo/Desktop/dev/cannon/node_modules/viem/_cjs/actions/wallet/prepareTransactionRequest.js:119:23)
    at async Object.prepareTransactionRequest (/Users/slorenzo/Desktop/dev/cannon/packages/builder/dist/src/error/index.js:64:28)
    at async Object.exec (/Users/slorenzo/Desktop/dev/cannon/packages/builder/dist/src/steps/deploy.js:260:41)
    at async Object.exec (/Users/slorenzo/Desktop/dev/cannon/packages/builder/dist/src/steps/deploy.js:277:24) {
  code: 'UNKNOWN_ERROR',
  error: {
    code: 3,
    message: 'execution reverted: revert: Initial supply cannot be 0',
    data: '0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001a496e697469616c20737570706c792063616e6e6f742062652030000000000000'
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants