Skip to content

Commit

Permalink
Merge pull request ethereum#223 from OffchainLabs/random_difficult
Browse files Browse the repository at this point in the history
set evm.Context.Random to be equal to evm.Context.Difficulty
  • Loading branch information
PlasmaPower authored May 24, 2023
2 parents a3601ea + 97ac04d commit ffad045
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion core/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common
if header.Difficulty.Cmp(common.Big0) == 0 {
random = &header.MixDigest
}
arbOsVersion := types.DeserializeHeaderExtraInformation(header).ArbOSFormatVersion
if arbOsVersion > 0 {
difficultyHash := common.BigToHash(header.Difficulty)
random = &difficultyHash
}
return vm.BlockContext{
CanTransfer: CanTransfer,
Transfer: Transfer,
Expand All @@ -66,7 +71,7 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common
BaseFee: baseFee,
GasLimit: header.GasLimit,
Random: random,
ArbOSVersion: types.DeserializeHeaderExtraInformation(header).ArbOSFormatVersion,
ArbOSVersion: arbOsVersion,
}
}

Expand Down
6 changes: 5 additions & 1 deletion internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,10 @@ func (diff *BlockOverrides) Apply(blockCtx *vm.BlockContext) {
}
if diff.Difficulty != nil {
blockCtx.Difficulty = diff.Difficulty.ToInt()
if blockCtx.ArbOSVersion > 0 {
difficultHash := common.BigToHash(diff.Difficulty.ToInt())
blockCtx.Random = &difficultHash
}
}
if diff.Time != nil {
blockCtx.Time = uint64(*diff.Time)
Expand All @@ -951,7 +955,7 @@ func (diff *BlockOverrides) Apply(blockCtx *vm.BlockContext) {
if diff.Coinbase != nil {
blockCtx.Coinbase = *diff.Coinbase
}
if diff.Random != nil {
if blockCtx.ArbOSVersion == 0 && diff.Random != nil {
blockCtx.Random = diff.Random
}
if diff.BaseFee != nil {
Expand Down

0 comments on commit ffad045

Please sign in to comment.