mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
added support for more granular storage slot override
This commit is contained in:
parent
659342a523
commit
b1d03eff56
1 changed files with 12 additions and 3 deletions
|
|
@ -42,6 +42,7 @@ type OverrideAccount struct {
|
||||||
Balance *hexutil.Big `json:"balance"`
|
Balance *hexutil.Big `json:"balance"`
|
||||||
State map[common.Hash]common.Hash `json:"state"`
|
State map[common.Hash]common.Hash `json:"state"`
|
||||||
StateDiff map[common.Hash]common.Hash `json:"stateDiff"`
|
StateDiff map[common.Hash]common.Hash `json:"stateDiff"`
|
||||||
|
StateDiffMask map[common.Hash]common.Hash `json:"stateDiffMask"`
|
||||||
MovePrecompileTo *common.Address `json:"movePrecompileToAddress"`
|
MovePrecompileTo *common.Address `json:"movePrecompileToAddress"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,8 +99,8 @@ func (diff *StateOverride) Apply(statedb *state.StateDB, precompiles vm.Precompi
|
||||||
u256Balance, _ := uint256.FromBig((*big.Int)(account.Balance))
|
u256Balance, _ := uint256.FromBig((*big.Int)(account.Balance))
|
||||||
statedb.SetBalance(addr, u256Balance, tracing.BalanceChangeUnspecified)
|
statedb.SetBalance(addr, u256Balance, tracing.BalanceChangeUnspecified)
|
||||||
}
|
}
|
||||||
if account.State != nil && account.StateDiff != nil {
|
if account.State != nil && (account.StateDiff != nil || account.StateDiffMask != nil) {
|
||||||
return fmt.Errorf("account %s has both 'state' and 'stateDiff'", addr.Hex())
|
return fmt.Errorf("account %s has both 'state' and 'stateDiff' or 'stateDiffMask'", addr.Hex())
|
||||||
}
|
}
|
||||||
// Replace entire state if caller requires.
|
// Replace entire state if caller requires.
|
||||||
if account.State != nil {
|
if account.State != nil {
|
||||||
|
|
@ -108,7 +109,15 @@ func (diff *StateOverride) Apply(statedb *state.StateDB, precompiles vm.Precompi
|
||||||
// Apply state diff into specified accounts.
|
// Apply state diff into specified accounts.
|
||||||
if account.StateDiff != nil {
|
if account.StateDiff != nil {
|
||||||
for key, value := range account.StateDiff {
|
for key, value := range account.StateDiff {
|
||||||
statedb.SetState(addr, key, value)
|
if mask, ok := account.StateDiffMask[key]; !ok {
|
||||||
|
statedb.SetState(addr, key, value)
|
||||||
|
} else {
|
||||||
|
curSlotVal := statedb.GetState(addr, key)
|
||||||
|
for i := range curSlotVal {
|
||||||
|
curSlotVal[i] = ^mask[i]&curSlotVal[i] | value[i]
|
||||||
|
}
|
||||||
|
statedb.SetState(addr, key, curSlotVal)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue