Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

[3.0] Add LibExchangeRichErrorDecoder to exchange package #1790

Merged

Conversation

dorothy-zbornak
Copy link
Contributor

@dorothy-zbornak dorothy-zbornak commented Apr 24, 2019

Description

Summary

This PR adds a LibExchangeRichErrorDecoder contract to the @0x/contracts-exchange package. This contract exposes decoding (more like decomposing) functionality for ABI-encoded rich revert reasons (#1761).

Notes

  • Exchange does not use this new contract (but it could). It's designed to be inherited by a TBD standalone contract, that will likely live in separate package.
  • exchange-libs is not this contract's home for two reasons:
    • This is more DRY, as it can inherit types and selectors from exchange's MExchangeRichErrorTypes. An alternative would be to move MExchangeRichErrorTypes into exchange-libs, but that seems like overkill since no other packages use that mixin.
    • Looking ahead to when we upgrade other contracts to rich reverts, it wouldn't make sense to place their decoder libraries in exchange-libs because they aren't really Exchange related. Rich reverts are defined and used within their contract package, so they might as well host their own decoder libraries.

Testing instructions

You can find the new tests for this contract in contracts/exchange/test/src/lib_exchange_rich_error_decoder.ts.

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

  • Prefix PR title with [WIP] if necessary.
  • Add tests to cover changes as needed.
  • Update documentation as needed.
  • Add new entries to the relevant CHANGELOG.jsons.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 84.595% when pulling 84e9ad3 on feature/3.0/contracts/exchange/rich-revert-decoder into 02d8ef1 on 3.0.

LibOrder.OrderStatus orderStatus,
bytes32 orderHash
bytes32 orderHash,
LibOrder.OrderStatus orderStatus
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Swapped the order of these for consistency with other errors.

Copy link
Contributor

@hysz hysz left a comment

Choose a reason for hiding this comment

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

lgtm!

ALREADY_EXECUTED
}

bytes4 internal constant SIGNATURE_ERROR_SELECTOR =
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that these constant's will be evaluated everywhere they're referenced. May not matter for decoding, but if gas is important then something like this would be more efficient.

// bytes4(keccak256("SignatureError(uint8,bytes32,address,bytes)"))
bytes4 internal constant SIGNATURE_ERROR_SELECTOR = 0x7e5a2318;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, wow, I had no idea. That makes no sense to me. Definitely worth changing.

Copy link
Member

Choose a reason for hiding this comment

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

@hysz does the new constantOptimizer optimizer flag change this? I haven't really looked into it, but I'm not sure what else it would do (this is already set to true in our compiler.json).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 8243a6f

@dorothy-zbornak dorothy-zbornak changed the title Add LibExchangeRichErrorDecoder to exchange package [3.0] Add LibExchangeRichErrorDecoder to exchange package Apr 26, 2019
@dorothy-zbornak dorothy-zbornak force-pushed the feature/3.0/contracts/exchange/rich-revert-decoder branch 2 times, most recently from 9fcb2ec to 8243a6f Compare April 30, 2019 00:07
Update coordinator tests for new tooling.
Remove unecessary `chainId` parameter in `eip712_utils.createCoordinatorApprovalTypeData`
…abi-gen-wrappers` to use new domain schema and `Order` format.
…e rich revert errors.

In `@0x/order-utils`: Change parameter order for `OrderStatusError`.
…RichErrors` into `MExchangeRichErrorTypes`.

In `@0x/contracts-utils`: Pull types and constants from `MRichErrors` into `MRichErrorTypes`.
…rit from `@0x/contracts-exchange/.../MExchangeRichErrorTypes.sol`.
@dorothy-zbornak dorothy-zbornak force-pushed the feature/3.0/contracts/exchange/rich-revert-decoder branch from d3e8fb6 to a587aa2 Compare April 30, 2019 15:33
@dorothy-zbornak dorothy-zbornak merged commit 39790f2 into 3.0 Apr 30, 2019
@dekz dekz added this to the v3 development milestone Jun 21, 2019
@dorothy-zbornak dorothy-zbornak deleted the feature/3.0/contracts/exchange/rich-revert-decoder branch August 19, 2019 19:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants