Commit a24e2e58 authored by inphi's avatar inphi

feat(ctb): make MIPS oracle addrs immutable

parent d6dcb1f4
...@@ -112,9 +112,17 @@ func NewEVMEnv(contracts *Contracts, addrs *Addresses) (*vm.EVM, *state.StateDB) ...@@ -112,9 +112,17 @@ func NewEVMEnv(contracts *Contracts, addrs *Addresses) (*vm.EVM, *state.StateDB)
env := vm.NewEVM(blockContext, vm.TxContext{}, state, chainCfg, vmCfg) env := vm.NewEVM(blockContext, vm.TxContext{}, state, chainCfg, vmCfg)
// pre-deploy the contracts // pre-deploy the contracts
env.StateDB.SetCode(addrs.MIPS, contracts.MIPS.DeployedBytecode.Object)
env.StateDB.SetCode(addrs.Oracle, contracts.Oracle.DeployedBytecode.Object) env.StateDB.SetCode(addrs.Oracle, contracts.Oracle.DeployedBytecode.Object)
env.StateDB.SetState(addrs.MIPS, common.Hash{}, addrs.Oracle.Hash())
var mipsCtorArgs [32]byte
copy(mipsCtorArgs[12:], addrs.Oracle[:])
mipsDeploy := append(hexutil.MustDecode(bindings.MIPSMetaData.Bin), mipsCtorArgs[:]...)
startingGas := uint64(30_000_000)
_, deployedMipsAddr, leftOverGas, err := env.Create(vm.AccountRef(addrs.Sender), mipsDeploy, startingGas, big.NewInt(0))
if err != nil {
panic(fmt.Errorf("failed to deploy MIPS contract: %w. took %d gas", err, startingGas-leftOverGas))
}
addrs.MIPS = deployedMipsAddr
rules := env.ChainConfig().Rules(header.Number, true, header.Time) rules := env.ChainConfig().Rules(header.Number, true, header.Time)
env.StateDB.Prepare(rules, addrs.Sender, addrs.FeeRecipient, &addrs.MIPS, vm.ActivePrecompiles(rules), nil) env.StateDB.Prepare(rules, addrs.Sender, addrs.FeeRecipient, &addrs.MIPS, vm.ActivePrecompiles(rules), nil)
......
This diff is collapsed.
This diff is collapsed.
...@@ -53,11 +53,15 @@ contract MIPS { ...@@ -53,11 +53,15 @@ contract MIPS {
uint32 constant EINVAL = 0x16; uint32 constant EINVAL = 0x16;
/// @notice The preimage oracle contract. /// @notice The preimage oracle contract.
IPreimageOracle public oracle; IPreimageOracle internal immutable ORACLE;
/// @param _oracle The address of the preimage oracle contract. /// @param _oracle The address of the preimage oracle contract.
constructor(IPreimageOracle _oracle) { constructor(IPreimageOracle _oracle) {
oracle = _oracle; ORACLE = _oracle;
}
function oracle() external view returns (IPreimageOracle oracle_) {
oracle_ = ORACLE;
} }
/// @notice Extends the value leftwards with its most significant bit (sign extension). /// @notice Extends the value leftwards with its most significant bit (sign extension).
...@@ -179,7 +183,7 @@ contract MIPS { ...@@ -179,7 +183,7 @@ contract MIPS {
if (uint8(preimageKey[0]) == 1) { if (uint8(preimageKey[0]) == 1) {
preimageKey = PreimageKeyLib.localize(preimageKey); preimageKey = PreimageKeyLib.localize(preimageKey);
} }
(bytes32 dat, uint256 datLen) = oracle.readPreimage(preimageKey, state.preimageOffset); (bytes32 dat, uint256 datLen) = ORACLE.readPreimage(preimageKey, state.preimageOffset);
// Transform data for writing to memory // Transform data for writing to memory
// We use assembly for more precise ops, and no var count limit // We use assembly for more precise ops, and no var count limit
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment