mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
aot: enable post-Byzantium & no input => no copy
* Enable WASM precompiles after the Byzantium fork since the WASM code is modelled after that code. * x86 glue would go into an infinite loop if the size of the data to copy was zero as it would cycle back to 0xffffffffffffffff
This commit is contained in:
parent
33a87d5fcc
commit
1243c05e8b
4 changed files with 24 additions and 25 deletions
|
|
@ -24,7 +24,9 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"log"
|
"log"
|
||||||
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
@ -121,8 +123,8 @@ func (ac *AoTContract) ResolveGlobal(module, field string, t wa.Type) (init uint
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ac *AoTContract) RequiredGas(code []byte) uint64 {
|
func (ac *AoTContract) RequiredGas(input []byte) uint64 {
|
||||||
return 0
|
return PrecompiledContractsByzantium[common.BigToAddress(big.NewInt(int64(ac.Num)))].RequiredGas(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ac *AoTContract) Run(input []byte, contract *Contract) ([]byte, error) {
|
func (ac *AoTContract) Run(input []byte, contract *Contract) ([]byte, error) {
|
||||||
|
|
@ -231,21 +233,13 @@ func (ac *AoTContract) Run(input []byte, contract *Contract) ([]byte, error) {
|
||||||
|
|
||||||
retaddr, retsize := aot.Exec(textAddr, stackLimit, memoryAddr, stackPtr)
|
retaddr, retsize := aot.Exec(textAddr, stackLimit, memoryAddr, stackPtr)
|
||||||
|
|
||||||
gasLeft := binary.LittleEndian.Uint64(contractData[8:])
|
if retsize == 0 {
|
||||||
if gasLeft == 0xffffffffffffffff {
|
return nil, nil
|
||||||
fmt.Println("Out of gas")
|
|
||||||
return nil, ErrOutOfGas
|
|
||||||
} else {
|
|
||||||
fmt.Println("gas left: ", gasLeft, "result: ", globalsMemory[retaddr+obj.MemoryOffset:retaddr+obj.MemoryOffset+retsize])
|
|
||||||
contract.Gas = gasLeft
|
|
||||||
if retsize == 0 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
retData := make([]byte, retsize)
|
|
||||||
copy(retData, globalsMemory[retaddr+obj.MemoryOffset:retaddr+obj.MemoryOffset+retsize])
|
|
||||||
return retData, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retData := make([]byte, retsize)
|
||||||
|
copy(retData, globalsMemory[retaddr+obj.MemoryOffset:retaddr+obj.MemoryOffset+retsize])
|
||||||
|
return retData, nil
|
||||||
|
|
||||||
// TODO cleanup all protected memory areas
|
// TODO cleanup all protected memory areas
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,13 +36,15 @@ TEXT ethereumUseGas<>(SB),NOSPLIT,$0
|
||||||
// Get pointer to the contract info area into r13
|
// Get pointer to the contract info area into r13
|
||||||
MOVQ -0x20(R15), R13
|
MOVQ -0x20(R15), R13
|
||||||
|
|
||||||
MOVQ 8(SP), AX // Gas required
|
// Disable gas accounting as it is currently implemented
|
||||||
MOVQ 0x8(R13), CX // Gas left
|
// before calling the precompile.
|
||||||
CMPQ AX, CX
|
//MOVQ 8(SP), AX // Gas required
|
||||||
JA oog
|
//MOVQ 0x8(R13), CX // Gas left
|
||||||
|
//CMPQ AX, CX
|
||||||
|
//JA oog
|
||||||
|
|
||||||
SUBQ AX, CX
|
//SUBQ AX, CX
|
||||||
MOVQ CX, 0x8(R13)
|
//MOVQ CX, 0x8(R13)
|
||||||
XORQ AX, AX
|
XORQ AX, AX
|
||||||
XORQ CX, CX
|
XORQ CX, CX
|
||||||
RET
|
RET
|
||||||
|
|
@ -80,6 +82,10 @@ TEXT ethereumCallDataCopy<>(SB),NOSPLIT,$0
|
||||||
CMPQ AX, R12
|
CMPQ AX, R12
|
||||||
JA eei_error
|
JA eei_error
|
||||||
|
|
||||||
|
// Skip copy loop if there are no data to copy
|
||||||
|
CMPQ AX, $0
|
||||||
|
JZ calldatacopy_end
|
||||||
|
|
||||||
// Load address of the destination buffer
|
// Load address of the destination buffer
|
||||||
MOVQ 0x18(SP), DI
|
MOVQ 0x18(SP), DI
|
||||||
ADDQ R14, DI
|
ADDQ R14, DI
|
||||||
|
|
@ -90,6 +96,7 @@ TEXT ethereumCallDataCopy<>(SB),NOSPLIT,$0
|
||||||
ADDQ $1, SI
|
ADDQ $1, SI
|
||||||
ADDQ $1, DI
|
ADDQ $1, DI
|
||||||
LOOP copy
|
LOOP copy
|
||||||
|
calldatacopy_end:
|
||||||
RET
|
RET
|
||||||
|
|
||||||
eei_error:
|
eei_error:
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,6 @@ func run(evm *EVM, contract *Contract, input []byte, readOnly bool) ([]byte, err
|
||||||
if contract.CodeAddr != nil {
|
if contract.CodeAddr != nil {
|
||||||
precompiles := PrecompiledContractsHomestead
|
precompiles := PrecompiledContractsHomestead
|
||||||
if evm.ChainConfig().IsByzantium(evm.BlockNumber) {
|
if evm.ChainConfig().IsByzantium(evm.BlockNumber) {
|
||||||
precompiles = PrecompiledContractsByzantium
|
|
||||||
}
|
|
||||||
if evm.ChainConfig().IsEWASM(evm.BlockNumber) {
|
|
||||||
precompiles = PrecompiledContractsEWASM
|
precompiles = PrecompiledContractsEWASM
|
||||||
}
|
}
|
||||||
if p := precompiles[*contract.CodeAddr]; p != nil {
|
if p := precompiles[*contract.CodeAddr]; p != nil {
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,7 @@ var (
|
||||||
ByzantiumBlock: big.NewInt(1035301),
|
ByzantiumBlock: big.NewInt(1035301),
|
||||||
ConstantinopleBlock: big.NewInt(3660663),
|
ConstantinopleBlock: big.NewInt(3660663),
|
||||||
PetersburgBlock: big.NewInt(4321234),
|
PetersburgBlock: big.NewInt(4321234),
|
||||||
|
EWASMBlock: nil,
|
||||||
Clique: &CliqueConfig{
|
Clique: &CliqueConfig{
|
||||||
Period: 15,
|
Period: 15,
|
||||||
Epoch: 30000,
|
Epoch: 30000,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue