Skip to content

Commit

Permalink
Added debiting gas for some precompiled contracts (#891)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsmkl authored Mar 10, 2020
1 parent 1ef233c commit 2f3bee7
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ func (c *bn256AddIstanbul) RequiredGas(input []byte) uint64 {
}

func (c *bn256AddIstanbul) Run(input []byte, caller common.Address, evm *EVM, gas uint64) ([]byte, uint64, error) {
gas, err := debitRequiredGas(c, input, gas)
if err != nil {
return nil, gas, err
}
return runBn256Add(input, caller, evm, gas)
}

Expand All @@ -415,6 +419,10 @@ func (c *bn256AddByzantium) RequiredGas(input []byte) uint64 {
}

func (c *bn256AddByzantium) Run(input []byte, caller common.Address, evm *EVM, gas uint64) ([]byte, uint64, error) {
gas, err := debitRequiredGas(c, input, gas)
if err != nil {
return nil, gas, err
}
return runBn256Add(input, caller, evm, gas)
}

Expand All @@ -440,6 +448,10 @@ func (c *bn256ScalarMulIstanbul) RequiredGas(input []byte) uint64 {
}

func (c *bn256ScalarMulIstanbul) Run(input []byte, caller common.Address, evm *EVM, gas uint64) ([]byte, uint64, error) {
gas, err := debitRequiredGas(c, input, gas)
if err != nil {
return nil, gas, err
}
return runBn256ScalarMul(input, caller, evm, gas)
}

Expand All @@ -453,6 +465,10 @@ func (c *bn256ScalarMulByzantium) RequiredGas(input []byte) uint64 {
}

func (c *bn256ScalarMulByzantium) Run(input []byte, caller common.Address, evm *EVM, gas uint64) ([]byte, uint64, error) {
gas, err := debitRequiredGas(c, input, gas)
if err != nil {
return nil, gas, err
}
return runBn256ScalarMul(input, caller, evm, gas)
}

Expand Down Expand Up @@ -502,10 +518,14 @@ func runBn256Pairing(input []byte, caller common.Address, evm *EVM, gas uint64)
type transfer struct{}

func (c *transfer) RequiredGas(input []byte) uint64 {
return params.TxGas
return params.CallValueTransferGas
}

func (c *transfer) Run(input []byte, caller common.Address, evm *EVM, gas uint64) ([]byte, uint64, error) {
gas, err := debitRequiredGas(c, input, gas)
if err != nil {
return nil, gas, err
}
celoGoldAddress, err := GetRegisteredAddressWithEvm(params.GoldTokenRegistryId, evm)
if err != nil {
return nil, gas, err
Expand Down Expand Up @@ -671,6 +691,10 @@ func (c *bn256PairingIstanbul) RequiredGas(input []byte) uint64 {
}

func (c *bn256PairingIstanbul) Run(input []byte, caller common.Address, evm *EVM, gas uint64) ([]byte, uint64, error) {
gas, err := debitRequiredGas(c, input, gas)
if err != nil {
return nil, gas, err
}
return runBn256Pairing(input, caller, evm, gas)
}

Expand All @@ -684,6 +708,10 @@ func (c *bn256PairingByzantium) RequiredGas(input []byte) uint64 {
}

func (c *bn256PairingByzantium) Run(input []byte, caller common.Address, evm *EVM, gas uint64) ([]byte, uint64, error) {
gas, err := debitRequiredGas(c, input, gas)
if err != nil {
return nil, gas, err
}
return runBn256Pairing(input, caller, evm, gas)
}

Expand All @@ -710,6 +738,10 @@ var (
)

func (c *blake2F) Run(input []byte, caller common.Address, evm *EVM, gas uint64) ([]byte, uint64, error) {
gas, err := debitRequiredGas(c, input, gas)
if err != nil {
return nil, gas, err
}
// Make sure the input is valid (correct lenth and final flag)
if len(input) != blake2FInputLength {
return nil, gas, errBlake2FInvalidInputLength
Expand Down

0 comments on commit 2f3bee7

Please sign in to comment.