diff --git a/core/types/block.go b/core/types/block.go index 1a357baa3a..46bbda6d1f 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -191,9 +191,9 @@ type Body struct { // - We do not copy body data on access because it does not affect the caches, and also // because it would be too expensive. type Block struct { - header *Header + Header_ *Header uncles []*Header - transactions Transactions + Txs Transactions withdrawals Withdrawals // caches @@ -221,28 +221,28 @@ type extblock struct { // are ignored and set to values derived from the given txs, uncles // and receipts. func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt, hasher TrieHasher) *Block { - b := &Block{header: CopyHeader(header)} + b := &Block{Header_: CopyHeader(header)} // TODO: panic if len(txs) != len(receipts) if len(txs) == 0 { - b.header.TxHash = EmptyTxsHash + b.Header_.TxHash = EmptyTxsHash } else { - b.header.TxHash = DeriveSha(Transactions(txs), hasher) - b.transactions = make(Transactions, len(txs)) - copy(b.transactions, txs) + b.Header_.TxHash = DeriveSha(Transactions(txs), hasher) + b.Txs = make(Transactions, len(txs)) + copy(b.Txs, txs) } if len(receipts) == 0 { - b.header.ReceiptHash = EmptyReceiptsHash + b.Header_.ReceiptHash = EmptyReceiptsHash } else { - b.header.ReceiptHash = DeriveSha(Receipts(receipts), hasher) - b.header.Bloom = CreateBloom(receipts) + b.Header_.ReceiptHash = DeriveSha(Receipts(receipts), hasher) + b.Header_.Bloom = CreateBloom(receipts) } if len(uncles) == 0 { - b.header.UncleHash = EmptyUncleHash + b.Header_.UncleHash = EmptyUncleHash } else { - b.header.UncleHash = CalcUncleHash(uncles) + b.Header_.UncleHash = CalcUncleHash(uncles) b.uncles = make([]*Header, len(uncles)) for i := range uncles { b.uncles[i] = CopyHeader(uncles[i]) @@ -261,12 +261,12 @@ func NewBlockWithWithdrawals(header *Header, txs []*Transaction, uncles []*Heade b := NewBlock(header, txs, uncles, receipts, hasher) if withdrawals == nil { - b.header.WithdrawalsHash = nil + b.Header_.WithdrawalsHash = nil } else if len(withdrawals) == 0 { - b.header.WithdrawalsHash = &EmptyWithdrawalsHash + b.Header_.WithdrawalsHash = &EmptyWithdrawalsHash } else { h := DeriveSha(Withdrawals(withdrawals), hasher) - b.header.WithdrawalsHash = &h + b.Header_.WithdrawalsHash = &h } return b.WithWithdrawals(withdrawals) @@ -314,7 +314,7 @@ func (b *Block) DecodeRLP(s *rlp.Stream) error { if err := s.Decode(&eb); err != nil { return err } - b.header, b.uncles, b.transactions, b.withdrawals = eb.Header, eb.Uncles, eb.Txs, eb.Withdrawals + b.Header_, b.uncles, b.Txs, b.withdrawals = eb.Header, eb.Uncles, eb.Txs, eb.Withdrawals b.size.Store(rlp.ListSize(size)) return nil } @@ -322,8 +322,8 @@ func (b *Block) DecodeRLP(s *rlp.Stream) error { // EncodeRLP serializes a block as RLP. func (b *Block) EncodeRLP(w io.Writer) error { return rlp.Encode(w, &extblock{ - Header: b.header, - Txs: b.transactions, + Header: b.Header_, + Txs: b.Txs, Uncles: b.uncles, Withdrawals: b.withdrawals, }) @@ -332,18 +332,18 @@ func (b *Block) EncodeRLP(w io.Writer) error { // Body returns the non-header content of the block. // Note the returned data is not an independent copy. func (b *Block) Body() *Body { - return &Body{b.transactions, b.uncles, b.withdrawals} + return &Body{b.Txs, b.uncles, b.withdrawals} } // Accessors for body data. These do not return a copy because the content // of the body slices does not affect the cached hash/size in block. func (b *Block) Uncles() []*Header { return b.uncles } -func (b *Block) Transactions() Transactions { return b.transactions } +func (b *Block) Transactions() Transactions { return b.Txs } func (b *Block) Withdrawals() Withdrawals { return b.withdrawals } func (b *Block) Transaction(hash common.Hash) *Transaction { - for _, transaction := range b.transactions { + for _, transaction := range b.Txs { if transaction.Hash() == hash { return transaction } @@ -353,52 +353,52 @@ func (b *Block) Transaction(hash common.Hash) *Transaction { // Header returns the block header (as a copy). func (b *Block) Header() *Header { - return CopyHeader(b.header) + return CopyHeader(b.Header_) } // Header value accessors. These do copy! -func (b *Block) Number() *big.Int { return new(big.Int).Set(b.header.Number) } -func (b *Block) GasLimit() uint64 { return b.header.GasLimit } -func (b *Block) GasUsed() uint64 { return b.header.GasUsed } -func (b *Block) Difficulty() *big.Int { return new(big.Int).Set(b.header.Difficulty) } -func (b *Block) Time() uint64 { return b.header.Time } +func (b *Block) Number() *big.Int { return new(big.Int).Set(b.Header_.Number) } +func (b *Block) GasLimit() uint64 { return b.Header_.GasLimit } +func (b *Block) GasUsed() uint64 { return b.Header_.GasUsed } +func (b *Block) Difficulty() *big.Int { return new(big.Int).Set(b.Header_.Difficulty) } +func (b *Block) Time() uint64 { return b.Header_.Time } -func (b *Block) NumberU64() uint64 { return b.header.Number.Uint64() } -func (b *Block) MixDigest() common.Hash { return b.header.MixDigest } -func (b *Block) Nonce() uint64 { return binary.BigEndian.Uint64(b.header.Nonce[:]) } -func (b *Block) Bloom() Bloom { return b.header.Bloom } -func (b *Block) Coinbase() common.Address { return b.header.Coinbase } -func (b *Block) Root() common.Hash { return b.header.Root } -func (b *Block) ParentHash() common.Hash { return b.header.ParentHash } -func (b *Block) TxHash() common.Hash { return b.header.TxHash } -func (b *Block) ReceiptHash() common.Hash { return b.header.ReceiptHash } -func (b *Block) UncleHash() common.Hash { return b.header.UncleHash } -func (b *Block) Extra() []byte { return common.CopyBytes(b.header.Extra) } +func (b *Block) NumberU64() uint64 { return b.Header_.Number.Uint64() } +func (b *Block) MixDigest() common.Hash { return b.Header_.MixDigest } +func (b *Block) Nonce() uint64 { return binary.BigEndian.Uint64(b.Header_.Nonce[:]) } +func (b *Block) Bloom() Bloom { return b.Header_.Bloom } +func (b *Block) Coinbase() common.Address { return b.Header_.Coinbase } +func (b *Block) Root() common.Hash { return b.Header_.Root } +func (b *Block) ParentHash() common.Hash { return b.Header_.ParentHash } +func (b *Block) TxHash() common.Hash { return b.Header_.TxHash } +func (b *Block) ReceiptHash() common.Hash { return b.Header_.ReceiptHash } +func (b *Block) UncleHash() common.Hash { return b.Header_.UncleHash } +func (b *Block) Extra() []byte { return common.CopyBytes(b.Header_.Extra) } func (b *Block) BaseFee() *big.Int { - if b.header.BaseFee == nil { + if b.Header_.BaseFee == nil { return nil } - return new(big.Int).Set(b.header.BaseFee) + return new(big.Int).Set(b.Header_.BaseFee) } -func (b *Block) BeaconRoot() *common.Hash { return b.header.ParentBeaconRoot } +func (b *Block) BeaconRoot() *common.Hash { return b.Header_.ParentBeaconRoot } func (b *Block) ExcessBlobGas() *uint64 { var excessBlobGas *uint64 - if b.header.ExcessBlobGas != nil { + if b.Header_.ExcessBlobGas != nil { excessBlobGas = new(uint64) - *excessBlobGas = *b.header.ExcessBlobGas + *excessBlobGas = *b.Header_.ExcessBlobGas } return excessBlobGas } func (b *Block) BlobGasUsed() *uint64 { var blobGasUsed *uint64 - if b.header.BlobGasUsed != nil { + if b.Header_.BlobGasUsed != nil { blobGasUsed = new(uint64) - *blobGasUsed = *b.header.BlobGasUsed + *blobGasUsed = *b.Header_.BlobGasUsed } return blobGasUsed } @@ -418,7 +418,7 @@ func (b *Block) Size() uint64 { // SanityCheck can be used to prevent that unbounded fields are // stuffed with junk data to add processing overhead func (b *Block) SanityCheck() error { - return b.header.SanityCheck() + return b.Header_.SanityCheck() } type writeCounter uint64 @@ -439,15 +439,15 @@ func CalcUncleHash(uncles []*Header) common.Hash { // header data is copied, changes to header and to the field values // will not affect the block. func NewBlockWithHeader(header *Header) *Block { - return &Block{header: CopyHeader(header)} + return &Block{Header_: CopyHeader(header)} } // WithSeal returns a new block with the data from b but the header replaced with // the sealed one. func (b *Block) WithSeal(header *Header) *Block { return &Block{ - header: CopyHeader(header), - transactions: b.transactions, + Header_: CopyHeader(header), + Txs: b.Txs, uncles: b.uncles, withdrawals: b.withdrawals, } @@ -456,12 +456,12 @@ func (b *Block) WithSeal(header *Header) *Block { // WithBody returns a copy of the block with the given transaction and uncle contents. func (b *Block) WithBody(transactions []*Transaction, uncles []*Header) *Block { block := &Block{ - header: b.header, - transactions: make([]*Transaction, len(transactions)), + Header_: b.Header_, + Txs: make([]*Transaction, len(transactions)), uncles: make([]*Header, len(uncles)), withdrawals: b.withdrawals, } - copy(block.transactions, transactions) + copy(block.Txs, transactions) for i := range uncles { block.uncles[i] = CopyHeader(uncles[i]) } @@ -471,8 +471,8 @@ func (b *Block) WithBody(transactions []*Transaction, uncles []*Header) *Block { // WithWithdrawals returns a copy of the block containing the given withdrawals. func (b *Block) WithWithdrawals(withdrawals []*Withdrawal) *Block { block := &Block{ - header: b.header, - transactions: b.transactions, + Header_: b.Header_, + Txs: b.Txs, uncles: b.uncles, } if withdrawals != nil { @@ -488,7 +488,7 @@ func (b *Block) Hash() common.Hash { if hash := b.hash.Load(); hash != nil { return hash.(common.Hash) } - v := b.header.Hash() + v := b.Header_.Hash() b.hash.Store(v) return v } diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 408c2d8dd5..8787e3e0ec 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -38,12 +38,12 @@ import ( // requires a deterministic gas count based on the input size of the Run method of the // contract. type PrecompiledContract interface { - RequiredGas(input []byte) uint64 // RequiredPrice calculates the contract gas use - Run(evm *EVM, sender common.Address, input []byte) ([]byte, error) // Run runs the precompiled contract + RequiredGas(input []byte) uint64 // RequiredPrice calculates the contract gas use + Run(evm *EVM, sender common.Address, input []byte, value *big.Int) ([]byte, error) // Run runs the precompiled contract } type DynamicGasPrecompiledContract interface { - RunAndCalculateGas(evm *EVM, sender common.Address, callingContract common.Address, input []byte, suppliedGas uint64) (ret []byte, remainingGas uint64, err error) // Run runs the precompiled contract and calculate gas dynamically + RunAndCalculateGas(evm *EVM, sender common.Address, callingContract common.Address, input []byte, suppliedGas uint64, value *big.Int) (ret []byte, remainingGas uint64, err error) // Run runs the precompiled contract and calculate gas dynamically } // PrecompiledContractsHomestead contains the default set of pre-compiled Ethereum @@ -172,9 +172,9 @@ func ActivePrecompiles(rules params.Rules) []common.Address { // - the returned bytes, // - the _remaining_ gas, // - any error that occurred -func RunPrecompiledContract(p PrecompiledContract, evm *EVM, sender common.Address, callingContract common.Address, input []byte, suppliedGas uint64, logger EVMLogger) (ret []byte, remainingGas uint64, err error) { +func RunPrecompiledContract(p PrecompiledContract, evm *EVM, sender common.Address, callingContract common.Address, input []byte, suppliedGas uint64, value *big.Int, logger EVMLogger) (ret []byte, remainingGas uint64, err error) { if dp, ok := p.(DynamicGasPrecompiledContract); ok { - return dp.RunAndCalculateGas(evm, sender, callingContract, input, suppliedGas) + return dp.RunAndCalculateGas(evm, sender, callingContract, input, suppliedGas, value) } gasCost := p.RequiredGas(input) if suppliedGas < gasCost { @@ -184,7 +184,7 @@ func RunPrecompiledContract(p PrecompiledContract, evm *EVM, sender common.Addre logger.OnGasChange(suppliedGas, suppliedGas-gasCost, GasChangeCallPrecompiledContract) } suppliedGas -= gasCost - output, err := p.Run(evm, sender, input) + output, err := p.Run(evm, sender, input, value) return output, suppliedGas, err } @@ -195,7 +195,7 @@ func (c *Ecrecover) RequiredGas(input []byte) uint64 { return params.EcrecoverGas } -func (c *Ecrecover) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (c *Ecrecover) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { const ecRecoverInputLength = 128 input = common.RightPadBytes(input, ecRecoverInputLength) @@ -236,7 +236,7 @@ type Sha256hash struct{} func (c *Sha256hash) RequiredGas(input []byte) uint64 { return uint64(len(input)+31)/32*params.Sha256PerWordGas + params.Sha256BaseGas } -func (c *Sha256hash) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (c *Sha256hash) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { h := sha256.Sum256(input) return h[:], nil } @@ -251,7 +251,7 @@ type Ripemd160hash struct{} func (c *Ripemd160hash) RequiredGas(input []byte) uint64 { return uint64(len(input)+31)/32*params.Ripemd160PerWordGas + params.Ripemd160BaseGas } -func (c *Ripemd160hash) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (c *Ripemd160hash) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { ripemd := ripemd160.New() ripemd.Write(input) return common.LeftPadBytes(ripemd.Sum(nil), 32), nil @@ -267,7 +267,7 @@ type DataCopy struct{} func (c *DataCopy) RequiredGas(input []byte) uint64 { return uint64(len(input)+31)/32*params.IdentityPerWordGas + params.IdentityBaseGas } -func (c *DataCopy) Run(_ *EVM, _ common.Address, in []byte) ([]byte, error) { +func (c *DataCopy) Run(_ *EVM, _ common.Address, in []byte, _ *big.Int) ([]byte, error) { return common.CopyBytes(in), nil } @@ -393,7 +393,7 @@ func (c *BigModExp) RequiredGas(input []byte) uint64 { return gas.Uint64() } -func (c *BigModExp) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (c *BigModExp) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { var ( baseLen = new(big.Int).SetBytes(getData(input, 0, 32)).Uint64() expLen = new(big.Int).SetBytes(getData(input, 32, 32)).Uint64() @@ -473,7 +473,7 @@ func (c *Bn256AddIstanbul) RequiredGas(input []byte) uint64 { return params.Bn256AddGasIstanbul } -func (c *Bn256AddIstanbul) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (c *Bn256AddIstanbul) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { return runBn256Add(input) } @@ -486,7 +486,7 @@ func (c *bn256AddByzantium) RequiredGas(input []byte) uint64 { return params.Bn256AddGasByzantium } -func (c *bn256AddByzantium) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (c *bn256AddByzantium) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { return runBn256Add(input) } @@ -511,7 +511,7 @@ func (c *Bn256ScalarMulIstanbul) RequiredGas(input []byte) uint64 { return params.Bn256ScalarMulGasIstanbul } -func (c *Bn256ScalarMulIstanbul) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (c *Bn256ScalarMulIstanbul) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { return runBn256ScalarMul(input) } @@ -524,7 +524,7 @@ func (c *bn256ScalarMulByzantium) RequiredGas(input []byte) uint64 { return params.Bn256ScalarMulGasByzantium } -func (c *bn256ScalarMulByzantium) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (c *bn256ScalarMulByzantium) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { return runBn256ScalarMul(input) } @@ -579,7 +579,7 @@ func (c *Bn256PairingIstanbul) RequiredGas(input []byte) uint64 { return params.Bn256PairingBaseGasIstanbul + uint64(len(input)/192)*params.Bn256PairingPerPointGasIstanbul } -func (c *Bn256PairingIstanbul) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (c *Bn256PairingIstanbul) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { return runBn256Pairing(input) } @@ -592,7 +592,7 @@ func (c *bn256PairingByzantium) RequiredGas(input []byte) uint64 { return params.Bn256PairingBaseGasByzantium + uint64(len(input)/192)*params.Bn256PairingPerPointGasByzantium } -func (c *bn256PairingByzantium) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (c *bn256PairingByzantium) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { return runBn256Pairing(input) } @@ -618,7 +618,7 @@ var ( ErrBlake2FInvalidFinalFlag = errors.New("invalid final flag") ) -func (c *Blake2F) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (c *Blake2F) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { // Make sure the input is valid (correct length and final flag) if len(input) != Blake2FInputLength { return nil, ErrBlake2FInvalidInputLength @@ -672,7 +672,7 @@ func (c *Bls12381G1Add) RequiredGas(input []byte) uint64 { return params.Bls12381G1AddGas } -func (c *Bls12381G1Add) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (c *Bls12381G1Add) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { // Implements EIP-2537 G1Add precompile. // > G1 addition call expects `256` bytes as an input that is interpreted as byte concatenation of two G1 points (`128` bytes each). // > Output is an encoding of addition operation result - single G1 point (`128` bytes). @@ -710,7 +710,7 @@ func (c *Bls12381G1Mul) RequiredGas(input []byte) uint64 { return params.Bls12381G1MulGas } -func (c *Bls12381G1Mul) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (c *Bls12381G1Mul) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { // Implements EIP-2537 G1Mul precompile. // > G1 multiplication call expects `160` bytes as an input that is interpreted as byte concatenation of encoding of G1 point (`128` bytes) and encoding of a scalar value (`32` bytes). // > Output is an encoding of multiplication operation result - single G1 point (`128` bytes). @@ -760,7 +760,7 @@ func (c *Bls12381G1MultiExp) RequiredGas(input []byte) uint64 { return (uint64(k) * params.Bls12381G1MulGas * discount) / 1000 } -func (c *Bls12381G1MultiExp) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (c *Bls12381G1MultiExp) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { // Implements EIP-2537 G1MultiExp precompile. // G1 multiplication call expects `160*k` bytes as an input that is interpreted as byte concatenation of `k` slices each of them being a byte concatenation of encoding of G1 point (`128` bytes) and encoding of a scalar value (`32` bytes). // Output is an encoding of multiexponentiation operation result - single G1 point (`128` bytes). @@ -803,7 +803,7 @@ func (c *Bls12381G2Add) RequiredGas(input []byte) uint64 { return params.Bls12381G2AddGas } -func (c *Bls12381G2Add) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (c *Bls12381G2Add) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { // Implements EIP-2537 G2Add precompile. // > G2 addition call expects `512` bytes as an input that is interpreted as byte concatenation of two G2 points (`256` bytes each). // > Output is an encoding of addition operation result - single G2 point (`256` bytes). @@ -841,7 +841,7 @@ func (c *Bls12381G2Mul) RequiredGas(input []byte) uint64 { return params.Bls12381G2MulGas } -func (c *Bls12381G2Mul) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (c *Bls12381G2Mul) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { // Implements EIP-2537 G2MUL precompile logic. // > G2 multiplication call expects `288` bytes as an input that is interpreted as byte concatenation of encoding of G2 point (`256` bytes) and encoding of a scalar value (`32` bytes). // > Output is an encoding of multiplication operation result - single G2 point (`256` bytes). @@ -891,7 +891,7 @@ func (c *Bls12381G2MultiExp) RequiredGas(input []byte) uint64 { return (uint64(k) * params.Bls12381G2MulGas * discount) / 1000 } -func (c *Bls12381G2MultiExp) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (c *Bls12381G2MultiExp) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { // Implements EIP-2537 G2MultiExp precompile logic // > G2 multiplication call expects `288*k` bytes as an input that is interpreted as byte concatenation of `k` slices each of them being a byte concatenation of encoding of G2 point (`256` bytes) and encoding of a scalar value (`32` bytes). // > Output is an encoding of multiexponentiation operation result - single G2 point (`256` bytes). @@ -934,7 +934,7 @@ func (c *Bls12381Pairing) RequiredGas(input []byte) uint64 { return params.Bls12381PairingBaseGas + uint64(len(input)/384)*params.Bls12381PairingPerPairGas } -func (c *Bls12381Pairing) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (c *Bls12381Pairing) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { // Implements EIP-2537 Pairing precompile logic. // > Pairing call expects `384*k` bytes as an inputs that is interpreted as byte concatenation of `k` slices. Each slice has the following structure: // > - `128` bytes of G1 point encoding @@ -1013,7 +1013,7 @@ func (c *Bls12381MapG1) RequiredGas(input []byte) uint64 { return params.Bls12381MapG1Gas } -func (c *Bls12381MapG1) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (c *Bls12381MapG1) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { // Implements EIP-2537 Map_To_G1 precompile. // > Field-to-curve call expects `64` bytes an an input that is interpreted as a an element of the base field. // > Output of this call is `128` bytes and is G1 point following respective encoding rules. @@ -1048,7 +1048,7 @@ func (c *Bls12381MapG2) RequiredGas(input []byte) uint64 { return params.Bls12381MapG2Gas } -func (c *Bls12381MapG2) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (c *Bls12381MapG2) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { // Implements EIP-2537 Map_FP2_TO_G2 precompile logic. // > Field-to-curve call expects `128` bytes an an input that is interpreted as a an element of the quadratic extension field. // > Output of this call is `256` bytes and is G2 point following respective encoding rules. @@ -1103,7 +1103,7 @@ var ( ) // Run executes the point evaluation precompile. -func (b *KzgPointEvaluation) Run(_ *EVM, _ common.Address, input []byte) ([]byte, error) { +func (b *KzgPointEvaluation) Run(_ *EVM, _ common.Address, input []byte, _ *big.Int) ([]byte, error) { if len(input) != blobVerifyInputLength { return nil, errBlobVerifyInvalidInputLength } diff --git a/core/vm/contracts_fuzz_test.go b/core/vm/contracts_fuzz_test.go index 89f9b96dc9..f457b3f40c 100644 --- a/core/vm/contracts_fuzz_test.go +++ b/core/vm/contracts_fuzz_test.go @@ -37,7 +37,7 @@ func FuzzPrecompiledContracts(f *testing.F) { return } inWant := string(input) - vm.RunPrecompiledContract(p, nil, common.Address{}, common.Address{}, input, gas, nil) + vm.RunPrecompiledContract(p, nil, common.Address{}, common.Address{}, input, gas, nil, nil) if inHave := string(input); inWant != inHave { t.Errorf("Precompiled %v modified input data", a) } diff --git a/core/vm/contracts_test.go b/core/vm/contracts_test.go index 8782f03dea..a532559b38 100644 --- a/core/vm/contracts_test.go +++ b/core/vm/contracts_test.go @@ -99,7 +99,7 @@ func testPrecompiled(addr string, test precompiledTest, t *testing.T) { in := common.Hex2Bytes(test.Input) gas := p.RequiredGas(in) t.Run(fmt.Sprintf("%s-Gas=%d", test.Name, gas), func(t *testing.T) { - if res, _, err := vm.RunPrecompiledContract(p, nil, common.Address{}, common.Address{}, in, gas, nil); err != nil { + if res, _, err := vm.RunPrecompiledContract(p, nil, common.Address{}, common.Address{}, in, gas, nil, nil); err != nil { t.Error(err) } else if common.Bytes2Hex(res) != test.Expected { t.Errorf("Expected %v, got %v", test.Expected, common.Bytes2Hex(res)) @@ -121,7 +121,7 @@ func testPrecompiledOOG(addr string, test precompiledTest, t *testing.T) { gas := p.RequiredGas(in) - 1 t.Run(fmt.Sprintf("%s-Gas=%d", test.Name, gas), func(t *testing.T) { - _, _, err := vm.RunPrecompiledContract(p, nil, common.Address{}, common.Address{}, in, gas, nil) + _, _, err := vm.RunPrecompiledContract(p, nil, common.Address{}, common.Address{}, in, gas, nil, nil) if err.Error() != "out of gas" { t.Errorf("Expected error [out of gas], got [%v]", err) } @@ -138,7 +138,7 @@ func testPrecompiledFailure(addr string, test precompiledFailureTest, t *testing in := common.Hex2Bytes(test.Input) gas := p.RequiredGas(in) t.Run(test.Name, func(t *testing.T) { - _, _, err := vm.RunPrecompiledContract(p, nil, common.Address{}, common.Address{}, in, gas, nil) + _, _, err := vm.RunPrecompiledContract(p, nil, common.Address{}, common.Address{}, in, gas, nil, nil) if err.Error() != test.ExpectedError { t.Errorf("Expected error [%v], got [%v]", test.ExpectedError, err) } @@ -170,7 +170,7 @@ func benchmarkPrecompiled(addr string, test precompiledTest, bench *testing.B) { bench.ResetTimer() for i := 0; i < bench.N; i++ { copy(data, in) - res, _, err = vm.RunPrecompiledContract(p, nil, common.Address{}, common.Address{}, data, reqGas, nil) + res, _, err = vm.RunPrecompiledContract(p, nil, common.Address{}, common.Address{}, data, reqGas, nil, nil) } bench.StopTimer() elapsed := uint64(time.Since(start)) diff --git a/core/vm/evm.go b/core/vm/evm.go index f8b4e01c71..a99d46c6ac 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -215,7 +215,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas evm.Context.Transfer(evm.StateDB, caller.Address(), addr, value) if isPrecompile { - ret, gas, err = RunPrecompiledContract(p, evm, caller.Address(), caller.Address(), input, gas, evm.Config.Tracer) + ret, gas, err = RunPrecompiledContract(p, evm, caller.Address(), caller.Address(), input, gas, value, evm.Config.Tracer) } else { // Initialise a new contract and set the code that is to be used by the EVM. // The contract is a scoped environment for this execution context only. @@ -281,7 +281,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte, // It is allowed to call precompiles, even via delegatecall if p, isPrecompile := evm.precompile(addr); isPrecompile { - ret, gas, err = RunPrecompiledContract(p, evm, caller.Address(), caller.Address(), input, gas, evm.Config.Tracer) + ret, gas, err = RunPrecompiledContract(p, evm, caller.Address(), caller.Address(), input, gas, value, evm.Config.Tracer) } else { addrCopy := addr // Initialise a new contract and set the code that is to be used by the EVM. @@ -332,7 +332,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by // NOTE: caller must, at all times be a contract. It should never happen // that caller is something other than a Contract. parent := caller.(*Contract) - ret, gas, err = RunPrecompiledContract(p, evm, parent.CallerAddress, caller.Address(), input, gas, evm.Config.Tracer) + ret, gas, err = RunPrecompiledContract(p, evm, parent.CallerAddress, caller.Address(), input, gas, nil, evm.Config.Tracer) } else { addrCopy := addr // Initialise a new contract and make initialise the delegate values @@ -383,7 +383,7 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte evm.StateDB.AddBalance(addr, new(big.Int), state.BalanceChangeTouchAccount) if p, isPrecompile := evm.precompile(addr); isPrecompile { - ret, gas, err = RunPrecompiledContract(p, evm, caller.Address(), caller.Address(), input, gas, evm.Config.Tracer) + ret, gas, err = RunPrecompiledContract(p, evm, caller.Address(), caller.Address(), input, gas, nil, evm.Config.Tracer) } else { // At this point, we use a copy of address. If we don't, the go compiler will // leak the 'contract' to the outer scope, and make allocation for 'contract' diff --git a/tests/fuzzers/bls12381/precompile_fuzzer.go b/tests/fuzzers/bls12381/precompile_fuzzer.go index 18827a1fec..20efbd48be 100644 --- a/tests/fuzzers/bls12381/precompile_fuzzer.go +++ b/tests/fuzzers/bls12381/precompile_fuzzer.go @@ -82,7 +82,7 @@ func fuzz(id byte, data []byte) int { } cpy := make([]byte, len(data)) copy(cpy, data) - _, err := precompile.Run(nil, common.Address{}, cpy) + _, err := precompile.Run(nil, common.Address{}, cpy, nil) if !bytes.Equal(cpy, data) { panic(fmt.Sprintf("input data modified, precompile %d: %x %x", id, data, cpy)) }