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

Ronin Task Process #1

Closed
ducthotran2010 opened this issue May 5, 2022 · 2 comments
Closed

Ronin Task Process #1

ducthotran2010 opened this issue May 5, 2022 · 2 comments

Comments

@ducthotran2010
Copy link
Contributor

ducthotran2010 commented May 5, 2022

1. The number of tasks when sending can be optimized

tasks, err := r.store.GetTaskStore().GetPendingTasks(r.GetListener().GetName(), defaultLimitRecords)
if err != nil {
return err
}
bulkDepositTask := NewBulkTask(r.client, r.store, r.chainId, r.validator, common.HexToAddress(r.contracts[types.GATEWAY_CONTRACT]), r.txCheckInterval, defaultMaxTry, types.DEPOSIT_TASK, r.util)
bulkSubmitWithdrawalSignaturesTask := NewBulkTask(r.client, r.store, r.chainId, r.validator, common.HexToAddress(r.contracts[types.GATEWAY_CONTRACT]), r.txCheckInterval, defaultMaxTry, types.WITHDRAWAL_TASK, r.util)
ackWithdrewTasks := NewBulkTask(r.client, r.store, r.chainId, r.validator, common.HexToAddress(r.contracts[types.GATEWAY_CONTRACT]), r.txCheckInterval, defaultMaxTry, types.ACK_WITHDREW_TASK, r.util)

We are collecting the maximum number of defaultLimitRecords tasks and then filtering them as deposit tasks, withdrawal tasks, and mainchain withdrawal tasks,... This causes the number of tasks in a transaction to be not optimized (less than defaultLimitRecords).

We can select tasks by task type with the maximum number of defaultLimitRecords and then send them before moving to the other task types - as the old bridge does:
https://github.com/axieinfinity/bridge/blob/aa7bbb3b4ffb993341349a2cf8ed9254c62c8a50/src/task/task_sender.rs#L211-L221

@ducthotran2010
Copy link
Contributor Author

ducthotran2010 commented May 5, 2022

2. Correct the signing typed data way

typedData := apitypes.TypedData{
Types: apitypes.Types{
"EIP712Domain": []apitypes.Type{{Name: "verifyingContract", Type: "address"}},
"SubmitWithdrawalSignatures": []apitypes.Type{
{Name: "_withdrawal", Type: "uint256"},
},
},
Domain: apitypes.TypedDataDomain{
VerifyingContract: r.contractAddress.Hex(),
},
PrimaryType: "SubmitWithdrawalSignatures",
Message: apitypes.TypedDataMessage{
"_withdrawals": fmt.Sprintf("%#d", receipt.Id),
},
}

Recommendation:

receipt := ronEvent.Receipt
typedData := apitypes.TypedData{
	Types: apitypes.Types{
		"Receipt": []apitypes.Type{
			{ Name: "id", Type: "uint256" },
			{ Name: "kind", Type: "uint8" },
			{ Name: "mainchain", Type: "TokenOwner" },
			{ Name: "ronin", Type: "TokenOwner" },
			{ Name: "info", Type: "TokenInfo" },
		},
		"TokenOwner": []apitypes.Type{
			{ Name: "addr", Type: "address" },
			{ Name: "tokenAddr", Type: "address" },
			{ Name: "chainId", Type: "uint256" },
		},
		"TokenInfo": []apitypes.Type{
			{ Name: "erc", Type: "uint8" },
			{ Name: "id", Type: "uint256" },
			{ Name: "quantity", Type: "uint256" },
		},
	},
	Domain: apitypes.TypedDataDomain{
		Name: "MainchainGatewayV2",
		Version: "2",
		ChainId, // Mainchain network id. Set to `receipt.mainchain.chainId`
		VerifyingContract: mainchainGatewayAddr, // Please set to the mainchain gateway contract address
	},
	PrimaryType: "Receipt",
	Message: receipt,
}

Double check

  • Signing account
ACCOUNT ADDRESS
0x0E1F1dd513C07DEf50d1a4166ba7A40a7455Cae0
PRIVATE KEY
_
  • Domain:
{
  name: 'MainchainGatewayV2',
  version: '2',
  chainId: 1,
  verifyingContract: '0x2cEB55a827257a3563a8382CC92f932B0B4c072f'
}
  • Receipt:
{
  id: 0,
  kind: 0,
  mainchain: {
    addr: '0x057B3862d021f8931c96f789f2A7c4d3eA3C665f',
    tokenAddr: '0x8DdBb1105325a27931be0515E174aC0B84E86671',
    chainId: 1
  },
  ronin: {
    addr: '0x057B3862d021f8931c96f789f2A7c4d3eA3C665f',
    tokenAddr: '0x8DdBb1105325a27931be0515E174aC0B84E86671',
    chainId: 1
  },
  info: { erc: 0, id: 0, quantity: 1 }
}
  • Output:
    • r: 0x6b214a69cb666361bbfbadadd8ae04dfa21e61ccdf62921b5beba1bb6b6c8d46
    • v: 27
    • s: 0x70a5c8ec96f09a66b57a85d7201f8182824c3ece3f3a6cf60f0c2b201d4e4753
0x6b214a69cb666361bbfbadadd8ae04dfa21e61ccdf62921b5beba1bb6b6c8d4670a5c8ec96f09a66b57a85d7201f8182824c3ece3f3a6cf60f0c2b201d4e47531b

@ducthotran2010
Copy link
Contributor Author

ducthotran2010 commented May 5, 2022

3. Consider checking the receipt between which emitted event and which stored in the database

// try getting withdrawal data from database by receipt.id
withdrawal, _ := l.store.GetWithdrawalStore().GetWithdrawalById(receipt.Id.Int64())
if withdrawal != nil {
return nil
}

This will reject handling WithdrawalRequested and WithdrawalSignaturesRequested events when they are found in the database.
In some cases, the receipt in the database is not correct (due to reorg?) but when the service receives the WithdrawalSignaturesRequested events and skips them instead of providing the signatures for the correct receipts, - the withdrawals can be stuck.

@DNK90 DNK90 closed this as completed Nov 22, 2022
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

No branches or pull requests

2 participants