Inject a "return 1" EntryPoint precompile, stop of messing with 'ExtCodeSize'

This commit is contained in:
Alex Forshtat 2024-08-09 20:02:26 +02:00
parent 587a6ac534
commit 6cfa0ad277
2 changed files with 15 additions and 8 deletions

View file

@ -109,6 +109,8 @@ var PrecompiledContractsCancun = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{0x8}): &bn256PairingIstanbul{}, common.BytesToAddress([]byte{0x8}): &bn256PairingIstanbul{},
common.BytesToAddress([]byte{0x9}): &blake2F{}, common.BytesToAddress([]byte{0x9}): &blake2F{},
common.BytesToAddress([]byte{0xa}): &kzgPointEvaluation{}, common.BytesToAddress([]byte{0xa}): &kzgPointEvaluation{},
common.BytesToAddress([]byte{0x75, 0x60}): &rip7560EntryPoint{},
} }
// PrecompiledContractsPrague contains the set of pre-compiled Ethereum // PrecompiledContractsPrague contains the set of pre-compiled Ethereum
@ -135,6 +137,19 @@ var PrecompiledContractsPrague = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{0x13}): &bls12381MapG2{}, common.BytesToAddress([]byte{0x13}): &bls12381MapG2{},
} }
// rip7560EntryPoint does not really have any code and simply returns '1' whenever it is called
type rip7560EntryPoint struct{}
func (r *rip7560EntryPoint) RequiredGas(input []byte) uint64 {
return 0
}
func (r *rip7560EntryPoint) Run(input []byte) ([]byte, error) {
byteRet := make([]byte, 32)
byteRet[31] = 1
return byteRet, nil
}
var PrecompiledContractsBLS = PrecompiledContractsPrague var PrecompiledContractsBLS = PrecompiledContractsPrague
var PrecompiledContractsVerkle = PrecompiledContractsPrague var PrecompiledContractsVerkle = PrecompiledContractsPrague

View file

@ -338,16 +338,8 @@ func opReturnDataCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeConte
return nil, nil return nil, nil
} }
// TODO: very ugly workaround for Solidity preventing calls to no-code contracts
var AA_ENTRY_POINT = common.HexToAddress("0x0000000000000000000000000000000000007560")
func opExtCodeSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { func opExtCodeSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
slot := scope.Stack.peek() slot := scope.Stack.peek()
if common.Address(slot.Bytes20()).Cmp(AA_ENTRY_POINT) == 0 {
slot.SetUint64(uint64(1))
return nil, nil
}
slot.SetUint64(uint64(interpreter.evm.StateDB.GetCodeSize(slot.Bytes20()))) slot.SetUint64(uint64(interpreter.evm.StateDB.GetCodeSize(slot.Bytes20())))
return nil, nil return nil, nil
} }