Commit 66a21a9a authored by clabby's avatar clabby Committed by GitHub

feat(ctb): Log preimage oracle calldata (#10278)

* feat(ctb): Log preimage oracle calldata

* Add log tests

x

more binding
parent 62a554dc
This diff is collapsed.
......@@ -104,8 +104,8 @@
"sourceCodeHash": "0x6ab593a4b87007c000c254b2c4ff0507683600f48b60e453148e44bee30030f6"
},
"src/cannon/PreimageOracle.sol": {
"initCodeHash": "0x9e0d25588d96934044c6f20b62b21444d734c85fe86b305efd8d226024e92725",
"sourceCodeHash": "0xa2d7d5a1de4159a41ff99c2f05d33b9b472c2d00ea62f817b372988f56650153"
"initCodeHash": "0x534ac3ad48b4425ccb0fcf31a3626a1ff08c215cee1b80442e46e6980257b6e7",
"sourceCodeHash": "0x292a950cfe01923558ead684f2e014b00bc17bc07362dbd58f45b1cc121942a9"
},
"src/dispute/AnchorStateRegistry.sol": {
"initCodeHash": "0x2f8c56069e43e306b0e40fba43109188b29328e83569560021a68aa5d9f2486b",
......
......@@ -29,8 +29,8 @@ contract PreimageOracle is IPreimageOracle, ISemver {
uint256 public constant MAX_LEAF_COUNT = 2 ** KECCAK_TREE_DEPTH - 1;
/// @notice The semantic version of the Preimage Oracle contract.
/// @custom:semver 0.1.0
string public constant version = "0.1.0";
/// @custom:semver 0.2.0
string public constant version = "0.2.0";
////////////////////////////////////////////////////////////////
// Authorized Preimage Parts //
......@@ -460,6 +460,8 @@ contract PreimageOracle is IPreimageOracle, ISemver {
uint256 blocksProcessed = metaData.blocksProcessed();
// The caller of `addLeavesLPP` must be an EOA.
// Note: This check may break if EIPs like EIP-3074 are introduced. We may query the data in the logs if this
// is the case.
if (msg.sender != tx.origin) revert NotEOA();
// Revert if the proposal has not been initialized. 0-size preimages are *not* allowed.
......@@ -552,6 +554,14 @@ contract PreimageOracle is IPreimageOracle, ISemver {
proposalBlocks[msg.sender][_uuid].push(uint64(block.number));
// Persist the updated metadata to storage.
proposalMetadata[msg.sender][_uuid] = metaData;
// Clobber memory and `log0` all calldata. This is safe because there is no execution afterwards within
// this callframe.
assembly {
mstore(0x00, shl(96, caller()))
calldatacopy(0x14, 0x00, calldatasize())
log0(0x00, add(0x14, calldatasize()))
}
}
/// @notice Challenge a keccak256 block that was committed to in the merkle tree.
......
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import { Test, console2 as console } from "forge-std/Test.sol";
import { Test, Vm, console2 as console } from "forge-std/Test.sol";
import { PreimageOracle } from "src/cannon/PreimageOracle.sol";
import { PreimageKeyLib } from "src/cannon/PreimageKeyLib.sol";
......@@ -329,11 +329,19 @@ contract PreimageOracle_LargePreimageProposals_Test is Test {
// Allocate the calldata so it isn't included in the gas measurement.
bytes memory cd = abi.encodeCall(oracle.addLeavesLPP, (TEST_UUID, 0, data, stateCommitments, true));
// Record logs from the call. `expectEmit` does not capture assembly logs.
bytes memory expectedLog = abi.encodePacked(address(this), cd);
vm.recordLogs();
uint256 gas = gasleft();
(bool success,) = address(oracle).call(cd);
uint256 gasUsed = gas - gasleft();
assertTrue(success);
Vm.Log[] memory logs = vm.getRecordedLogs();
assertEq(logs[0].data, expectedLog);
assertEq(logs[0].emitter, address(oracle));
console.log("Gas used: %d", gasUsed);
console.log("Gas per byte (%d bytes streamed): %d", data.length, gasUsed / data.length);
console.log("Gas for 4MB: %d", (gasUsed / data.length) * 4000000);
......
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