@0x/zero-ex: Address CD post-audit feedback.

Add `LogMetadataTransformer`.
This commit is contained in:
Lawrence Forman 2020-08-19 12:50:20 -04:00 committed by Lawrence Forman
parent 14d6330b40
commit 71700e69af
17 changed files with 73 additions and 35 deletions

View File

@ -17,6 +17,14 @@
{ {
"note": "Refund unused protocol fees to `refundReceiver` in FQT", "note": "Refund unused protocol fees to `refundReceiver` in FQT",
"pr": 2657 "pr": 2657
},
{
"note": "Address CD post-audit feedback",
"pr": 2657
},
{
"note": "Add `LogMetadataTransformer`",
"pr": 2657
} }
] ]
}, },

View File

@ -77,6 +77,7 @@ contract Bootstrap is
/// @dev Self-destructs this contract. /// @dev Self-destructs this contract.
/// Can only be called by the deployer. /// Can only be called by the deployer.
function die() external { function die() external {
assert(address(this) == _implementation);
if (msg.sender != _deployer) { if (msg.sender != _deployer) {
LibProxyRichErrors.InvalidDieCallerError(msg.sender, _deployer).rrevert(); LibProxyRichErrors.InvalidDieCallerError(msg.sender, _deployer).rrevert();
} }

View File

@ -271,7 +271,9 @@ contract MetaTransactions is
_validateMetaTransaction(state); _validateMetaTransaction(state);
// Mark the transaction executed. // Mark the transaction executed by storing the block at which it was executed.
// Currently the block number just indicates that the mtx was executed and
// serves no other purpose from within this contract.
LibMetaTransactionsStorage.getStorage() LibMetaTransactionsStorage.getStorage()
.mtxHashToExecutedBlockNumber[state.hash] = block.number; .mtxHashToExecutedBlockNumber[state.hash] = block.number;

View File

@ -44,10 +44,6 @@ contract Ownable is
using LibRichErrorsV06 for bytes; using LibRichErrorsV06 for bytes;
constructor() public FixinCommon() {
// solhint-disable-next-line no-empty-blocks
}
/// @dev Initializes this feature. The intial owner will be set to this (ZeroEx) /// @dev Initializes this feature. The intial owner will be set to this (ZeroEx)
/// to allow the bootstrappers to call `extend()`. Ownership should be /// to allow the bootstrappers to call `extend()`. Ownership should be
/// transferred to the real owner by the bootstrapper after /// transferred to the real owner by the bootstrapper after

View File

@ -49,10 +49,6 @@ contract SignatureValidator is
/// @dev Version of this feature. /// @dev Version of this feature.
uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 0, 0); uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 0, 0);
constructor() public FixinCommon() {
// solhint-disable-next-line no-empty-blocks
}
/// @dev Initialize and register this feature. /// @dev Initialize and register this feature.
/// Should be delegatecalled by `Migrate.migrate()`. /// Should be delegatecalled by `Migrate.migrate()`.
/// @return success `LibMigrate.SUCCESS` on success. /// @return success `LibMigrate.SUCCESS` on success.

View File

@ -42,10 +42,6 @@ contract SimpleFunctionRegistry is
using LibRichErrorsV06 for bytes; using LibRichErrorsV06 for bytes;
constructor() public FixinCommon() {
// solhint-disable-next-line no-empty-blocks
}
/// @dev Initializes this feature, registering its own functions. /// @dev Initializes this feature, registering its own functions.
/// @return success Magic bytes if successful. /// @return success Magic bytes if successful.
function bootstrap() function bootstrap()

View File

@ -48,10 +48,6 @@ contract TokenSpender is
using LibRichErrorsV06 for bytes; using LibRichErrorsV06 for bytes;
constructor() public FixinCommon() {
// solhint-disable-next-line no-empty-blocks
}
/// @dev Initialize and register this feature. Should be delegatecalled /// @dev Initialize and register this feature. Should be delegatecalled
/// into during a `Migrate.migrate()`. /// into during a `Migrate.migrate()`.
/// @param allowanceTarget An `allowanceTarget` instance, configured to have /// @param allowanceTarget An `allowanceTarget` instance, configured to have

View File

