Skip to content

Commit bdf58bb

Browse files
committed
fix: celo unstake methods collide with weth unwrap
Ticket: SC-4630
1 parent ad52c5c commit bdf58bb

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

modules/abstract-eth/src/lib/transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class Transaction extends BaseTransaction {
9090
if (txData.id) {
9191
this._id = txData.id;
9292
}
93-
this._type = classifyTransaction(txData.data);
93+
this._type = classifyTransaction(txData.data, this._coinConfig.name);
9494

9595
// reset arrays to empty to ensure that they are only set with one set of fresh values
9696
this._inputs = [];

modules/abstract-eth/src/lib/transactionBuilder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
183183
* @param {boolean} isFirstSigner if the transaction is being signed by the first signer
184184
*/
185185
protected loadBuilderInput(transactionJson: TxData, isFirstSigner?: boolean): void {
186-
const decodedType = classifyTransaction(transactionJson.data);
186+
const decodedType = classifyTransaction(transactionJson.data, this._coinConfig.name);
187187
this.type(decodedType);
188188
this.counter(transactionJson.nonce);
189189
this.value(transactionJson.value);

modules/abstract-eth/src/lib/utils.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,22 +664,41 @@ export function decodeFlushTokensData(data: string, to?: string): FlushTokensDat
664664
* @param {string} data The data to classify the transaction with
665665
* @returns {TransactionType} The classified transaction type
666666
*/
667-
export function classifyTransaction(data: string): TransactionType {
667+
export function classifyTransaction(data: string, coinName?: string): TransactionType {
668668
if (data.length < 10) {
669669
// contract calls must have at least 4 bytes (method id) and '0x'
670670
// if it doesn't have enough data to be a contract call it must be a single sig send
671671
return TransactionType.SingleSigSend;
672672
}
673673

674674
// TODO(STLX-1970): validate if we are going to constraint to some methods allowed
675-
let transactionType = transactionTypesMap[data.slice(0, 10).toLowerCase()];
675+
const methodId = data.slice(0, 10).toLowerCase();
676+
const isCeloStaking =
677+
CELO_STAKING_METHOD_IDS.has(methodId) && coinName && (coinName === 'celo' || coinName === 'tcelo');
678+
let transactionType = transactionTypesMap[methodId];
679+
680+
if (transactionType !== undefined) {
681+
if (!isCeloStaking && CELO_STAKING_METHOD_IDS.has(methodId)) {
682+
transactionType = TransactionType.ContractCall;
683+
}
684+
}
685+
676686
if (transactionType === undefined) {
677687
transactionType = TransactionType.ContractCall;
678688
}
679689

680690
return transactionType;
681691
}
682692

693+
const CELO_STAKING_METHOD_IDS = new Set([
694+
LockMethodId,
695+
VoteMethodId,
696+
ActivateMethodId,
697+
UnvoteMethodId,
698+
UnlockMethodId,
699+
WithdrawMethodId,
700+
]);
701+
683702
/**
684703
* A transaction types map according to the starting part of the encoded data
685704
*/

modules/abstract-eth/test/unit/utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import {
44
flushERC1155TokensData,
55
decodeFlushERC721TokensData,
66
decodeFlushERC1155TokensData,
7+
classifyTransaction,
78
} from '../../src/lib/utils';
9+
import { TransactionType } from '@bitgo/sdk-core';
810

911
describe('Abstract ETH Utils', () => {
1012
describe('ERC721 Flush Functions', () => {
@@ -228,4 +230,20 @@ describe('Abstract ETH Utils', () => {
228230
decoded1155.tokenAddress.toLowerCase().should.equal(tokenAddressChecksum.toLowerCase());
229231
});
230232
});
233+
234+
describe('classifyTransaction', () => {
235+
describe('CELO Staking Method ID Collision', () => {
236+
const WITHDRAW_DATA = '0x2e1a7d4d0000000000000000000000000000000000000000000000000000000005f5e100';
237+
238+
it('should classify as StakingWithdraw on CELO chains', () => {
239+
classifyTransaction(WITHDRAW_DATA, 'celo').should.equal(TransactionType.StakingWithdraw);
240+
classifyTransaction(WITHDRAW_DATA, 'tcelo').should.equal(TransactionType.StakingWithdraw);
241+
});
242+
243+
it('should classify as ContractCall on non-CELO chains', () => {
244+
classifyTransaction(WITHDRAW_DATA, 'eth').should.equal(TransactionType.ContractCall);
245+
classifyTransaction(WITHDRAW_DATA).should.equal(TransactionType.ContractCall);
246+
});
247+
});
248+
});
231249
});

0 commit comments

Comments
 (0)