Skip to content

Commit

Permalink
fix: Incorrectly converting byte parameters (#232)
Browse files Browse the repository at this point in the history
* fix: Remove bytes conversion

* fix: domain salt param position

* fix: Remove bytes conversion when saving in DB

* fix: tests

* fix: revert domain order

* fix: revert store extra in db

* fix: prettier

---------

Co-authored-by: Gabriel Diaz <[email protected]>
  • Loading branch information
LautaroPetaccio and cyaiox authored Dec 22, 2024
1 parent adc094d commit 6072e71
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
21 changes: 7 additions & 14 deletions src/logic/trades/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {
Contract,
TypedDataField,
hexlify,
TypedDataDomain,
verifyTypedData,
toBeArray,
toUtf8Bytes,
zeroPadValue,
JsonRpcProvider
} from 'ethers'
import { Contract, TypedDataField, TypedDataDomain, verifyTypedData, toBeArray, zeroPadValue, JsonRpcProvider } from 'ethers'
import { ChainId, ERC721TradeAsset, Network, TradeAsset, TradeAssetType, TradeCreation } from '@dcl/schemas'
import { ContractData, ContractName, getContract } from 'decentraland-transactions'
import { InvalidECDSASignatureError, MarketplaceContractNotFound } from '../../ports/trades/errors'
Expand Down Expand Up @@ -98,21 +88,24 @@ export function validateTradeSignature(trade: TradeCreation, signer: string): bo
externalChecks: trade.checks.externalChecks?.map(externalCheck => ({
contractAddress: externalCheck.contractAddress,
selector: externalCheck.selector,
value: hexlify(toUtf8Bytes(externalCheck.value)),
// '0x' is the default value for the value bytes (0 bytes)
value: externalCheck.value ? externalCheck.value : '0x',
required: externalCheck.required
}))
},
sent: trade.sent.map(asset => ({
assetType: asset.assetType,
contractAddress: asset.contractAddress,
value: getValueFromTradeAsset(asset),
extra: hexlify(toUtf8Bytes(asset.extra))
// '0x' is the default value for extra bytes (0 bytes)
extra: asset.extra ? asset.extra : '0x'
})),
received: trade.received.map(asset => ({
assetType: asset.assetType,
contractAddress: asset.contractAddress,
value: getValueFromTradeAsset(asset),
extra: hexlify(toUtf8Bytes(asset.extra)),
// '0x' is the default value for extra bytes (0 bytes)
extra: asset.extra ? asset.extra : '0x',
beneficiary: asset.beneficiary
}))
}
Expand Down
8 changes: 4 additions & 4 deletions test/unit/trades-component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ describe('when adding a new trade', () => {
assetType: TradeAssetType.ERC20,
contractAddress: '0xabcdef',
amount: '2',
extra: ''
extra: '0x'
}
],
received: [
{
assetType: TradeAssetType.ERC721,
contractAddress: '0x789abc',
tokenId: '1',
extra: '',
extra: '0x',
beneficiary: '0x9876543210'
}
]
Expand Down Expand Up @@ -335,15 +335,15 @@ describe('when getting a trade', () => {
assetType: TradeAssetType.ERC20,
contractAddress: '0xabcdef',
amount: '2',
extra: ''
extra: '0x'
}
],
received: [
{
assetType: TradeAssetType.ERC721,
contractAddress: '0x789abc',
tokenId: '1',
extra: '',
extra: '0x',
beneficiary: '0x9876543210'
}
]
Expand Down
6 changes: 3 additions & 3 deletions test/unit/trades-logic.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { HDNodeWallet, TypedDataDomain, Wallet, zeroPadValue, toBeArray, hexlify, toUtf8Bytes } from 'ethers'
import { HDNodeWallet, TypedDataDomain, Wallet, zeroPadValue, toBeArray } from 'ethers'
import { ChainId, Network, TradeAssetType, TradeCreation, TradeType } from '@dcl/schemas'
import { ContractData, ContractName, getContract } from 'decentraland-transactions'
import { fromMillisecondsToSeconds } from '../../src/logic/date'
Expand Down Expand Up @@ -82,13 +82,13 @@ describe('when verifying the trade signature', () => {
assetType: asset.assetType,
contractAddress: asset.contractAddress,
value: getValueFromTradeAsset(asset),
extra: hexlify(toUtf8Bytes(asset.extra))
extra: asset.extra
})),
received: trade.received.map(asset => ({
assetType: asset.assetType,
contractAddress: asset.contractAddress,
value: getValueFromTradeAsset(asset),
extra: hexlify(toUtf8Bytes(asset.extra)),
extra: asset.extra,
beneficiary: asset.beneficiary
}))
}
Expand Down

0 comments on commit 6072e71

Please sign in to comment.