@ -61,10 +61,6 @@ contract TransformERC20 is
/// @dev Version of this feature. /// @dev Version of this feature.
uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 2, 0); uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 2, 0);
constructor() public FixinCommon() {
// solhint-disable-next-line no-empty-blocks
}
/// @dev Initialize and register this feature. /// @dev Initialize and register this feature.
/// Should be delegatecalled by `Migrate.migrate()`. /// Should be delegatecalled by `Migrate.migrate()`.
/// @param transformerDeployer The trusted deployer for transformers. /// @param transformerDeployer The trusted deployer for transformers.
@ -257,16 +253,15 @@ contract TransformERC20 is
// Compute how much output token has been transferred to the taker. // Compute how much output token has been transferred to the taker.
state.takerOutputTokenBalanceAfter = state.takerOutputTokenBalanceAfter =
LibERC20Transformer.getTokenBalanceOf(args.outputToken, args.taker); LibERC20Transformer.getTokenBalanceOf(args.outputToken, args.taker);
if (state.takerOutputTokenBalanceAfter > state.takerOutputTokenBalanceBefore) { if (state.takerOutputTokenBalanceAfter < state.takerOutputTokenBalanceBefore) {
outputTokenAmount = state.takerOutputTokenBalanceAfter.safeSub(
state.takerOutputTokenBalanceBefore
);
} else if (state.takerOutputTokenBalanceAfter < state.takerOutputTokenBalanceBefore) {
LibTransformERC20RichErrors.NegativeTransformERC20OutputError( LibTransformERC20RichErrors.NegativeTransformERC20OutputError(
address(args.outputToken), address(args.outputToken),
state.takerOutputTokenBalanceBefore - state.takerOutputTokenBalanceAfter state.takerOutputTokenBalanceBefore - state.takerOutputTokenBalanceAfter
).rrevert(); ).rrevert();
} }
outputTokenAmount = state.takerOutputTokenBalanceAfter.safeSub(
state.takerOutputTokenBalanceBefore
);
// Ensure enough output token has been sent to the taker. // Ensure enough output token has been sent to the taker.
if (outputTokenAmount < args.minOutputTokenAmount) { if (outputTokenAmount < args.minOutputTokenAmount) {
LibTransformERC20RichErrors.IncompleteTransformERC20Error( LibTransformERC20RichErrors.IncompleteTransformERC20Error(

View File

@ -32,7 +32,6 @@ import "./LibERC20Transformer.sol";
contract AffiliateFeeTransformer is contract AffiliateFeeTransformer is
Transformer Transformer
{ {
// solhint-disable no-empty-blocks
using LibRichErrorsV06 for bytes; using LibRichErrorsV06 for bytes;
using LibSafeMathV06 for uint256; using LibSafeMathV06 for uint256;
using LibERC20Transformer for IERC20TokenV06; using LibERC20Transformer for IERC20TokenV06;
@ -51,12 +50,6 @@ contract AffiliateFeeTransformer is
uint256 private constant MAX_UINT256 = uint256(-1); uint256 private constant MAX_UINT256 = uint256(-1);
/// @dev Create this contract.
constructor()
public
Transformer()
{}
/// @dev Transfers tokens to recipients. /// @dev Transfers tokens to recipients.
/// @param context Context information. /// @param context Context information.
/// @return success The success bytes (`LibERC20Transformer.TRANSFORMER_SUCCESS`). /// @return success The success bytes (`LibERC20Transformer.TRANSFORMER_SUCCESS`).

View File

@ -0,0 +1,46 @@
/*
Copyright 2020 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.6.5;
pragma experimental ABIEncoderV2;
import "./Transformer.sol";
import "./LibERC20Transformer.sol";
/// @dev A transformer that just emits an event with an arbitrary byte payload.
contract LogMetadataTransformer is
Transformer
{
event TransformerMetadata(bytes32 callDataHash, address sender, address taker, bytes data);
/// @dev Maximum uint256 value.
uint256 private constant MAX_UINT256 = uint256(-1);
/// @dev Emits an event.
/// @param context Context information.
/// @return success The success bytes (`LibERC20Transformer.TRANSFORMER_SUCCESS`).
function transform(TransformContext calldata context)
external
override
returns (bytes4 success)
{
emit TransformerMetadata(context.callDataHash, context.sender, context.taker, context.data);
return LibERC20Transformer.TRANSFORMER_SUCCESS;
}
}

View File

@ -39,9 +39,9 @@
"publish:private": "yarn build && gitpkg publish" "publish:private": "yarn build && gitpkg publish"
}, },
"config": { "config": {
"publicInterfaceContracts": "IZeroEx,ZeroEx,FullMigration,InitialMigration,IFlashWallet,IAllowanceTarget,IERC20Transformer,IOwnable,ISimpleFunctionRegistry,ITokenSpender,ITransformERC20,FillQuoteTransformer,PayTakerTransformer,WethTransformer,Ownable,SimpleFunctionRegistry,TransformERC20,TokenSpender,AffiliateFeeTransformer,SignatureValidator,MetaTransactions", "publicInterfaceContracts": "IZeroEx,ZeroEx,FullMigration,InitialMigration,IFlashWallet,IAllowanceTarget,IERC20Transformer,IOwnable,ISimpleFunctionRegistry,ITokenSpender,ITransformERC20,FillQuoteTransformer,PayTakerTransformer,WethTransformer,Ownable,SimpleFunctionRegistry,TransformERC20,TokenSpender,AffiliateFeeTransformer,SignatureValidator,MetaTransactions,LogMetadataTransformer",
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.", "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.",
"abis": "./test/generated-artifacts/@(AffiliateFeeTransformer|AllowanceTarget|Bootstrap|FillQuoteTransformer|FixinCommon|FixinEIP712|FixinGasToken|FixinReentrancyGuard|FlashWallet|FullMigration|IAllowanceTarget|IBootstrap|IERC20Bridge|IERC20Transformer|IExchange|IFeature|IFlashWallet|IGasToken|IMetaTransactions|IOwnable|ISignatureValidator|ISimpleFunctionRegistry|ITestSimpleFunctionRegistryFeature|ITokenSpender|ITransformERC20|IZeroEx|InitialMigration|LibBootstrap|LibCommonRichErrors|LibERC20Transformer|LibMetaTransactionsRichErrors|LibMetaTransactionsStorage|LibMigrate|LibOwnableRichErrors|LibOwnableStorage|LibProxyRichErrors|LibProxyStorage|LibReentrancyGuardStorage|LibSignatureRichErrors|LibSignedCallData|LibSimpleFunctionRegistryRichErrors|LibSimpleFunctionRegistryStorage|LibSpenderRichErrors|LibStorage|LibTokenSpenderStorage|LibTransformERC20RichErrors|LibTransformERC20Storage|LibWalletRichErrors|MetaTransactions|Ownable|PayTakerTransformer|SignatureValidator|SimpleFunctionRegistry|TestCallTarget|TestDelegateCaller|TestFillQuoteTransformerBridge|TestFillQuoteTransformerExchange|TestFillQuoteTransformerHost|TestFullMigration|TestInitialMigration|TestMetaTransactionsTransformERC20Feature|TestMigrator|TestMintTokenERC20Transformer|TestMintableERC20Token|TestSimpleFunctionRegistryFeatureImpl1|TestSimpleFunctionRegistryFeatureImpl2|TestTokenSpender|TestTokenSpenderERC20Token|TestTransformERC20|TestTransformerBase|TestTransformerDeployerTransformer|TestTransformerHost|TestWeth|TestWethTransformerHost|TestZeroExFeature|TokenSpender|TransformERC20|Transformer|TransformerDeployer|WethTransformer|ZeroEx).json" "abis": "./test/generated-artifacts/@(AffiliateFeeTransformer|AllowanceTarget|Bootstrap|FillQuoteTransformer|FixinCommon|FixinEIP712|FixinGasToken|FixinReentrancyGuard|FlashWallet|FullMigration|IAllowanceTarget|IBootstrap|IERC20Bridge|IERC20Transformer|IExchange|IFeature|IFlashWallet|IGasToken|IMetaTransactions|IOwnable|ISignatureValidator|ISimpleFunctionRegistry|ITestSimpleFunctionRegistryFeature|ITokenSpender|ITransformERC20|IZeroEx|InitialMigration|LibBootstrap|LibCommonRichErrors|LibERC20Transformer|LibMetaTransactionsRichErrors|LibMetaTransactionsStorage|LibMigrate|LibOwnableRichErrors|LibOwnableStorage|LibProxyRichErrors|LibProxyStorage|LibReentrancyGuardStorage|LibSignatureRichErrors|LibSignedCallData|LibSimpleFunctionRegistryRichErrors|LibSimpleFunctionRegistryStorage|LibSpenderRichErrors|LibStorage|LibTokenSpenderStorage|LibTransformERC20RichErrors|LibTransformERC20Storage|LibWalletRichErrors|LogMetadataTransformer|MetaTransactions|Ownable|PayTakerTransformer|SignatureValidator|SimpleFunctionRegistry|TestCallTarget|TestDelegateCaller|TestFillQuoteTransformerBridge|TestFillQuoteTransformerExchange|TestFillQuoteTransformerHost|TestFullMigration|TestInitialMigration|TestMetaTransactionsTransformERC20Feature|TestMigrator|TestMintTokenERC20Transformer|TestMintableERC20Token|TestSimpleFunctionRegistryFeatureImpl1|TestSimpleFunctionRegistryFeatureImpl2|TestTokenSpender|TestTokenSpenderERC20Token|TestTransformERC20|TestTransformerBase|TestTransformerDeployerTransformer|TestTransformerHost|TestWeth|TestWethTransformerHost|TestZeroExFeature|TokenSpender|TransformERC20|Transformer|TransformerDeployer|WethTransformer|ZeroEx).json"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -17,6 +17,7 @@ import * as ISimpleFunctionRegistry from '../generated-artifacts/ISimpleFunction
import * as ITokenSpender from '../generated-artifacts/ITokenSpender.json'; import * as ITokenSpender from '../generated-artifacts/ITokenSpender.json';
import * as ITransformERC20 from '../generated-artifacts/ITransformERC20.json'; import * as ITransformERC20 from '../generated-artifacts/ITransformERC20.json';
import * as IZeroEx from '../generated-artifacts/IZeroEx.json'; import * as IZeroEx from '../generated-artifacts/IZeroEx.json';
import * as LogMetadataTransformer from '../generated-artifacts/LogMetadataTransformer.json';
import * as MetaTransactions from '../generated-artifacts/MetaTransactions.json'; import * as MetaTransactions from '../generated-artifacts/MetaTransactions.json';
import * as Ownable from '../generated-artifacts/Ownable.json'; import * as Ownable from '../generated-artifacts/Ownable.json';
import * as PayTakerTransformer from '../generated-artifacts/PayTakerTransformer.json'; import * as PayTakerTransformer from '../generated-artifacts/PayTakerTransformer.json';
@ -48,4 +49,5 @@ export const artifacts = {
AffiliateFeeTransformer: AffiliateFeeTransformer as ContractArtifact, AffiliateFeeTransformer: AffiliateFeeTransformer as ContractArtifact,
SignatureValidator: SignatureValidator as ContractArtifact, SignatureValidator: SignatureValidator as ContractArtifact,
MetaTransactions: MetaTransactions as ContractArtifact, MetaTransactions: MetaTransactions as ContractArtifact,
LogMetadataTransformer: LogMetadataTransformer as ContractArtifact,
}; };

View File

@ -9,6 +9,7 @@ export {
ITokenSpenderContract, ITokenSpenderContract,
ITransformERC20Contract, ITransformERC20Contract,
IZeroExContract, IZeroExContract,
LogMetadataTransformerContract,
PayTakerTransformerContract, PayTakerTransformerContract,
WethTransformerContract, WethTransformerContract,
ZeroExContract, ZeroExContract,

View File

@ -15,6 +15,7 @@ export * from '../generated-wrappers/i_token_spender';
export * from '../generated-wrappers/i_transform_erc20'; export * from '../generated-wrappers/i_transform_erc20';
export * from '../generated-wrappers/i_zero_ex'; export * from '../generated-wrappers/i_zero_ex';
export * from '../generated-wrappers/initial_migration'; export * from '../generated-wrappers/initial_migration';
export * from '../generated-wrappers/log_metadata_transformer';
export * from '../generated-wrappers/meta_transactions'; export * from '../generated-wrappers/meta_transactions';
export * from '../generated-wrappers/ownable'; export * from '../generated-wrappers/ownable';
export * from '../generated-wrappers/pay_taker_transformer'; export * from '../generated-wrappers/pay_taker_transformer';

View File

@ -53,6 +53,7 @@ import * as LibTokenSpenderStorage from '../test/generated-artifacts/LibTokenSpe
import * as LibTransformERC20RichErrors from '../test/generated-artifacts/LibTransformERC20RichErrors.json'; import * as LibTransformERC20RichErrors from '../test/generated-artifacts/LibTransformERC20RichErrors.json';
import * as LibTransformERC20Storage from '../test/generated-artifacts/LibTransformERC20Storage.json'; import * as LibTransformERC20Storage from '../test/generated-artifacts/LibTransformERC20Storage.json';
import * as LibWalletRichErrors from '../test/generated-artifacts/LibWalletRichErrors.json'; import * as LibWalletRichErrors from '../test/generated-artifacts/LibWalletRichErrors.json';
import * as LogMetadataTransformer from '../test/generated-artifacts/LogMetadataTransformer.json';
import * as MetaTransactions from '../test/generated-artifacts/MetaTransactions.json'; import * as MetaTransactions from '../test/generated-artifacts/MetaTransactions.json';
import * as Ownable from '../test/generated-artifacts/Ownable.json'; import * as Ownable from '../test/generated-artifacts/Ownable.json';
import * as PayTakerTransformer from '../test/generated-artifacts/PayTakerTransformer.json'; import * as PayTakerTransformer from '../test/generated-artifacts/PayTakerTransformer.json';
@ -139,6 +140,7 @@ export const artifacts = {
FillQuoteTransformer: FillQuoteTransformer as ContractArtifact, FillQuoteTransformer: FillQuoteTransformer as ContractArtifact,
IERC20Transformer: IERC20Transformer as ContractArtifact, IERC20Transformer: IERC20Transformer as ContractArtifact,
LibERC20Transformer: LibERC20Transformer as ContractArtifact, LibERC20Transformer: LibERC20Transformer as ContractArtifact,
LogMetadataTransformer: LogMetadataTransformer as ContractArtifact,
PayTakerTransformer: PayTakerTransformer as ContractArtifact, PayTakerTransformer: PayTakerTransformer as ContractArtifact,
Transformer: Transformer as ContractArtifact, Transformer: Transformer as ContractArtifact,
WethTransformer: WethTransformer as ContractArtifact, WethTransformer: WethTransformer as ContractArtifact,

View File

@ -51,6 +51,7 @@ export * from '../test/generated-wrappers/lib_token_spender_storage';
export * from '../test/generated-wrappers/lib_transform_erc20_rich_errors'; export * from '../test/generated-wrappers/lib_transform_erc20_rich_errors';
export * from '../test/generated-wrappers/lib_transform_erc20_storage'; export * from '../test/generated-wrappers/lib_transform_erc20_storage';
export * from '../test/generated-wrappers/lib_wallet_rich_errors'; export * from '../test/generated-wrappers/lib_wallet_rich_errors';
export * from '../test/generated-wrappers/log_metadata_transformer';
export * from '../test/generated-wrappers/meta_transactions'; export * from '../test/generated-wrappers/meta_transactions';
export * from '../test/generated-wrappers/ownable'; export * from '../test/generated-wrappers/ownable';
export * from '../test/generated-wrappers/pay_taker_transformer'; export * from '../test/generated-wrappers/pay_taker_transformer';

View File

@ -15,6 +15,7 @@
"generated-artifacts/ITransformERC20.json", "generated-artifacts/ITransformERC20.json",
"generated-artifacts/IZeroEx.json", "generated-artifacts/IZeroEx.json",
"generated-artifacts/InitialMigration.json", "generated-artifacts/InitialMigration.json",
"generated-artifacts/LogMetadataTransformer.json",
"generated-artifacts/MetaTransactions.json", "generated-artifacts/MetaTransactions.json",
"generated-artifacts/Ownable.json", "generated-artifacts/Ownable.json",
"generated-artifacts/PayTakerTransformer.json", "generated-artifacts/PayTakerTransformer.json",
@ -72,6 +73,7 @@
"test/generated-artifacts/LibTransformERC20RichErrors.json", "test/generated-artifacts/LibTransformERC20RichErrors.json",
"test/generated-artifacts/LibTransformERC20Storage.json", "test/generated-artifacts/LibTransformERC20Storage.json",
"test/generated-artifacts/LibWalletRichErrors.json", "test/generated-artifacts/LibWalletRichErrors.json",
"test/generated-artifacts/LogMetadataTransformer.json",
"test/generated-artifacts/MetaTransactions.json", "test/generated-artifacts/MetaTransactions.json",
"test/generated-artifacts/Ownable.json", "test/generated-artifacts/Ownable.json",
"test/generated-artifacts/PayTakerTransformer.json", "test/generated-artifacts/PayTakerTransformer.json",