Skip to content

Commit

Permalink
fix: remove comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ly0va committed Nov 25, 2024
1 parent a7d7d7c commit 2a491c2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 307 deletions.
4 changes: 2 additions & 2 deletions packages/contracts/src/libraries/SessionLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ library SessionLib {
}
}

require(found, "Call not allowed");
require(found, "Call to this contract is not allowed");
require(transaction.value <= callPolicy.maxValuePerUse, "Value exceeds limit");
callPolicy.valueLimit.checkAndUpdate(state.callValue[target][selector], transaction.value, periodIds[1]);

Expand All @@ -225,7 +225,7 @@ library SessionLib {
}
}

require(found, "Transfer not allowed");
require(found, "Transfer to this address is not allowed");
require(transaction.value <= transferPolicy.maxValuePerUse, "Value exceeds limit");
transferPolicy.valueLimit.checkAndUpdate(state.transferValue[target], transaction.value, periodIds[1]);
}
Expand Down
305 changes: 0 additions & 305 deletions packages/contracts/src/validators/SessionKeyValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,311 +15,6 @@ import { IHookManager } from "../interfaces/IHookManager.sol";
import { IValidatorManager } from "../interfaces/IValidatorManager.sol";
import { SessionLib } from "../libraries/SessionLib.sol";

