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

Limit exec report based on gas estimate limits #56

Merged
merged 1 commit into from
Aug 9, 2024

Conversation

winder
Copy link
Contributor

@winder winder commented Aug 1, 2024

Introduce gas.EstimateProvider interface for calculating whether estimated gas requirements should prevent an exec report from being created. This PR wires this interface into the plugin via standard factory methods, but hard codes it to the evm.EstimateProvider implementation. This implementation will be moved to a separate repo in the future.

Use gas.EstimateProvider as part of the verifyReport check which is executed dynamically with different message sets to find the largest allowable report.

The new factory parameter is initialized in the ccip repo with this PR: smartcontractkit/ccip#1274

Base automatically changed from will/3-move-executed-check to ccip-develop August 5, 2024 14:01
@winder winder force-pushed the will/4-gas-estimate-limit branch 2 times, most recently from 653a1e3 to 3e98152 Compare August 7, 2024 16:30
@winder winder force-pushed the will/4-gas-estimate-limit branch from 6822ca0 to e5ee623 Compare August 7, 2024 17:02
@winder winder marked this pull request as ready for review August 7, 2024 17:03
Copy link

github-actions bot commented Aug 7, 2024

Test Coverage

Branch Coverage
will/4-gas-estimate-limit 76.3%
ccip-develop 76.0%

@@ -0,0 +1,81 @@
// Package evm provides an EVM implementation to the gas.EstimateProvider interface.
// TODO: Move this package into the EVM repo, chainlink-ccip should be chain agnostic.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lets have a ticket for this once you merge these changes 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

var data []byte = msg.Data
dataLength := len(data)

// TODO: parse max gas from ExtraArgs.
Copy link
Collaborator

Choose a reason for hiding this comment

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

To get this to work in the integration tests, for now I think we can duplicate the implementation here: https://github.com/smartcontractkit/chainlink/blob/6ab3eb5b67739ff88d3c4cf8ea125fd8273bc2b1/core/capabilities/ccip/ccipevm/helpers.go#L9-L13

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah dang actually this uses the ABI to decode. We definitely don't wanna import that here

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we can do a super hacky way for now, something like:

extraArgsNoTag := msg.ExtraArgs[4:]
// gas limit is always the first 32 bytes of ExtraArgs for EVM
gasLimitBytes := extraArgsNoTag[:32]
// convert bytes to big
gasLimit := new(big.Int).SetBytes(gasLimitBytes)

Maybe can pull this into a helper func and run a few test cases through it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was going to open a ticket and punt on that part until this function has access to go-ethereum.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's a good point - maybe implement the EVM version of this interface in the ccipevm package in chainlink? like e.g https://github.com/smartcontractkit/chainlink/blob/6ab3eb5b67739ff88d3c4cf8ea125fd8273bc2b1/core/capabilities/ccip/ccipevm/commitcodec.go#L21

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that the ExtraArgs param is abi encoded, so it should be implemented somewhere that go-ethereum can be used, so probably not the ccip / chainlink repos.

Copy link
Collaborator

Choose a reason for hiding this comment

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

go-ethereum can (at least currently) be used in ccip and chainlink

"github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"
)

const (
Copy link
Contributor

@0xnogo 0xnogo Aug 9, 2024

Choose a reason for hiding this comment

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

How this gas cost estimations were made? Any risk of drifting after smart contract change or is the precision we are looking for enough even if a gas cost increase by x%?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, there is risk of drift. The current logic is taken from here, which are only accurate for 1.5. Hopefully v2 is similar.

Copy link
Contributor

Choose a reason for hiding this comment

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

It would probably make sense to check it with onchain team when contracts are defined and audited.

@winder winder merged commit a5af749 into ccip-develop Aug 9, 2024
2 checks passed
@winder winder deleted the will/4-gas-estimate-limit branch August 9, 2024 15:24
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.

3 participants