-
Notifications
You must be signed in to change notification settings - Fork 1.8k
core/vm: reject duplicate bridge validators at Pasteur #3623
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
Merged
+334
−9
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ee3f3c6
core/vm: reject duplicate bridge validators at Mendel
MatusKysel bb0b2cf
core/vm: enforce duplicate bridge validator checks at Pasteur
MatusKysel fb42601
core/vm: reject duplicate bridge validators at Pasteur
zlacfzy 62ba5ac
core/vm: reject duplicate bridge validators at Pasteur
zlacfzy 141f190
core/vm: reject duplicate bridge validators at Pasteur
zlacfzy fdd6502
contracts.go: update precompile
zlacfzy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -350,13 +350,21 @@ var PrecompiledContractsOsaka = PrecompiledContracts{ | |
| common.BytesToAddress([]byte{0x1, 0x00}): &p256Verify{eip7951: true}, | ||
| } | ||
|
|
||
| var PrecompiledContractsPasteur = func() PrecompiledContracts { | ||
| precompiles := maps.Clone(PrecompiledContractsOsaka) | ||
| precompiles[common.BytesToAddress([]byte{0x66})] = &blsSignatureVerifyPasteur{} | ||
| precompiles[common.BytesToAddress([]byte{0x67})] = &cometBFTLightBlockValidatePasteur{} | ||
| return precompiles | ||
| }() | ||
|
|
||
| // PrecompiledContractsP256Verify contains the precompiled Ethereum | ||
| // contract specified in EIP-7212. This is exported for testing purposes. | ||
| var PrecompiledContractsP256Verify = PrecompiledContracts{ | ||
| common.BytesToAddress([]byte{0x1, 0x00}): &p256Verify{}, | ||
| } | ||
|
|
||
| var ( | ||
| PrecompiledAddressesPasteur []common.Address | ||
| PrecompiledAddressesOsaka []common.Address | ||
| PrecompiledAddressesPrague []common.Address | ||
| PrecompiledAddressesHaber []common.Address | ||
|
|
@@ -417,6 +425,9 @@ func init() { | |
| for k := range PrecompiledContractsPrague { | ||
| PrecompiledAddressesPrague = append(PrecompiledAddressesPrague, k) | ||
| } | ||
| for k := range PrecompiledContractsPasteur { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move after PrecompiledContractsOsaka |
||
| PrecompiledAddressesPasteur = append(PrecompiledAddressesPasteur, k) | ||
| } | ||
| for k := range PrecompiledContractsOsaka { | ||
| PrecompiledAddressesOsaka = append(PrecompiledAddressesOsaka, k) | ||
| } | ||
|
|
@@ -426,6 +437,8 @@ func activePrecompiledContracts(rules params.Rules) PrecompiledContracts { | |
| switch { | ||
| case rules.IsVerkle: | ||
| return PrecompiledContractsVerkle | ||
| case rules.IsPasteur: | ||
| return PrecompiledContractsPasteur | ||
| case rules.IsOsaka: | ||
| return PrecompiledContractsOsaka | ||
| case rules.IsPrague: | ||
|
|
@@ -467,6 +480,8 @@ func ActivePrecompiledContracts(rules params.Rules) PrecompiledContracts { | |
| // ActivePrecompiles returns the precompile addresses enabled with the current configuration. | ||
| func ActivePrecompiles(rules params.Rules) []common.Address { | ||
| switch { | ||
| case rules.IsPasteur: | ||
| return PrecompiledAddressesPasteur | ||
| case rules.IsOsaka: | ||
| return PrecompiledAddressesOsaka | ||
| case rules.IsPrague: | ||
|
|
@@ -1602,6 +1617,10 @@ func (c *bls12381MapG2) Name() string { | |
| // blsSignatureVerify implements bls signature verification precompile. | ||
| type blsSignatureVerify struct{} | ||
|
|
||
| type blsSignatureVerifyPasteur struct { | ||
| blsSignatureVerify | ||
| } | ||
|
|
||
| const ( | ||
| msgHashLength = uint64(32) | ||
| signatureLength = uint64(96) | ||
|
|
@@ -1620,16 +1639,13 @@ func (c *blsSignatureVerify) RequiredGas(input []byte) uint64 { | |
| return params.BlsSignatureVerifyBaseGas + pubKeyNumber*params.BlsSignatureVerifyPerKeyGas | ||
| } | ||
|
|
||
| // Run input: | ||
| // msg | signature | [{bls pubkey}] | | ||
| // 32 bytes | 96 bytes | [{48 bytes}] | | ||
| func (c *blsSignatureVerify) Run(input []byte) ([]byte, error) { | ||
| func parseBlsSignatureVerifyInput(input []byte, requireUniquePubKeys bool) ([32]byte, bls.Signature, []bls.PublicKey, error) { | ||
| msgAndSigLength := msgHashLength + signatureLength | ||
| inputLen := uint64(len(input)) | ||
| if inputLen <= msgAndSigLength || | ||
| (inputLen-msgAndSigLength)%singleBlsPubkeyLength != 0 { | ||
| log.Debug("blsSignatureVerify input size wrong", "inputLen", inputLen) | ||
| return nil, ErrExecutionReverted | ||
| return [32]byte{}, nil, nil, ErrExecutionReverted | ||
| } | ||
|
|
||
| var msg [32]byte | ||
|
|
@@ -1640,38 +1656,76 @@ func (c *blsSignatureVerify) Run(input []byte) ([]byte, error) { | |
| sig, err := bls.SignatureFromBytes(signatureBytes) | ||
| if err != nil { | ||
| log.Debug("blsSignatureVerify invalid signature", "err", err) | ||
| return nil, ErrExecutionReverted | ||
| return [32]byte{}, nil, nil, ErrExecutionReverted | ||
| } | ||
|
|
||
| pubKeyNumber := (inputLen - msgAndSigLength) / singleBlsPubkeyLength | ||
| pubKeys := make([]bls.PublicKey, pubKeyNumber) | ||
| var seenPubKeys map[string]struct{} | ||
| if requireUniquePubKeys { | ||
| seenPubKeys = make(map[string]struct{}, pubKeyNumber) | ||
| } | ||
| for i := uint64(0); i < pubKeyNumber; i++ { | ||
| pubKeyBytes := getData(input, msgAndSigLength+i*singleBlsPubkeyLength, singleBlsPubkeyLength) | ||
| pubKey, err := bls.PublicKeyFromBytes(pubKeyBytes) | ||
| if err != nil { | ||
| log.Debug("blsSignatureVerify invalid pubKey", "err", err) | ||
| return nil, ErrExecutionReverted | ||
| return [32]byte{}, nil, nil, ErrExecutionReverted | ||
| } | ||
| if requireUniquePubKeys { | ||
| key := string(pubKeyBytes) | ||
| if _, ok := seenPubKeys[key]; ok { | ||
| return msg, sig, nil, nil | ||
| } | ||
| seenPubKeys[key] = struct{}{} | ||
| } | ||
| pubKeys[i] = pubKey | ||
| } | ||
|
|
||
| if pubKeyNumber > 1 { | ||
| return msg, sig, pubKeys, nil | ||
| } | ||
|
|
||
| func runBlsSignatureVerify(input []byte, requireUniquePubKeys bool) ([]byte, error) { | ||
| msg, sig, pubKeys, err := parseBlsSignatureVerifyInput(input, requireUniquePubKeys) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if pubKeys == nil { | ||
| return common.Big0.Bytes(), nil | ||
| } | ||
|
|
||
| if len(pubKeys) > 1 { | ||
| if !sig.FastAggregateVerify(pubKeys, msg) { | ||
| return common.Big0.Bytes(), nil | ||
| } | ||
| } else { | ||
| if !sig.Verify(pubKeys[0], msgBytes) { | ||
| if !sig.Verify(pubKeys[0], msg[:]) { | ||
| return common.Big0.Bytes(), nil | ||
| } | ||
| } | ||
|
|
||
| return common.Big1.Bytes(), nil | ||
| } | ||
|
|
||
| // Run input: | ||
| // msg | signature | [{bls pubkey}] | | ||
| // 32 bytes | 96 bytes | [{48 bytes}] | | ||
| func (c *blsSignatureVerify) Run(input []byte) ([]byte, error) { | ||
| return runBlsSignatureVerify(input, false) | ||
| } | ||
|
|
||
| func (c *blsSignatureVerify) Name() string { | ||
| return "BLS_SIGNATURE_VERIFY" | ||
| } | ||
|
|
||
| func (c *blsSignatureVerifyPasteur) Run(input []byte) ([]byte, error) { | ||
| return runBlsSignatureVerify(input, true) | ||
| } | ||
|
|
||
| func (c *blsSignatureVerifyPasteur) Name() string { | ||
| return "BLS_SIGNATURE_VERIFY_PASTEUR" | ||
| } | ||
|
|
||
| // kzgPointEvaluation implements the EIP-4844 point evaluation precompile. | ||
| type kzgPointEvaluation struct{} | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
list precompiles directly like others