Repository: iotexproject/iotex-core
Pull request #3995 (2023-11-23 09:59:30)

[action] Increase Execution Size Limit to 48K
# Description

After activating EIP-3860: Limit and meter initcode in the Shanghai upgrade, the limit on the initcode size was increased to 48KB in evm. Currently, we have a limit of 32KB on execution action size. To be compatible with this change in Ethereum, we propose to raise the limit size up to 48KB.

## Type of change
- [x] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)

# How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
- [] make test
- [] fullsync
- [] Other test (please specify)

**Test Configuration**:
- Firmware version:
- Hardware:
- Toolchain:
- SDK:

# Checklist:
- [] My code follows the style guidelines of this project
- [] I have performed a self-review of my code
- [] I have commented my code, particularly in hard-to-understand areas
- [] I have made corresponding changes to the documentation
- [] My changes generate no new warnings
- [] I have added tests that prove my fix is effective or that my feature works
- [] New and existing unit tests pass locally with my changes
- [] Any dependent changes have been merged and published in downstream modules


sonarcloud[bot]: SonarCloud Quality Gate failed.&nbsp; &nbsp; [![Quality Gate failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/failed-16px.png 'Quality Gate failed')](https://sonarcloud.io/dashboard?id=iotexproject_iotex-core&pullRequest=3995)

[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=BUG)  
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=SECURITY_HOTSPOT)  
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=CODE_SMELL)

