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

EBIP-19: Misc Bug Fixes 2 #1148

Merged
merged 13 commits into from
Oct 14, 2024
Merged

EBIP-19: Misc Bug Fixes 2 #1148

merged 13 commits into from
Oct 14, 2024

Conversation

Brean0
Copy link
Contributor

@Brean0 Brean0 commented Oct 13, 2024

EBIP-19: Misc Bug Fixes 2

Submitter

Beanstalk Community Multisig

Summary

  • Update Morning Auction and Generalized Convert to fetch the L2 block number;
  • Update getAmountOut to return the correct value when Converting Unripe LP to Unripe Bean;
  • Upgrade the Gauge System to update Gauge Points and Seeds for whitelisted LP tokens regardless of the number of Beans in each Well;
  • Update the whitelisted Wells to use Multi Flow Pump v1.2.1, which properly resets the reserves in the Well when the reserves go from non-zero to zero; and
  • Update the whitelisted Wells that use the Constant Product 2 Well Function to use Constant Product 2 v1.2.1, which uses the Math library to increase precision in operations in the calcRate function.

Links

Per the process outlined in the BCM Emergency Response Procedures, the BCM can take swift action to protect Beanstalk in the event of a bug or security vulnerability.

Problem

The Morning Auction and Generalized Convert used block.number to determine how much time had passed and Convert capacity (the amount of assets that can be Converted within 1 L2 block), respectively. On Arbitrum, block.number returns the L1 block number rather than the latest block number on Arbitrum. As a result, the Morning Auction had been lasting longer than its intended duration (the entire Season) and the Convert capacity was accrued over multiple blocks rather a single block.

The getAmountOut view function is used in order to return the amount of tokens returned from a Convert. This function returned an incorrect value when attempting to fetch the amount returned from Converting Unripe LP to Unripe Bean.

Previously, if a whitelisted Well had fewer than 1000 Beans, Beanstalk assumed manipulation was occurring in the Well. When this manipulation was detected, the LP Gauge System did not change the Gauge Points nor Seeds of any whitelisted LP token. This creates liveness issues when new Wells are whitelisted, such as in BIP-50.

The Multi Flow Pump v1.2 (deployed for BIP-50) stored incorrect reserves when a Well went from non-zero to zero reserves.

The calcRate function in the Constant Product 2 Well Function failed when reserves were set to the max value.

No funds were at risk as a result of these bugs.

Solution

Update Morning Auction and Generalized Convert to fetch the L2 block number.

Update getAmountOut to return the correct value when Converting Unripe LP to Unripe Bean.

Upgrade the Gauge System to update Gauge Points and Seeds for whitelisted LP tokens regardless of the number of Beans in each Well.

Update the whitelisted Wells to use Multi Flow Pump v1.2.1, which properly resets the reserves in the Well when the reserves go from non-zero to zero.

Update the whitelisted Wells that use the Constant Product 2 Well Function to use Constant Product 2 v1.2.1, which uses the Math library to increase precision in operations in the calcRate function.

Contract Changes

Initialization Contract

The init function on the following InitMultiFlowPumpUpgrade contract is called:

Season Facet

The following SeasonFacet is being removed from Beanstalk:

The following SeasonFacet is added to Beanstalk:

SeasonFacet Function Changes

Name Selector Action Type New Functionality
getShipmentRoutes 0xfd497a68 Replace Write
setShipmentRoutes 0xf1e2dfb0 Replace Read
gm 0x64ee4b80 Replace Write
seasonTime 0xca7b7d7b Replace Read
sunrise 0xfc06d2a6 Replace Write

Season Getters Facet

The following SeasonGettersFacet is being removed from Beanstalk:

The following SeasonGettersFacet is added to Beanstalk:

SeasonGettersFacet Function Changes

Name Selector Action Type New Functionality
cumulativeCurrentDeltaB 0x89a218d2 Replace Read
getAbsBeanToMaxLpRatioChangeFromCaseId 0xe53b479e Replace Read
getAbsTemperatureChangeFromCaseId 0x3cee5dea Replace Read
getCaseData 0x8097f0ca Replace Read
getCases 0x065cb594 Replace Read
getChangeFromCaseId 0x43e0156a Replace Read
getDeltaPodDemandLowerBound 0x57801d87 Replace Read
getDeltaPodDemandUpperBound 0x70fd1b06 Replace Read
getEvaluationParameters 0xda61af62 Replace Read
getExcessivePriceThreshold 0x44fb7cc3 Replace Read
getLpToSupplyRatioUpperBound 0x1eedbfbb Replace Read
getLpToSupplyRatioOptimal 0x1f48a553 Replace Read
getLpToSupplyRatioLowerBound 0x11a8d895 Replace Read
getMaxBeanMaxLpGpPerBdvRatio 0xab843b34 Replace Read
getMinBeanMaxLpGpPerBdvRatio 0xb3c39ce5 Replace Read
getPodRateLowerBound 0xfd6d1483 Replace Read
getPodRateOptimal 0xdd9330d2 Replace Read
getPodRateUpperBound 0x08fa96d3 Replace Read
getRelBeanToMaxLpRatioChangeFromCaseId 0x35870a7a Replace Read
getRelTemperatureChangeFromCaseId 0x4d65f762 Replace Read
getSeasonStruct 0x738ad142 Replace Read
getSeasonTimestamp 0xf07f0760 Replace Read
getTargetSeasonsToCatchUp 0xcb677411 Replace Read
getWellsByDeltaB 0xbf170533 Replace Read
poolCurrentDeltaB 0x8223eac8 Replace Read
abovePeg 0x2a27c499 Replace Read
getLargestLiqWell 0xd1943f7f Replace Read
getTotalUsdLiquidity 0xbbf459a7 Replace Read
getTotalWeightedUsdLiquidity 0xf788b47c Replace Read
getTwaLiquidityForWell 0xa13a3742 Replace Read
getWeightedTwaLiquidityForWell 0x93c9e531 Replace Read
l2BlockNumber 0x8b85902b Replace Read
paused 0x5c975abb Replace Read
plentyPerRoot 0x3fccd20c Replace Read
poolDeltaB 0x471bcdbe Replace Read
rain 0x43def26e Replace Read
season 0xc50b0fb0 Replace Read
sunriseBlock 0x3b2ecb70 Replace Read
time 0x16ada547 Replace Read
totalDeltaB 0x06c499d8 Replace Read
weather 0x686b6159 Replace Read
wellOracleSnapshot 0x597490c0 Replace Read

