diff --git a/src/types/Weaver.sol b/src/types/Weaver.sol index 8098efd..7317cf9 100644 --- a/src/types/Weaver.sol +++ b/src/types/Weaver.sol @@ -17,10 +17,10 @@ abstract contract Weaver is IWeaver { uint256 public override currentWeavingSession; uint256 public override startWeavingSession; - mapping(uint256 => mapping(uint256 => Checkpoints.Trace256)) internal _treeNodes; - mapping(uint256 => mapping(uint256 => Checkpoints.Trace160)) internal _slotLenghts; - mapping(uint256 => mapping(uint256 => bytes32[])) internal _slotValues; - mapping(uint256 => uint256) internal _filledEntries; + mapping(uint256 => mapping(uint256 => Checkpoints.Trace256)) private _treeNodes; + mapping(uint256 => mapping(uint256 => Checkpoints.Trace160)) private _slotLenghts; + mapping(uint256 => mapping(uint256 => bytes32[])) private _slotValues; + mapping(uint256 => uint256) private _filledEntries; function previousAddress() external virtual view returns (address); @@ -178,4 +178,36 @@ abstract contract Weaver is IWeaver { currentWeavingSession = newSession; startWeavingSession = newSession; } + + function _getTreeNodesLatest(uint256 session, uint256 index) internal view returns (uint256) { + return _treeNodes[session][index].latest(); + } + + function _getTreeNodesUpperLookup( + uint256 session, + uint256 index, + uint256 atBlock + ) internal view returns (uint256) { + return _treeNodes[session][index].upperLookup(atBlock); + } + + function _getSlotLenghtsLatest(uint256 session, uint256 index) internal view returns (uint160) { + return _slotLenghts[session][index].latest(); + } + + function _getSlotLenghtsUpperLookup( + uint256 session, + uint256 index, + uint96 atBlock + ) internal view returns (uint160) { + return _slotLenghts[session][index].upperLookup(atBlock); + } + + function _getSlotValue(uint256 session, uint256 slot, uint256 index) internal view returns (bytes32) { + return _slotValues[session][slot][index]; + } + + function _getFilledEntries(uint256 session) internal view returns (uint256) { + return _filledEntries[session]; + } } diff --git a/test/gatekeeper/GatekeeperWeaver.t.sol b/test/gatekeeper/GatekeeperWeaver.t.sol index 282d0da..f2de511 100644 --- a/test/gatekeeper/GatekeeperWeaver.t.sol +++ b/test/gatekeeper/GatekeeperWeaver.t.sol @@ -46,23 +46,23 @@ contract GatekeeperWeaver is Gatekeeper { constructor(address storageHistory, address staking) Gatekeeper(storageHistory, staking) {} function filledEntries(uint256 session) public view returns (uint256) { - return _filledEntries[session]; + return _getFilledEntries(session); } function slotLengths(uint256 session, uint256 globalIndex) public view returns (uint160) { uint256 slotIndex = globalIndex % SLOTS; - return _slotLenghts[session][slotIndex].latest(); + return _getSlotLenghtsLatest(session, slotIndex); } - function slotValues(uint256 session, uint256 globalIndex) public view returns (bytes32) { + function slotValue(uint256 session, uint256 globalIndex) public view returns (bytes32) { uint256 slotIndex = globalIndex % SLOTS; uint256 valueIndex = globalIndex / SLOTS; - return _slotValues[session][slotIndex][valueIndex]; + return _getSlotValue(session, slotIndex, valueIndex); } function treeNodesLatest(uint256 session, uint256 globalIndex) public view returns (bytes32) { uint256 slotIndex = globalIndex % SLOTS; - return bytes32(_treeNodes[session][slotIndex].latest()); + return bytes32(_getTreeNodesLatest(session, slotIndex)); } function computePreimage(uint256 globalIndex, uint256 a, bytes32 r) public view returns (bytes32) { @@ -242,7 +242,7 @@ contract GatekeeperWeaverTest is Test { } { - bytes32 preimage1 = gatekeeper.slotValues(emittedSession, globalIndex); + bytes32 preimage1 = gatekeeper.slotValue(emittedSession, globalIndex); bytes32 preimage2 = gatekeeper.computePreimage(globalIndex, amount, who); assertEq(preimage1, preimage2); }