mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
core/vm: per byte cost of CREATE2
This commit is contained in:
parent
7ae9bd5605
commit
da9e9e8a6b
2 changed files with 21 additions and 4 deletions
|
|
@ -347,6 +347,17 @@ func gasCreate2(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack,
|
|||
if gas, overflow = math.SafeAdd(gas, params.Create2Gas); overflow {
|
||||
return 0, errGasUintOverflow
|
||||
}
|
||||
wordGas, overflow := bigUint64(stack.Back(2))
|
||||
if overflow {
|
||||
return 0, errGasUintOverflow
|
||||
}
|
||||
if wordGas, overflow = math.SafeMul(toWordSize(wordGas), params.Sha3WordGas); overflow {
|
||||
return 0, errGasUintOverflow
|
||||
}
|
||||
if gas, overflow = math.SafeAdd(gas, wordGas); overflow {
|
||||
return 0, errGasUintOverflow
|
||||
}
|
||||
|
||||
return gas, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,12 +18,11 @@ package vm
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
)
|
||||
|
||||
|
|
@ -544,14 +543,21 @@ func TestCreate2Addreses(t *testing.T) {
|
|||
code: "0x",
|
||||
expected: "0xE33C0C7F7df4809055C3ebA6c09CFe4BaF1BD9e0",
|
||||
},
|
||||
|
||||
} {
|
||||
|
||||
origin := common.BytesToAddress(common.FromHex(tt.origin))
|
||||
salt := common.BytesToHash(common.FromHex(tt.salt))
|
||||
code := common.FromHex(tt.code)
|
||||
address := crypto.CreateAddress2(origin, salt, code)
|
||||
fmt.Printf("Example %d\n* address `0x%x`\n* salt `0x%x`\n* code `0x%x`\n* result: `%s`\n\n", i,origin, salt, code, address.String())
|
||||
/*
|
||||
stack := newstack()
|
||||
// salt, but we don't need that for this test
|
||||
stack.push(big.NewInt(int64(len(code)))) //size
|
||||
stack.push(big.NewInt(0)) // memstart
|
||||
stack.push(big.NewInt(0)) // value
|
||||
gas, _ := gasCreate2(params.GasTable{}, nil, nil, stack, nil, 0)
|
||||
fmt.Printf("Example %d\n* address `0x%x`\n* salt `0x%x`\n* init_code `0x%x`\n* gas (assuming no mem expansion): `%v`\n* result: `%s`\n\n", i,origin, salt, code, gas, address.String())
|
||||
*/
|
||||
expected := common.BytesToAddress(common.FromHex(tt.expected))
|
||||
if bytes.Compare(expected.Bytes(), address.Bytes()) != 0 {
|
||||
t.Errorf("test %d: expected %s, got %s", i, expected.String(), address.String())
|
||||
|
|
|
|||
Loading…
Reference in a new issue