Convert Facet

The following ConvertFacet is being removed from Beanstalk:

The following ConvertFacet is added to Beanstalk:

ConvertFacet Function Changes

Name Selector Action Type New Functionality
convert 0xb362a6e8 Add Write

Convert Getters Facet

The following ConvertGettersFacet is being removed from Beanstalk:

The following ConvertGettersFacet is added to Beanstalk:

ConvertGettersFacet Function Changes

Name Selector Action Type New Functionality
calculateDeltaBFromReserves 0xd052f0d5 Replace Read
calculateStalkPenalty 0xb325d2ef Replace Read
cappedReservesDeltaB 0x6842f2b3 Replace Read
getAmountOut 0x4aa06652 Replace Read
getMaxAmountIn 0x24dd285c Replace Read
getOverallConvertCapacity 0xf66d5589 Replace Read
getWellConvertCapacity 0xb905065b Replace Read
getUsedConvertCapacity 0xb8ff0f01 Add Read
overallCappedDeltaB 0x3e8b56f1 Replace Read
overallCurrentDeltaB 0xb267ea07 Replace Read
scaledDeltaB 0x24568abf Replace Read

Pipeline Convert Facet

The following PipelineConvertFacet is being removed from Beanstalk:

The following PipelineConvertFacet is added to Beanstalk:

PipelineConvertFacet Function Changes

Name Selector Action Type New Functionality
pipelineConvert 0xbb25c1c2 Replace Write

Field Facet

The following FieldFacet is being removed from Beanstalk:

The following FieldFacet is added to Beanstalk:

FieldFacet Function Changes

Name Selector Action Type New Functionality
activeField 0xd1eba544 Replace Read
addField 0xb94e871c Replace Write
balanceOfPods 0x9a337c1d Replace Read
fieldCount 0xbb485bbd Replace Read
getPlotIndexesFromAccount 0x253fcfb5 Replace Read
getPlotsFromAccount 0x91b24284 Replace Read
isHarvesting 0x4bea67c4 Replace Read
setActiveField 0x057c571b Replace Write
totalHarvestableForActiveField 0x237dbac5 Replace Read
harvest 0xe9bbb033 Replace Write
harvestableIndex 0xb511654d Replace Read
maxTemperature 0x7907091f Replace Read
plot 0x9ee7ea12 Replace Read
podIndex 0xccda40b9 Replace Read
remainingPods 0x56ba3e24 Replace Read
sow 0x32ab68ce Replace Write
sowWithMin 0x553030d0 Replace Write
temperature 0xadccea12 Replace Read
totalHarvestable 0x2e76f597 Replace Read
totalHarvested 0x352525a6 Replace Read
totalPods 0xf1e0a211 Replace Read
totalSoil 0x3285008a Replace Read
totalUnharvestable 0xf29ffe94 Replace Read

Beans Minted

None.

Effective

Effective immediately upon commitment, which has already happened.

Copy link

netlify bot commented Oct 13, 2024

Deploy Preview for beanstalk-ui failed.

Name Link
🔨 Latest commit a26664d
🔍 Latest deploy log https://app.netlify.com/sites/beanstalk-ui/deploys/670b43adf453b100084084e3

Copy link

netlify bot commented Oct 13, 2024

Deploy Preview for basin ready!

Name Link
🔨 Latest commit a26664d
🔍 Latest deploy log https://app.netlify.com/sites/basin/deploys/670b43adf42d84000818781c
😎 Deploy Preview https://deploy-preview-1148--basin.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@BeanstalkFarmsOperations BeanstalkFarmsOperations changed the title L2block number EBIP-19: Misc Bug Fixes #2 Oct 14, 2024
@BeanstalkFarmsOperations BeanstalkFarmsOperations changed the title EBIP-19: Misc Bug Fixes #2 EBIP-19: Misc Bug Fixes 2 Oct 14, 2024
@Brean0 Brean0 merged commit 37635af into master Oct 14, 2024
6 of 10 checks passed
@Brean0 Brean0 deleted the L2blockNumber branch October 14, 2024 22:47
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