Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Zero Value Enforcers #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dylandesrosier
Copy link
Contributor

What?

  • NoValueEnforcer restricts the value field of the Execution to 0 for both single and batch execution modes. No terms are required.
  • NoCalldataEnforcer restricts the calldata field of the Execution to `` (ie empty bytes array, no data) for both single and batch execution modes. No terms are required.

@dylandesrosier dylandesrosier requested a review from a team as a code owner October 31, 2024 14:39
/**
* @title NoValueEnforcer
* @dev This contract enforces that the execution has no value.
* @dev This caveat enforcer only works when the execution is in single mode.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @dev This caveat enforcer only works when the execution is in single mode.
* @dev This caveat enforcer only works in single and batch modes

/**
* @title NoCalldataEnforcer
* @dev This contract enforces that the execution has no calldata.
* @dev This caveat enforcer only works when the execution is in single mode.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @dev This caveat enforcer only works when the execution is in single mode.
* @dev This caveat enforcer only works in single and batch modes.

require(callData_.length == 0, "NoCalldataEnforcer:calldata-not-allowed");
} else if (ModeLib.getCallType(_mode) == CALLTYPE_BATCH) {
(Execution[] calldata executions_) = _executionCallData.decodeBatch();
for (uint256 i = 0; i < executions_.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (uint256 i = 0; i < executions_.length; i++) {
for (uint256 i = 0; i < executions_.length; ++i) {

{
if (ModeLib.getCallType(_mode) == CALLTYPE_SINGLE) {
(,, bytes calldata callData_) = _executionCallData.decodeSingle();
require(callData_.length == 0, "NoCalldataEnforcer:calldata-not-allowed");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit concerned about the errors being exactly the same, it might help to differentiate them

@hanzel98
Copy link
Contributor

hanzel98 commented Nov 1, 2024

please add the new enforcers to the deployment script

import { CALLTYPE_SINGLE, CALLTYPE_BATCH } from "../utils/Constants.sol";

/**
* @title NoCalldataEnforcer
Copy link
Contributor

@hanzel98 hanzel98 Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see some places inside our contracts where calldata is lowercase but in others it is callData


////////////////////////////// State //////////////////////////////
NoCalldataEnforcer public noCalldataEnforcer;
DummyContract public c;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe DummyContract public dummy; instead

require(value_ == 0, "NoValueEnforcer:value-not-allowed");
} else if (ModeLib.getCallType(_mode) == CALLTYPE_BATCH) {
(Execution[] calldata executions_) = _executionCallData.decodeBatch();
for (uint256 i = 0; i < executions_.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (uint256 i = 0; i < executions_.length; i++) {
for (uint256 i = 0; i < executions_.length; ++i) {

Comment on lines +46 to +47
// should allow an execution in single mode with no calldata
function test_singleMethodNoCalldataIsAllowed() public {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename tests, these are value tests not calldata

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants