Skip to content

Commit

Permalink
Merge pull request #94 from smart-transaction/fix/data-storage-in-cal…
Browse files Browse the repository at this point in the history
…l-object

Fix data store and load in call obj holder
  • Loading branch information
mevtxn authored Nov 6, 2024
2 parents 52cf059 + cf79ab7 commit b143185
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/TimeTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ struct CallObjectHolderStorage {
bool executed;
uint40 firstCallableBlock;
uint256 executionNonce;
bytes data;
genericDynArrayHead callObjsHead;
genericDynArrayElementsSlot callObjsElements;
}
Expand Down Expand Up @@ -110,6 +111,7 @@ library CallObjectLib {

holderStorage.callObjsHead = callObjsHead;
holderStorage.executionNonce = holder.nonce;
holderStorage.data = abi.encode(holder.data);
}

function store(CallObjectStorage storage callObjStorage, CallObject memory callObj) internal {
Expand All @@ -135,6 +137,8 @@ library CallObjectLib {
holder.initialized = holderStorage.initialized;
holder.executed = holderStorage.executed;
holder.firstCallableBlock = holderStorage.firstCallableBlock;
holder.nonce = holderStorage.executionNonce;
holder.data = _getDecodedData(holderStorage.data);
uint256 len = holderStorage.callObjsHead.length();
holder.callObjs = new CallObject[](len);

Expand Down Expand Up @@ -173,4 +177,10 @@ library CallObjectLib {
callObj.slot := ptr
}
}

function _getDecodedData(bytes memory encodedData) internal pure returns (SolverData[] memory solverData) {
if (encodedData.length != 0) {
solverData = abi.decode(encodedData, (SolverData[]));
}
}
}
20 changes: 19 additions & 1 deletion test/Laminator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.26;

import "forge-std/Test.sol";

import {Laminator, SolverData} from "src/lamination/Laminator.sol";
import {Laminator, SolverData, DATATYPE} from "src/lamination/Laminator.sol";
import {CallBreaker} from "src/timetravel/CallBreaker.sol";
import {LaminatedProxy} from "src/lamination/LaminatedProxy.sol";
import {CallObjectLib, CallObject, CallObjectHolder, ReturnObject} from "src/TimeTypes.sol";
Expand Down Expand Up @@ -125,6 +125,24 @@ contract LaminatorTest is Test {
proxy.pull(1);
}

function testPushToProxyDataValues() public {
CallObject[] memory callObj = new CallObject[](1);
callObj[0] = CallObject({
amount: 0,
addr: address(dummy),
gas: saneGasLeft(),
callvalue: abi.encodeWithSignature("emitArg(uint256)", 1)
});
bytes memory cData = abi.encode(callObj);
SolverData[] memory dataValues = new SolverData[](1);
dataValues[0] = SolverData({name: "MockVariable", datatype: DATATYPE.UINT256, value: "1"});

uint256 sequenceNumber = laminator.pushToProxy(cData, 0, DEFAULT_CODE, dataValues);
CallObjectHolder memory holder = proxy.deferredCalls(sequenceNumber);
assertEq(holder.data.length, 1);
assertEq(abi.encode(dataValues[0]), abi.encode(holder.data[0]));
}

// test delays in pushToProxy- 0 delay is immediately possible
function testDelayedPushToProxy0delayWorks() public {
// push sequence number 0. it should emit 42.
Expand Down
2 changes: 1 addition & 1 deletion test/examples/MEVOracle/KITNDisburmentScheduler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ contract KITNDisburmentScheduler is SmarterContract, Ownable {
// require(signer == owner(), "CleanAppKITNDisbursal: Verification Failed");
}

function getEthSignedMessageHash(bytes memory data) public view returns (bytes32) {
function getEthSignedMessageHash(bytes memory data) public pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", data));
}
}

0 comments on commit b143185

Please sign in to comment.