Repository: iotexproject/iotex-core
Pull request #4075 (2024-01-30 04:26:56)

[action] check calldata size instead of total size for 48kB init code limit
# Description
follow the same behavior as Ethereum.

Fixes #(issue)

## Type of change
Please delete options that are not relevant.
- [] Bug fix (non-breaking change which fixes an issue)
- [] New feature (non-breaking change which adds functionality)
- [x] Code refactor or improvement
- [] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
- [] This change requires a documentation update

# 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
- [x] 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]: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=iotexproject_iotex-core&pullRequest=4075) **Quality Gate passed**  
Kudos, no new issues were introduced!

[0 New issues](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=4075&resolved=false&inNewCodePeriod=true)  
[0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=iotexproject_iotex-core&pullRequest=4075&resolved=false&inNewCodePeriod=true)  
No data about Coverage  
[0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=iotexproject_iotex-core&pullRequest=4075&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=iotexproject_iotex-core&pullRequest=4075)


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject) Report
Attention: `541 lines` in your changes are missing coverage. Please review.
> Comparison is base [(`e1f0636`)](https://app.codecov.io/gh/iotexproject/iotex-core/commit/e1f0636b27ca54fa57da8cadb3034431143833fa?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject) 75.38% compared to head [(`1a0bcba`)](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject) 76.20%.
> Report is 164 commits behind head on master.

| [Files](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject) | Patch % | Lines |
|---|---|---|
| [action/protocol/staking/staking\_statereader.go](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject#diff-YWN0aW9uL3Byb3RvY29sL3N0YWtpbmcvc3Rha2luZ19zdGF0ZXJlYWRlci5nbw==) | 69.76% | [35 Missing and 17 partials :warning: ](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject) |
| [action/protocol/execution/evm/evm.go](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject#diff-YWN0aW9uL3Byb3RvY29sL2V4ZWN1dGlvbi9ldm0vZXZtLmdv) | 48.38% | [47 Missing and 1 partial :warning: ](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject) |
| [api/coreservice.go](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject#diff-YXBpL2NvcmVzZXJ2aWNlLmdv) | 63.24% | [37 Missing and 6 partials :warning: ](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject) |
| [api/web3server.go](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject#diff-YXBpL3dlYjNzZXJ2ZXIuZ28=) | 79.24% | [30 Missing and 3 partials :warning: ](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject) |
| [action/candidate\_endorsement.go](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject#diff-YWN0aW9uL2NhbmRpZGF0ZV9lbmRvcnNlbWVudC5nbw==) | 0.00% | [31 Missing :warning: ](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject) |
| [action/protocol/staking/protocol.go](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject#diff-YWN0aW9uL3Byb3RvY29sL3N0YWtpbmcvcHJvdG9jb2wuZ28=) | 36.36% | [28 Missing :warning: ](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject) |
| [action/candidate\_activate.go](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject#diff-YWN0aW9uL2NhbmRpZGF0ZV9hY3RpdmF0ZS5nbw==) | 0.00% | [25 Missing :warning: ](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject) |
| [...tion/protocol/staking/contractstake\_bucket\_type.go](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject#diff-YWN0aW9uL3Byb3RvY29sL3N0YWtpbmcvY29udHJhY3RzdGFrZV9idWNrZXRfdHlwZS5nbw==) | 0.00% | [24 Missing :warning: ](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject) |
| [action/protocol/rewarding/fund.go](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject#diff-YWN0aW9uL3Byb3RvY29sL3Jld2FyZGluZy9mdW5kLmdv) | 23.07% | [19 Missing and 1 partial :warning: ](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject) |
| [api/websocket.go](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject#diff-YXBpL3dlYnNvY2tldC5nbw==) | 0.00% | [20 Missing :warning: ](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject) |
| ... and [43 more](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject) | |

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #4075      +/-   ##
==========================================
+ Coverage   75.38%   76.20%   +0.82%     
==========================================
  Files         303      338      +35     
  Lines       25923    28811    +2888     
==========================================
+ Hits        19541    21956    +2415     
- Misses       5360     5737     +377     
- Partials     1022     1118      +96     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/iotexproject/iotex-core/pull/4075?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=iotexproject).

sonarcloud[bot]: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=iotexproject_iotex-core&pullRequest=4075) **Quality Gate passed**  
Kudos, no new issues were introduced!

[0 New issues](https://sonarcloud.io/project/issues?id=iotexproject_iotex-core&pullRequest=4075&resolved=false&inNewCodePeriod=true)  
[0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=iotexproject_iotex-core&pullRequest=4075&resolved=false&inNewCodePeriod=true)  
No data about Coverage  
[0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=iotexproject_iotex-core&pullRequest=4075&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=iotexproject_iotex-core&pullRequest=4075)



Patch:
diff --git a/action/protocol/execution/protocol.go b/action/protocol/execution/protocol.go
index 71f1133eb..ba5264ea2 100644
--- a/action/protocol/execution/protocol.go
+++ b/action/protocol/execution/protocol.go
@@ -89,14 +89,18 @@ func (p *Protocol) Validate(ctx context.Context, act action.Action, _ protocol.S
 	if !ok {
 		return nil
 	}
-	sizeLimit := _executionSizeLimit48KB
+	var (
+		sizeLimit = _executionSizeLimit48KB
+		dataSize  = uint32(len(exec.Data()))
+	)
 	fCtx := protocol.MustGetFeatureCtx(ctx)
 	if fCtx.ExecutionSizeLimit32KB {
 		sizeLimit = _executionSizeLimit32KB
+		dataSize = exec.TotalSize()
 	}
 
 	// Reject oversize execution
-	if exec.TotalSize() > sizeLimit {
+	if dataSize > 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 fde4680b6..05845a326 100644
--- a/action/protocol/execution/protocol_test.go
+++ b/action/protocol/execution/protocol_test.go
@@ -635,8 +635,8 @@ func TestProtocol_Validate(t *testing.T) {
 	}{
 		{"limit 32KB", 0, 32683, nil},
 		{"exceed 32KB", 0, 32684, action.ErrOversizedData},
-		{"limit 48KB", genesis.Default.SumatraBlockHeight, 49067, nil},
-		{"exceed 48KB", genesis.Default.SumatraBlockHeight, 49068, action.ErrOversizedData},
+		{"limit 48KB", genesis.Default.SumatraBlockHeight, uint64(_executionSizeLimit48KB), nil},
+		{"exceed 48KB", genesis.Default.SumatraBlockHeight, uint64(_executionSizeLimit48KB) + 1, action.ErrOversizedData},
 	}
 
 	for i := range cases {