-
Notifications
You must be signed in to change notification settings - Fork 0
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
Apply kingster's change to Leeren's branch #1
base: feat/add-ip-and-p256-verify-precompiles
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,10 @@ import ( | |
"encoding/binary" | ||
"errors" | ||
"fmt" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/crypto" | ||
|
||
"github.com/consensys/gnark-crypto/ecc" | ||
bls12381 "github.com/consensys/gnark-crypto/ecc/bls12-381" | ||
"github.com/consensys/gnark-crypto/ecc/bls12-381/fp" | ||
|
@@ -34,7 +35,8 @@ import ( | |
"github.com/ethereum/go-ethereum/crypto/blake2b" | ||
"github.com/ethereum/go-ethereum/crypto/bn256" | ||
"github.com/ethereum/go-ethereum/crypto/kzg4844" | ||
"github.com/ethereum/go-ethereum/crypto/secp256r1" | ||
|
||
// "github.com/ethereum/go-ethereum/crypto/secp256r1" | ||
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. not delete this |
||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/params" | ||
"golang.org/x/crypto/ripemd160" | ||
|
@@ -55,7 +57,7 @@ var PrecompiledContractsHomestead = map[common.Address]PrecompiledContract{ | |
common.BytesToAddress([]byte{0x2}): &sha256hash{}, | ||
common.BytesToAddress([]byte{0x3}): &ripemd160hash{}, | ||
common.BytesToAddress([]byte{0x4}): &dataCopy{}, | ||
common.BytesToAddress([]byte{0x1a}): &ipGraph{}, | ||
// common.BytesToAddress([]byte{0x1a}): &ipGraph{}, | ||
} | ||
|
||
// PrecompiledContractsByzantium contains the default set of pre-compiled Ethereum | ||
|
@@ -69,7 +71,7 @@ var PrecompiledContractsByzantium = map[common.Address]PrecompiledContract{ | |
common.BytesToAddress([]byte{0x6}): &bn256AddByzantium{}, | ||
common.BytesToAddress([]byte{0x7}): &bn256ScalarMulByzantium{}, | ||
common.BytesToAddress([]byte{0x8}): &bn256PairingByzantium{}, | ||
common.BytesToAddress([]byte{0x1a}): &ipGraph{}, | ||
// common.BytesToAddress([]byte{0x1a}): &ipGraph{}, | ||
} | ||
|
||
// PrecompiledContractsIstanbul contains the default set of pre-compiled Ethereum | ||
|
@@ -84,7 +86,7 @@ var PrecompiledContractsIstanbul = map[common.Address]PrecompiledContract{ | |
common.BytesToAddress([]byte{0x7}): &bn256ScalarMulIstanbul{}, | ||
common.BytesToAddress([]byte{0x8}): &bn256PairingIstanbul{}, | ||
common.BytesToAddress([]byte{0x9}): &blake2F{}, | ||
common.BytesToAddress([]byte{0x1a}): &ipGraph{}, | ||
// common.BytesToAddress([]byte{0x1a}): &ipGraph{}, | ||
} | ||
|
||
// PrecompiledContractsBerlin contains the default set of pre-compiled Ethereum | ||
|
@@ -99,7 +101,7 @@ var PrecompiledContractsBerlin = map[common.Address]PrecompiledContract{ | |
common.BytesToAddress([]byte{0x7}): &bn256ScalarMulIstanbul{}, | ||
common.BytesToAddress([]byte{0x8}): &bn256PairingIstanbul{}, | ||
common.BytesToAddress([]byte{0x9}): &blake2F{}, | ||
common.BytesToAddress([]byte{0x1a}): &ipGraph{}, | ||
// common.BytesToAddress([]byte{0x1a}): &ipGraph{}, | ||
} | ||
|
||
// PrecompiledContractsCancun contains the default set of pre-compiled Ethereum | ||
|
@@ -140,42 +142,39 @@ var PrecompiledContractsPrague = map[common.Address]PrecompiledContract{ | |
common.BytesToAddress([]byte{0x11}): &bls12381Pairing{}, | ||
common.BytesToAddress([]byte{0x12}): &bls12381MapG1{}, | ||
common.BytesToAddress([]byte{0x13}): &bls12381MapG2{}, | ||
common.BytesToAddress([]byte{0x1a}): &ipGraph{}, | ||
} | ||
|
||
// PrecompiledContractsNostoi contains the set of pre-compiled Ethereum | ||
// contracts used in the iliad nostoi release. | ||
var PrecompiledContractsNostoi = map[common.Address]PrecompiledContract{ | ||
common.BytesToAddress([]byte{0x01}): &ecrecover{}, | ||
common.BytesToAddress([]byte{0x02}): &sha256hash{}, | ||
common.BytesToAddress([]byte{0x03}): &ripemd160hash{}, | ||
common.BytesToAddress([]byte{0x04}): &dataCopy{}, | ||
common.BytesToAddress([]byte{0x05}): &bigModExp{eip2565: true}, | ||
common.BytesToAddress([]byte{0x06}): &bn256AddIstanbul{}, | ||
common.BytesToAddress([]byte{0x07}): &bn256ScalarMulIstanbul{}, | ||
common.BytesToAddress([]byte{0x08}): &bn256PairingIstanbul{}, | ||
common.BytesToAddress([]byte{0x09}): &blake2F{}, | ||
common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{}, | ||
common.BytesToAddress([]byte{0x0b}): &bls12381G1Add{}, | ||
common.BytesToAddress([]byte{0x0c}): &bls12381G1Mul{}, | ||
common.BytesToAddress([]byte{0x0d}): &bls12381G1MultiExp{}, | ||
common.BytesToAddress([]byte{0x0e}): &bls12381G2Add{}, | ||
common.BytesToAddress([]byte{0x0f}): &bls12381G2Mul{}, | ||
common.BytesToAddress([]byte{0x10}): &bls12381G2MultiExp{}, | ||
common.BytesToAddress([]byte{0x11}): &bls12381Pairing{}, | ||
common.BytesToAddress([]byte{0x12}): &bls12381MapG1{}, | ||
common.BytesToAddress([]byte{0x13}): &bls12381MapG2{}, | ||
common.BytesToAddress([]byte{0x1a}): &ipGraph{}, | ||
common.BytesToAddress([]byte{0x1b}): &ipGraphWithPolicyKind{}, | ||
common.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{}, | ||
} | ||
// common.BytesToAddress([]byte{0x1a}): &ipGraph{}, | ||
} | ||
|
||
//var PrecompiledContractsNostoi = map[common.Address]PrecompiledContract{ | ||
// common.BytesToAddress([]byte{0x01}): &ecrecover{}, | ||
// common.BytesToAddress([]byte{0x02}): &sha256hash{}, | ||
// common.BytesToAddress([]byte{0x03}): &ripemd160hash{}, | ||
// common.BytesToAddress([]byte{0x04}): &dataCopy{}, | ||
// common.BytesToAddress([]byte{0x05}): &bigModExp{eip2565: true}, | ||
// common.BytesToAddress([]byte{0x06}): &bn256AddIstanbul{}, | ||
// common.BytesToAddress([]byte{0x07}): &bn256ScalarMulIstanbul{}, | ||
// common.BytesToAddress([]byte{0x08}): &bn256PairingIstanbul{}, | ||
// common.BytesToAddress([]byte{0x09}): &blake2F{}, | ||
// common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{}, | ||
// common.BytesToAddress([]byte{0x0b}): &bls12381G1Add{}, | ||
// common.BytesToAddress([]byte{0x0c}): &bls12381G1Mul{}, | ||
// common.BytesToAddress([]byte{0x0d}): &bls12381G1MultiExp{}, | ||
// common.BytesToAddress([]byte{0x0e}): &bls12381G2Add{}, | ||
// common.BytesToAddress([]byte{0x0f}): &bls12381G2Mul{}, | ||
// common.BytesToAddress([]byte{0x10}): &bls12381G2MultiExp{}, | ||
// common.BytesToAddress([]byte{0x11}): &bls12381Pairing{}, | ||
// common.BytesToAddress([]byte{0x12}): &bls12381MapG1{}, | ||
// common.BytesToAddress([]byte{0x13}): &bls12381MapG2{}, | ||
// common.BytesToAddress([]byte{0x1a}): &ipGraphDynamicGas{}, // redirect 0x1a to ipGraphDynamicGas | ||
// common.BytesToAddress([]byte{0x1b}): &ipGraphWithPolicyKind{}, | ||
// common.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{}, | ||
//} | ||
Comment on lines
+148
to
+171
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. These need to be activated |
||
|
||
var PrecompiledContractsBLS = PrecompiledContractsPrague | ||
|
||
var PrecompiledContractsVerkle = PrecompiledContractsPrague | ||
|
||
var ( | ||
PrecompiledAddressesNostoi []common.Address | ||
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. not delete this |
||
PrecompiledAddressesPrague []common.Address | ||
PrecompiledAddressesCancun []common.Address | ||
PrecompiledAddressesBerlin []common.Address | ||
|
@@ -203,16 +202,11 @@ func init() { | |
for k := range PrecompiledContractsPrague { | ||
PrecompiledAddressesPrague = append(PrecompiledAddressesPrague, k) | ||
} | ||
for k := range PrecompiledContractsNostoi { | ||
PrecompiledAddressesNostoi = append(PrecompiledAddressesNostoi, k) | ||
} | ||
Comment on lines
-206
to
-208
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. not delete these |
||
} | ||
|
||
// ActivePrecompiles returns the precompiles enabled with the current configuration. | ||
func ActivePrecompiles(rules params.Rules) []common.Address { | ||
switch { | ||
case rules.IsStoryNostoi: | ||
return PrecompiledAddressesNostoi | ||
Comment on lines
-214
to
-215
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. Not delete this |
||
case rules.IsPrague: | ||
return PrecompiledAddressesPrague | ||
case rules.IsCancun: | ||
|
@@ -1266,38 +1260,3 @@ func kZGToVersionedHash(kzg kzg4844.Commitment) common.Hash { | |
|
||
return h | ||
} | ||
|
||
// P256VERIFY (secp256r1 signature verification) | ||
// implemented as a native contract | ||
type p256Verify struct{} | ||
|
||
// RequiredGas returns the gas required to execute the precompiled contract | ||
func (c *p256Verify) RequiredGas(input []byte) uint64 { | ||
return params.P256VerifyGas | ||
} | ||
|
||
// Run executes the precompiled contract with the given input and EVM context, returning the output and the used gas | ||
func (c *p256Verify) Run(evm *EVM, input []byte) ([]byte, error) { | ||
// Required input length is 160 bytes | ||
const p256VerifyInputLength = 160 | ||
|
||
// Check the input length | ||
if len(input) != p256VerifyInputLength { | ||
// Input length is invalid | ||
return nil, nil | ||
} | ||
|
||
// Extract the hash, r, s, x, y from the input | ||
hash := input[0:32] | ||
r, s := new(big.Int).SetBytes(input[32:64]), new(big.Int).SetBytes(input[64:96]) | ||
x, y := new(big.Int).SetBytes(input[96:128]), new(big.Int).SetBytes(input[128:160]) | ||
|
||
// Verify the secp256r1 signature | ||
if secp256r1.Verify(hash, r, s, x, y) { | ||
// Signature is valid | ||
return common.LeftPadBytes([]byte{1}, 32), nil | ||
} else { | ||
// Signature is invalid | ||
return nil, nil | ||
} | ||
} | ||
Comment on lines
-1269
to
-1303
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. why are the deleted? |
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.
No need to add to genesis