[![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=iotexproject_iotex-core&pullRequest=3995) No Coverage information  
[![4.6%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/5-16px.png '4.6%')](https://sonarcloud.io/component_measures?id=iotexproject_iotex-core&pullRequest=3995&metric=new_duplicated_lines_density&view=list) [4.6% Duplication](https://sonarcloud.io/component_measures?id=iotexproject_iotex-core&pullRequest=3995&metric=new_duplicated_lines_density&view=list)



![idea](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/light_bulb-16px.png 'idea') Catch issues before they fail your Quality Gate with our IDE extension ![sonarlint](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/sonarlint-16px.png 'sonarlint') [SonarLint](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=sonarcloud-welcome)
sonarcloud[bot]: SonarCloud Quality Gate failed.&nbsp; &nbsp; [![Quality Gate failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/failed-16px.png 'Quality Gate failed')](https://sonarcloud.io/dashboard?id=iotexproject_iotex-core&pullRequest=3995)

[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=BUG)  
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=SECURITY_HOTSPOT)  
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=CODE_SMELL)

[![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=iotexproject_iotex-core&pullRequest=3995) No Coverage information  
[![4.6%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/5-16px.png '4.6%')](https://sonarcloud.io/component_measures?id=iotexproject_iotex-core&pullRequest=3995&metric=new_duplicated_lines_density&view=list) [4.6% Duplication](https://sonarcloud.io/component_measures?id=iotexproject_iotex-core&pullRequest=3995&metric=new_duplicated_lines_density&view=list)



![idea](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/light_bulb-16px.png 'idea') Catch issues before they fail your Quality Gate with our IDE extension ![sonarlint](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/sonarlint-16px.png 'sonarlint') [SonarLint](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=sonarcloud-welcome)
sonarcloud[bot]: SonarCloud Quality Gate failed.&nbsp; &nbsp; [![Quality Gate failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/failed-16px.png 'Quality Gate failed')](https://sonarcloud.io/dashboard?id=iotexproject_iotex-core&pullRequest=3995)

[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=BUG)  
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=SECURITY_HOTSPOT)  
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=3995&resolved=false&types=CODE_SMELL)

[![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=iotexproject_iotex-core&pullRequest=3995) No Coverage information  
[![4.2%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/5-16px.png '4.2%')](https://sonarcloud.io/component_measures?id=iotexproject_iotex-core&pullRequest=3995&metric=new_duplicated_lines_density&view=list) [4.2% Duplication](https://sonarcloud.io/component_measures?id=iotexproject_iotex-core&pullRequest=3995&metric=new_duplicated_lines_density&view=list)



![idea](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/light_bulb-16px.png 'idea') Catch issues before they fail your Quality Gate with our IDE extension ![sonarlint](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/sonarlint-16px.png 'sonarlint') [SonarLint](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=sonarcloud-welcome)

Patch:
diff --git a/action/protocol/context.go b/action/protocol/context.go
index 4557303fa..d9d36852f 100644
--- a/action/protocol/context.go
+++ b/action/protocol/context.go
@@ -114,6 +114,7 @@ type (
 		AddContractStakingVotes                 bool
 		FixContractStakingWeightedVotes         bool
 		SharedGasWithDapp                       bool
+		ExecutionSizeLimit32KB                  bool
 	}
 
 	// FeatureWithHeightCtx provides feature check functions.
@@ -253,6 +254,7 @@ func WithFeatureCtx(ctx context.Context) context.Context {
 			AddContractStakingVotes:                 g.IsQuebec(height),
 			FixContractStakingWeightedVotes:         g.IsRedsea(height),
 			SharedGasWithDapp:                       g.IsToBeEnabled(height),
+			ExecutionSizeLimit32KB:                  !g.IsToBeEnabled(height),
 		},
 	)
 }
diff --git a/action/protocol/execution/protocol.go b/action/protocol/execution/protocol.go
index bf190dc67..71f1133eb 100644
--- a/action/protocol/execution/protocol.go
+++ b/action/protocol/execution/protocol.go
@@ -20,8 +20,9 @@ import (
 )
 
 const (
-	// ExecutionSizeLimit is the maximum size of execution allowed
-	ExecutionSizeLimit = 32 * 1024
+	// the maximum size of execution allowed
+	_executionSizeLimit48KB = uint32(48 * 1024)
+	_executionSizeLimit32KB = uint32(32 * 1024)
 	// TODO: it works only for one instance per protocol definition now
 	_protocolID = "smart_contract"
 )
@@ -83,13 +84,19 @@ func (p *Protocol) Handle(ctx context.Context, act action.Action, sm protocol.St
 }
 
 // Validate validates an execution
-func (p *Protocol) Validate(_ context.Context, act action.Action, _ protocol.StateReader) error {
+func (p *Protocol) Validate(ctx context.Context, act action.Action, _ protocol.StateReader) error {
 	exec, ok := act.(*action.Execution)
 	if !ok {
 		return nil
 	}
+	sizeLimit := _executionSizeLimit48KB
+	fCtx := protocol.MustGetFeatureCtx(ctx)
+	if fCtx.ExecutionSizeLimit32KB {
+		sizeLimit = _executionSizeLimit32KB
+	}
+
 	// Reject oversize execution
-	if exec.TotalSize() > ExecutionSizeLimit {
+	if exec.TotalSize() > sizeLimit {
 		return action.ErrOversizedData
 	}
 	return nil


Test patch:
diff --git a/action/protocol/execution/protocol_test.go b/action/protocol/execution/protocol_test.go
index 1134c34d2..571a9a2b6 100644
--- a/action/protocol/execution/protocol_test.go
+++ b/action/protocol/execution/protocol_test.go
@@ -615,9 +615,29 @@ func TestProtocol_Validate(t *testing.T) {
 		return time.Time{}, nil
 	})
 
-	ex, err := action.NewExecution("2", uint64(1), big.NewInt(0), uint64(0), big.NewInt(0), make([]byte, 32684))
-	require.NoError(err)
-	require.Equal(action.ErrOversizedData, errors.Cause(p.Validate(context.Background(), ex, nil)))
+	cases := []struct {
+		name      string
+		height    uint64
+		size      uint64
+		expectErr error
+	}{
+		{"limit 32KB", 0, 32684, action.ErrOversizedData},
+		{"limit 48KB I", genesis.Default.ToBeEnabledBlockHeight, 32684, nil},
+		{"limit 48KB II", genesis.Default.ToBeEnabledBlockHeight, 49153, action.ErrOversizedData},
+	}
+
+	for i := range cases {
+		t.Run(cases[i].name, func(t *testing.T) {
+			ex, err := action.NewExecution("2", uint64(1), big.NewInt(0), uint64(0), big.NewInt(0), make([]byte, cases[i].size))
+			require.NoError(err)
+			ctx := genesis.WithGenesisContext(context.Background(), config.Default.Genesis)
+			ctx = protocol.WithBlockCtx(ctx, protocol.BlockCtx{
+				BlockHeight: cases[i].height,
+			})
+			ctx = protocol.WithFeatureCtx(ctx)
+			require.Equal(cases[i].expectErr, errors.Cause(p.Validate(ctx, ex, nil)))
+		})
+	}
 }
 
 func TestProtocol_Handle(t *testing.T) {