Skip to content

Commit 0af6c98

Browse files
authored
feat: support cronos precompiles (#20)
* feat: apply patches v1.15 * doc: update CHANGELOG * doc: update CHANGELOG * doc: update CHANGELOG * fix: precompiles * fix: comments
1 parent 36b2371 commit 0af6c98

File tree

20 files changed

+570
-251
lines changed

20 files changed

+570
-251
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Changelog
2+
3+
## [Unreleased]
4+
5+
### State Machine Breaking
6+
7+
- [#20](https://github.com/crypto-org-chain/go-ethereum/pull/20) feat: support cronos precompiles

core/state_transition.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
476476
// Execute the preparatory steps for state transition which includes:
477477
// - prepare accessList(post-berlin)
478478
// - reset transient storage(eip 1153)
479-
st.state.Prepare(rules, msg.From, st.evm.Context.Coinbase, msg.To, vm.ActivePrecompiles(rules), msg.AccessList)
479+
st.state.Prepare(rules, msg.From, st.evm.Context.Coinbase, msg.To, st.evm.ActivePrecompiles(rules), msg.AccessList)
480480

481481
var (
482482
ret []byte

core/tracing/hooks.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,13 @@ type StateDB interface {
5959

6060
// VMContext provides the context for the EVM execution.
6161
type VMContext struct {
62-
Coinbase common.Address
63-
BlockNumber *big.Int
64-
Time uint64
65-
Random *common.Hash
66-
BaseFee *big.Int
67-
StateDB StateDB
62+
Coinbase common.Address
63+
BlockNumber *big.Int
64+
Time uint64
65+
Random *common.Hash
66+
BaseFee *big.Int
67+
StateDB StateDB
68+
ActivePrecompiles []common.Address
6869
}
6970

7071
// BlockEvent is emitted upon tracing an incoming block.

core/vm/contract.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
)
2424

2525
// Contract represents an ethereum contract in the state database. It contains
26-
// the contract code, calling arguments. Contract implements ContractRef
26+
// the contract code, calling arguments.
2727
type Contract struct {
2828
// caller is the result of the caller which initialised this
2929
// contract. However, when the "call method" is delegated this
@@ -44,6 +44,8 @@ type Contract struct {
4444

4545
Gas uint64
4646
value *uint256.Int
47+
48+
isPrecompile bool
4749
}
4850

4951
// NewContract returns a new contract environment for the execution of EVM.
@@ -61,7 +63,30 @@ func NewContract(caller common.Address, address common.Address, value *uint256.I
6163
}
6264
}
6365

66+
// NewPrecompile returns a new instance of a precompiled contract environment for the execution of EVM.
67+
func NewPrecompile(caller common.Address, address common.Address, value *uint256.Int, gas uint64) *Contract {
68+
c := &Contract{
69+
caller: caller,
70+
address: address,
71+
isPrecompile: true,
72+
}
73+
74+
c.Gas = gas
75+
c.value = value
76+
77+
return c
78+
}
79+
80+
// IsPrecompile returns true if the contract is a precompiled contract environment
81+
func (c Contract) IsPrecompile() bool {
82+
return c.isPrecompile
83+
}
84+
6485
func (c *Contract) validJumpdest(dest *uint256.Int) bool {
86+
if c.isPrecompile {
87+
return false
88+
}
89+
6590
udest, overflow := dest.Uint64WithOverflow()
6691
// PC cannot go beyond len(code) and certainly can't be bigger than 63bits.
6792
// Don't bother checking for JUMPDEST in that case.
@@ -78,6 +103,10 @@ func (c *Contract) validJumpdest(dest *uint256.Int) bool {
78103
// isCode returns true if the provided PC location is an actual opcode, as
79104
// opposed to a data-segment following a PUSHN operation.
80105
func (c *Contract) isCode(udest uint64) bool {
106+
if c.isPrecompile {
107+
return false
108+
}
109+
81110
// Do we already have an analysis laying around?
82111
if c.analysis != nil {
83112
return c.analysis.codeSegment(udest)

0 commit comments

Comments
 (0)