// <<<<<<< HEAD
//
// library SessionLib {
// using SessionLib for SessionLib.Constraint;
// using SessionLib for SessionLib.UsageLimit;
//
// // For each session, its session status can only be changed
// // from NotInitialized to Active, and from Active to Closed.
// // To reopen a session with the same spec, use a different signer.
// enum Status {
// NotInitialized,
// Active,
// Closed
// }
//
// // This struct is used to track usage information for each session.
// // Along with `status`, this is considered the session state.
// // While everything else is considered the session spec, and is stored offchain.
// // Storage layout of this struct is weird to conform to ERC-7562 storage access restrictions during validation.
// // Each innermost mapping is always mapping(address account => ...).
// struct SessionStorage {
// mapping(address => Status) status;
// UsageTracker fee;
// // (target) => transfer value tracker
// mapping(address => UsageTracker) transferValue;
// // (target, selector) => call value tracker
// mapping(address => mapping(bytes4 => UsageTracker)) callValue;
// // (target, selector, index) => call parameter tracker
// // index is the constraint index in callPolicy, not the parameter index
// mapping(address => mapping(bytes4 => mapping(uint256 => UsageTracker))) params;
// }
//
// struct Constraint {
// Condition condition;
// uint64 index;
// bytes32 refValue;
// UsageLimit limit;
// }
//
// struct UsageTracker {
// // Used for LimitType.Lifetime
// mapping(address => uint256) lifetimeUsage;
// // Used for LimitType.Allowance
// // period => used that period
// mapping(uint64 => mapping(address => uint256)) allowanceUsage;
// }
//
// struct UsageLimit {
// LimitType limitType;
// uint256 limit; // ignored if limitType == Unlimited
// uint256 period; // ignored if limitType != Allowance
// }
//
// enum LimitType {
// Unlimited,
// Lifetime,
// Allowance
// }
//
// enum Condition {
// Unconstrained,
// Equal,
// Greater,
// Less,
// GreaterOrEqual,
// LessOrEqual,
// NotEqual
// }
//
// struct SessionSpec {
// address signer;
// uint256 expiresAt;
// UsageLimit feeLimit;
// CallSpec[] callPolicies;
// TransferSpec[] transferPolicies;
// }
//
// struct CallSpec {
// address target;
// bytes4 selector;
// uint256 maxValuePerUse;
// UsageLimit valueLimit;
// Constraint[] constraints;
// // add max data length restriction?
// // add max number of calls restriction?
// }
//
// struct TransferSpec {
// address target;
// uint256 maxValuePerUse;
// UsageLimit valueLimit;
// }
//
// struct LimitState {
// // this might also be limited by a constraint or `maxValuePerUse`,
// // which is not reflected here
// uint256 remaining;
// address target;
// // ignored for transfer value
// bytes4 selector;
// // ignored for transfer and call value
// uint256 index;
// }
//
// // Info about remaining session limits and its status
// struct SessionState {
// Status status;
// uint256 feesRemaining;
// LimitState[] transferValue;
// LimitState[] callValue;
// LimitState[] callParams;
// }
//
// function checkAndUpdate(
// UsageLimit memory limit,
// UsageTracker storage tracker,
// uint256 value,
// uint64 period
// ) internal {
// if (limit.limitType == LimitType.Lifetime) {
// require(tracker.lifetimeUsage[msg.sender] + value <= limit.limit, "Lifetime limit exceeded");
// tracker.lifetimeUsage[msg.sender] += value;
// }
// if (limit.limitType == LimitType.Allowance) {
// TimestampAsserterLocator.locate().assertTimestampInRange(period * limit.period, (period + 1) * limit.period);
// require(tracker.allowanceUsage[period][msg.sender] + value <= limit.limit, "Allowance limit exceeded");
// tracker.allowanceUsage[period][msg.sender] += value;
// }
// }
//
// function checkAndUpdate(
// Constraint memory constraint,
// UsageTracker storage tracker,
// bytes calldata data,
// uint64 period
// ) internal {
// uint256 index = 4 + constraint.index * 32;
// bytes32 param = bytes32(data[index:index + 32]);
// Condition condition = constraint.condition;
// bytes32 refValue = constraint.refValue;
//
// if (condition == Condition.Equal) {
// require(param == refValue, "EQUAL constraint not met");
// } else if (condition == Condition.Greater) {
// require(param > refValue, "GREATER constraint not met");
// } else if (condition == Condition.Less) {
// require(param < refValue, "LESS constraint not met");
// } else if (condition == Condition.GreaterOrEqual) {
// require(param >= refValue, "GREATER_OR_EQUAL constraint not met");
// } else if (condition == Condition.LessOrEqual) {
// require(param <= refValue, "LESS_OR_EQUAL constraint not met");
// } else if (condition == Condition.NotEqual) {
// require(param != refValue, "NOT_EQUAL constraint not met");
// }
//
// constraint.limit.checkAndUpdate(tracker, uint256(param), period);
// }
//
// // Here we additionally pass uint64[] periodId to check allowance limits
// // periodId is defined as block.timestamp / limit.period if limitType == Allowance, and 0 otherwise (which will be ignored).
// // periodIds[0] is for fee limit,
// // periodIds[1] is for value limit,
// // periodIds[2:] are for call constraints, if there are any.
// // It is required to pass them in (instead of computing via block.timestamp) since during validation
// // we can only assert the range of the timestamp, but not access its value.
// function validate(
// SessionStorage storage state,
// Transaction calldata transaction,
// SessionSpec memory spec,
// uint64[] memory periodIds
// ) internal {
// require(state.status[msg.sender] == Status.Active, "Session is not active");
// TimestampAsserterLocator.locate().assertTimestampInRange(0, spec.expiresAt);
//
// // TODO: update fee allowance with the gasleft/refund at the end of execution
// uint256 fee = transaction.maxFeePerGas * transaction.gasLimit;
// spec.feeLimit.checkAndUpdate(state.fee, fee, periodIds[0]);
//
// address target = address(uint160(transaction.to));
//
// if (transaction.data.length >= 4) {
// bytes4 selector = bytes4(transaction.data[:4]);
// CallSpec memory callPolicy;
// bool found = false;
//
// for (uint256 i = 0; i < spec.callPolicies.length; i++) {
// if (spec.callPolicies[i].target == target && spec.callPolicies[i].selector == selector) {
// callPolicy = spec.callPolicies[i];
// found = true;
// break;
// }
// }
//
// require(found, "Call to this contract is not allowed");
// require(transaction.value <= callPolicy.maxValuePerUse, "Value exceeds limit");
// callPolicy.valueLimit.checkAndUpdate(state.callValue[target][selector], transaction.value, periodIds[1]);
//
// for (uint256 i = 0; i < callPolicy.constraints.length; i++) {
// callPolicy.constraints[i].checkAndUpdate(state.params[target][selector][i], transaction.data, periodIds[i + 2]);
// }
// } else {
// TransferSpec memory transferPolicy;
// bool found = false;
//
// for (uint256 i = 0; i < spec.transferPolicies.length; i++) {
// if (spec.transferPolicies[i].target == target) {
// transferPolicy = spec.transferPolicies[i];
// found = true;
// break;
// }
// }
//
// require(found, "Transfer to this address is not allowed");
// require(transaction.value <= transferPolicy.maxValuePerUse, "Value exceeds limit");
// transferPolicy.valueLimit.checkAndUpdate(state.transferValue[target], transaction.value, periodIds[1]);
// }
// }
//
// function remainingLimit(
// UsageLimit memory limit,
// UsageTracker storage tracker,
// address account
// ) internal view returns (uint256) {
// if (limit.limitType == LimitType.Unlimited) {
// // this might be still limited by `maxValuePerUse` or a constraint
// return type(uint256).max;
// }
// if (limit.limitType == LimitType.Lifetime) {
// return limit.limit - tracker.lifetimeUsage[account];
// }
// if (limit.limitType == LimitType.Allowance) {
// // this is not used during validation, so it's fine to use block.timestamp
// uint64 period = uint64(block.timestamp / limit.period);
// return limit.limit - tracker.allowanceUsage[period][account];
// }
// }
//
// function getState(
// SessionStorage storage session,
// address account,
// SessionSpec calldata spec
// ) internal view returns (SessionState memory) {
// uint256 totalConstraints = 0;
// for (uint256 i = 0; i < spec.callPolicies.length; i++) {
// totalConstraints += spec.callPolicies[i].constraints.length;
// }
//
// LimitState[] memory transferValue = new LimitState[](spec.transferPolicies.length);
// LimitState[] memory callValue = new LimitState[](spec.callPolicies.length);
// LimitState[] memory callParams = new LimitState[](totalConstraints); // there will be empty ones at the end
// uint256 paramLimitIndex = 0;
//
// for (uint256 i = 0; i < transferValue.length; i++) {
// TransferSpec memory transferSpec = spec.transferPolicies[i];
// transferValue[i] = LimitState({
// remaining: remainingLimit(transferSpec.valueLimit, session.transferValue[transferSpec.target], account),
// target: spec.transferPolicies[i].target,
// selector: bytes4(0),
// index: 0
// });
// }
//
// for (uint256 i = 0; i < callValue.length; i++) {
// CallSpec memory callSpec = spec.callPolicies[i];
// callValue[i] = LimitState({
// remaining: remainingLimit(callSpec.valueLimit, session.callValue[callSpec.target][callSpec.selector], account),
// target: callSpec.target,
// selector: callSpec.selector,
// index: 0
// });
//
// for (uint256 j = 0; j < callSpec.constraints.length; j++) {
// if (callSpec.constraints[j].limit.limitType != LimitType.Unlimited) {
// callParams[paramLimitIndex++] = LimitState({
// remaining: remainingLimit(
// callSpec.constraints[j].limit,
// session.params[callSpec.target][callSpec.selector][j],
// account
// ),
// target: callSpec.target,
// selector: callSpec.selector,
// index: callSpec.constraints[j].index
// });
// }
// }
// }
//
// // shrink array to actual size
// assembly {
// mstore(callParams, paramLimitIndex)
// }
//
// return
// SessionState({
// status: session.status[account],
// feesRemaining: remainingLimit(spec.feeLimit, session.fee, account),
// transferValue: transferValue,
// callValue: callValue,
// callParams: callParams
// });
// }
// }
//
// contract SessionKeyValidator is IHook, IValidationHook, IModuleValidator, IModule {
// =======
contract SessionKeyValidator is IValidationHook, IModuleValidator, IModule {
using SessionLib for SessionLib.SessionStorage;
using EnumerableSet for EnumerableSet.Bytes32Set;
Expand Down

0 comments on commit 2a491c2

Please sign in to comment.