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

fix: limit the max size of lending item extradata can be inside the t… #405

Merged
merged 2 commits into from
Jan 29, 2024

Conversation

wjrjerome
Copy link
Collaborator

@wjrjerome wjrjerome commented Jan 27, 2024

Proposed changes

This PR is to fix the issue with no checking on the extradata field inside the trading and lending payload.

II'm taking the best guess based on the implementation of the extradata inside the trading and lending codebase.
The extraData can be one of the following data:

// from XDCxLending.go
extraData, _ := json.Marshal(struct {
	Price *big.Int
}{
        Price: XYZ,
})
// OR, from the `liquidationData` inside the same file (can also be found in order_processor.go)
liquidationData := lendingstate.LiquidationData{
	RecallAmount:      common.Big0,
	LiquidationAmount: newTrade.CollateralLockedAmount,
	CollateralPrice:   collateralPrice,
	Reason:            lendingstate.LiquidatedByPrice,
}
extraData, _ := json.Marshal(liquidationData)

// OR from the order_process.go's cancelOrder
extraData, _ := json.Marshal(struct {
   CancelFee       string
   TokenPriceInXDC string
}{
   CancelFee:       tokenCancelFee.Text(10),
   TokenPriceInXDC: tokenPriceInXDC.Text(10),
})

Based on the above struct, we can see the liquidationData is likely be the one with max length in payload.
I made theaAssumptions that each numeric value (RecallAmount, LiquidationAmount, CollateralPrice) is up to 30 digits long and the Reason field is 20 characters long, the estimated maximum size of the ExtraData JSON string in the ProcessLiquidationData function would be approximately 185 bytes.
Hence the value of 200 has been chosen to safeguard the block/tx in XDC in terms of sizes.

Types of changes

What types of changes does your code introduce to XDC network?
Put an in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)
  • Regular KTLO or any of the maintaince work. e.g code style
  • CICD Improvement

Impacted Components

Which part of the codebase this PR will touch base on,

Put an in the boxes that apply

  • Consensus
  • Account
  • Network
  • Geth
  • Smart Contract
  • External components
  • Not sure (Please specify below)

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

  • This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
  • Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
  • Tested the backwards compatibility.
  • Tested with XDC nodes running this version co-exist with those running the previous version.
  • Relevant documentation has been updated as part of this PR
  • N/A

@wjrjerome wjrjerome force-pushed the limit-lending-tx-extradata-size branch from d8cb98f to 789dc85 Compare January 27, 2024 12:10
@@ -27,6 +27,7 @@ const (
LendingStatusCancelled = "CANCELLED"
Market = "MO"
Limit = "LO"
MaxLendingExtraDataSize = 200
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you put the math explanation at this comment please.

Based on the above struct, we can see the liquidationData is likely be the one with max length in payload.
I made theaAssumptions that each numeric value (RecallAmount, LiquidationAmount, CollateralPrice) is up to 30 digits long and the Reason field is 20 characters long, the estimated maximum size of the ExtraData JSON string in the ProcessLiquidationData function would be approximately 185 bytes.
Hence the value of 200 has been chosen to safeguard the block/tx in XDC in terms of sizes.

@wjrjerome wjrjerome merged commit 95e108c into dev-upgrade Jan 29, 2024
2 checks passed
@wjrjerome wjrjerome deleted the limit-lending-tx-extradata-size branch January 29, 2024 00:31
@liam-lai liam-lai mentioned this pull request Feb 4, 2024
19 tasks
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

Successfully merging this pull request may close these issues.

2 participants