Skip to content

Commit

Permalink
Merge pull request #7 from OffchainLabs/cross_module_internal
Browse files Browse the repository at this point in the history
OneStepProof: CrossModuleInternal instead of dynamic
  • Loading branch information
rachel-bousfield authored Oct 16, 2023
2 parents f291b58 + da28eac commit 78ecfd5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
26 changes: 18 additions & 8 deletions src/osp/OneStepProver0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,25 @@ contract OneStepProver0 is IOneStepProver {
mach.functionPc = 0;
}

function executeCrossModuleDynamicCall(
function executeCrossModuleInternalCall(
Machine memory mach,
Module memory mod,
Instruction calldata inst,
bytes calldata
bytes calldata proof
) internal pure {
// Get the target from the stack
uint32 func = mach.valueStack.pop().assumeI32();
uint32 module = mach.valueStack.pop().assumeI32();
uint32 internalIndex = uint32(inst.argumentData);
uint32 moduleIndex = mach.valueStack.pop().assumeI32();
Module memory calledMod;

MerkleProof memory modProof;
uint256 offset = 0;
(calledMod, offset) = Deserialize.module(proof, offset);
(modProof, offset) = Deserialize.merkleProof(proof, offset);
require(
modProof.computeRootFromModule(moduleIndex, calledMod) == mach.modulesRoot,
"CROSS_MODULE_INTERNAL_MODULES_ROOT"
);

// Push the return pc to the stack
mach.valueStack.push(createReturnValue(mach));
Expand All @@ -182,8 +192,8 @@ contract OneStepProver0 is IOneStepProver {
mach.valueStack.push(ValueLib.newI32(mod.internalsOffset));

// Jump to the target
mach.moduleIdx = module;
mach.functionIdx = func;
mach.moduleIdx = moduleIndex;
mach.functionIdx = internalIndex + calledMod.internalsOffset;
mach.functionPc = 0;
}

Expand Down Expand Up @@ -486,8 +496,8 @@ contract OneStepProver0 is IOneStepProver {
impl = executeCrossModuleCall;
} else if (opcode == Instructions.CROSS_MODULE_FORWARD) {
impl = executeCrossModuleForward;
} else if (opcode == Instructions.CROSS_MODULE_DYNAMIC_CALL) {
impl = executeCrossModuleDynamicCall;
} else if (opcode == Instructions.CROSS_MODULE_INTERNAL_CALL) {
impl = executeCrossModuleInternalCall;
} else if (opcode == Instructions.CALLER_MODULE_INTERNAL_CALL) {
impl = executeCallerModuleInternalCall;
} else if (opcode == Instructions.CALL_INDIRECT) {
Expand Down
2 changes: 2 additions & 0 deletions src/precompiles/ArbWasm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ interface ArbWasm {
// @return gas cost paid per half kb uncompressed.
function callScalar() external view returns (uint16 gas);

event ProgramActivated(bytes32 indexed codehash, address program, uint16 version);

error ProgramNotActivated();
error ProgramOutOfDate(uint16 version);
error ProgramUpToDate();
Expand Down
2 changes: 1 addition & 1 deletion src/state/Instructions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ library Instructions {
uint16 internal constant CROSS_MODULE_CALL = 0x8009;
uint16 internal constant CALLER_MODULE_INTERNAL_CALL = 0x800A;
uint16 internal constant CROSS_MODULE_FORWARD = 0x800B;
uint16 internal constant CROSS_MODULE_DYNAMIC_CALL = 0x800C;
uint16 internal constant CROSS_MODULE_INTERNAL_CALL = 0x800C;

uint16 internal constant GET_GLOBAL_STATE_BYTES32 = 0x8010;
uint16 internal constant SET_GLOBAL_STATE_BYTES32 = 0x8011;
Expand Down

0 comments on commit 78ecfd5

Please sign in to comment.