-
Notifications
You must be signed in to change notification settings - Fork 369
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
Adds backwards compatibility in UsingPrecompile
contract.
#11236
base: release/core-contracts/12
Are you sure you want to change the base?
Adds backwards compatibility in UsingPrecompile
contract.
#11236
Conversation
Adds backwards compatibility in
|
Severity Level | Results | |
---|---|---|
Contracts | Critical High Medium Low Note Total |
3 2 0 14 43 62 |
Dependencies | Critical High Medium Low Note Total |
0 0 0 0 0 0 |
For more details view the full report in OpenZeppelin Code Inspector
As of 50bec5c Testing is not fully implemented for registry functions, but the plan was to use stCELO only uses To get the epoch info based on block number, I used binary search to avoid looping through all the epoch 1x1. This was required for We could further improve the compute cost by introducing a mapping of blocksToEpoch,
but that would be a more complex change and increase the gas cost of processing an epoch as we'd have to store this info during processing. NOTE: Not all functions have backwards compatibility. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but there's a few, potentially very impactful, gas optimizations possible. There's no need to read the entire elected
array into memory when we only need one field of the Epoch struct, or just one of the elected addresses. These should be fairly simple changes that would reduce the number of SLOAD
s by a factor of ~100 where relevant.
require(success, "error calling numberValidatorsInCurrentSet precompile"); | ||
return getUint256FromBytes(out, 0); | ||
if (isL2()) { | ||
return getEpochManager().getElected().length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto, implementing this in EpochManager should save gas since the whole elected
array won't be read into memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The limitation in implementing this whole function in EpochManager
, is to avoid importing the UsingPrecompiles
contract.
I created an EpochManager
function that returns the number instead of getting the elected array and getting its length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to fix all precompiles in all contracts
Updated this PR based on our last sync.
|
As of commit 681a858 To minimize the gas cost of reading epoch info based on block number, the mapping of That being said, it would still be good to run a gas cost benchmark to know if it will be prohibitive. usingPrecompile backwards compatibility has been added for |
…backward-compatibility-fix
* @return startTimestamp The starting timestamp of the given block number. | ||
* @return rewardsBlock The reward block of the given block number. | ||
*/ | ||
function _getEpochByBlockNumber( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is very likely to run out of gas, is it (and the functions that use it) really needed?
I also think that it has quite some edge cases, would be difficult to test them all.
…backward-compatibility-fix
… to be in use by external parties
Description
Updated
UsingPrecompile
contract to maintain backwards compatibility after L2 migration.Fucntions that maintained backwards compatibility query the required information from the
EpochManager
contract instead of the precompiles.Other changes
Was required to add the list of elected validators to the
Epoch
struct of the EpochManager contract to keep the historical list of elected validators at a given epoch number.Tested
Added unit test.
Related issues
Backwards compatibility
for some select functions