Skip to content

fix(kms): make the AWS KMS signer support dynamic-fee transactions - #792

Open
renatomaia wants to merge 18 commits into
next/2.0from
fix/awsKmsDynamicFeeSigning
Open

fix(kms): make the AWS KMS signer support dynamic-fee transactions#792
renatomaia wants to merge 18 commits into
next/2.0from
fix/awsKmsDynamicFeeSigning

Conversation

@renatomaia

@renatomaia renatomaia commented Jul 21, 2026

Copy link
Copy Markdown

Problem

The AWS KMS factory is still built with types.NewEIP155Signer(chainId). That signer is legacy-only. Direct geth bindings can create dynamic-fee transactions when GasPrice is nil and the chain has a base fee, which is the normal EIP-1559 path. In that case the KMS code hashes and attaches the signature using the wrong signer family.

AI Review Findings

This PR also implements some improvements described in review here.

Divergences from Proposed Fixes

  1. C3 is ignored because CreateAWSTransactOptsFactory is actually called on Claimer and PRT with a time-bounded context (CARTESI_MAX_STARTUP_TIME).
  2. C4 is implemented as recommended in the review, however this fix only for a particular cause of service failue (KMS authentication failure on startup), and we intend to emulate the multi-process service lifecyle in the single-process mode in PR#785.
  3. H7 and Y6 are ignored because we don't want to run AWS Local Stack locally by default.

Commit relation to Findings

The table below lists the commits, and column ID indicates which improvement is introduced.

ID Commit Change Component Description
7a3951d fix kms make the AWS KMS signer support dynamic-fee transactions
H1 5b17f6d test kms add unit test for AWS KMS authentication
7e388a3 test integration add make target to run AWS LocalStack
H2 ad56d20 test integration fix AWS KMS subtest execution
H3 4b17c3d test integration use new style for Ethereum transactions for better test coverage
H6 4445d6c test integration only run AWS Local Stack for required tests
H8 e5bcf39 test integration fix clean up of configurations used in tests
H9 d6579d7 test integration isolate AWS KMS funding account
Y5 c302b18 test integration allow built-in readness check of AWS LocalStack image
Y9 cd3705e test integration clean up AWS KMS test resources
C1,H4,H12 71fa8fe fix kms remove redundant configuration variables for AWS KMS
H5 a989251 fix kms handle invalid AWS KMS authentication
H10 8658356 test kms improve test coverage of AWS KMS authentication
Y3,Y7,Y8 67da6ca refactor kms fix small details in implementation and tests
7db8476 style kms avoid lint errors
C2 2eda6ed feat claimer,prt log submitter identity on service startup
H11 05ee583 fix cli use a single authentication for all deposit transactions
C4 275baf3 feat node delay startup of services until able to authenticate

@renatomaia
renatomaia requested review from mpolitzer and vfusco July 21, 2026 20:51
@renatomaia renatomaia self-assigned this Jul 21, 2026
@renatomaia
renatomaia force-pushed the fix/awsKmsDynamicFeeSigning branch 3 times, most recently from 26060af to e412f81 Compare July 22, 2026 13:04
@mpolitzer

Copy link
Copy Markdown

Old tests needed to fill in the ARN variable with a valid AWS KMS instance to work. That would cost money and expose secrets, so it is disabled by default. But maybe with the localstack setup it could be enabled or refactored, any thoughts on that?

@renatomaia
renatomaia force-pushed the fix/awsKmsDynamicFeeSigning branch 3 times, most recently from 9092af5 to bae5e92 Compare July 23, 2026 22:32
@vfusco
vfusco requested a review from Copilot July 24, 2026 10:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the AWS KMS-backed transaction signing path to correctly support EIP-1559 (dynamic-fee) transactions by switching to the appropriate signer family, and adds unit + LocalStack-based integration coverage to prevent regressions.

Changes:

  • Use types.LatestSignerForChainID for AWS KMS signing (instead of legacy-only NewEIP155Signer).
  • Add a unit test ensuring dynamic-fee tx signing + sender recovery works.
  • Add a LocalStack KMS integration test and wire LocalStack into the integration compose + shard selection.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
internal/config/auth/auth.go Switch AWS KMS signing to latest signer; add optional region/endpoint support (currently has a compile issue to fix).
internal/config/generated.go Add generated config key + getter for CARTESI_AUTH_AWS_KMS_ENDPOINT.
internal/config/generate/Config.toml Define the new AWS KMS endpoint config entry for generation.
internal/kms/signtx_test.go Add unit test for signing DynamicFeeTx with AWS KMS factory.
test/integration/localstack_integration_test.go New LocalStack KMS integration suite verifying legacy + dynamic-fee signing end-to-end (currently has a config-setting bug to fix).
test/compose/compose.integration.yaml Add LocalStack service and env wiring for integration-test container.
Makefile Add LocalStack start/stop/restart targets and register an awskms integration shard.
Files not reviewed (1)
  • internal/config/generated.go: Generated file
Comments suppressed due to low confidence (1)

internal/config/auth/auth.go:83

  • These errors.Is checks reference config.ErrNotDefined, but this file already dot-imports internal/config. After removing the duplicate config import, these references should use ErrNotDefined directly.
		kmsRegion, err := GetAuthAwsKmsRegion()
		if !errors.Is(err, config.ErrNotDefined) {
			if err != nil {
				return nil, err
			}
			awsOpts = append(awsOpts, aws_cfg.WithRegion(kmsRegion.Value))
		}
		kmsEndpoint, err := GetAuthAwsKmsEndpoint()
		if !errors.Is(err, config.ErrNotDefined) {
			if err != nil {
				return nil, err
			}
			awsOpts = append(awsOpts, aws_cfg.WithBaseEndpoint(kmsEndpoint.Value))
		}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/config/auth/auth.go Outdated
Comment thread test/integration/localstack_integration_test.go Outdated
Comment thread Makefile Outdated
Comment thread Makefile Outdated
@renatomaia
renatomaia force-pushed the fix/awsKmsDynamicFeeSigning branch 2 times, most recently from 432a6f9 to 4d1433c Compare July 24, 2026 12:17
@renatomaia
renatomaia force-pushed the fix/awsKmsDynamicFeeSigning branch from 4d1433c to 1f34938 Compare August 11, 2026 15:28
mpolitzer
mpolitzer previously approved these changes Aug 11, 2026
@renatomaia
renatomaia force-pushed the fix/awsKmsDynamicFeeSigning branch from 1f34938 to 6dff1ae Compare August 21, 2026 19:18
@renatomaia
renatomaia force-pushed the fix/awsKmsDynamicFeeSigning branch 3 times, most recently from 8b7dd6a to 3b8473d Compare August 26, 2026 23:51
- Exercises the real 'GetTransactOptsFactory' AWS wiring.
- Uses an httptest KMS implementation—no Docker or AWS access.
- Tests dynamic-fee and legacy transactions.
- Verifies the recovered sender matches the KMS key.
- Uses isolated dummy AWS credentials and resets Viper state.
@renatomaia
renatomaia force-pushed the fix/awsKmsDynamicFeeSigning branch from 3b8473d to 7a2a158 Compare August 27, 2026 14:18
- Replaced nondeterministic map iteration with an ordered test-case slice.
- Replaced s.T().Run with s.Run, ensuring suite assertions target the correct subtest.
- Legacy and dynamic-fee cases now run predictably and report failures independently.
… test coverage

- Funding transfers now use EIP-1559 `DynamicFeeTx`.
- Gas tip and fee caps are derived from the current chain state.
- `sendFunds` waits for transaction mining before returning.
- Receipt success is asserted, removing the funding race.
- Ethereum clients are closed after use.
- LocalStack is now behind the awskms Compose profile.
- Its dependency is optional when that profile is inactive.
- Compose runners activate the profile only when the selected shards include awskms.
- The awskms shard is excluded from the multiprocess topology.
- Replaced `TearDownSuite` cleanup with eagerly registered `t.Cleanup` callbacks.
- KMS key deletion now uses a fresh background context with a 10-second timeout.
- Viper is fully reset and configuration defaults are restored.
- Removed suite fields that existed only for deferred teardown.
Use a dedicated Foundry account to avoid nonce collisions with the node submitter and other integration-test actors.
Removed the custom gateway-only LocalStack healthcheck, allowing the image’s
built-in per-service readiness check and start period to apply.
- Hoisted the Ethereum client into SetupSuite and registered cleanup once.
- Reused the client for both funding transfers.
- Read AWS_REGION from the environment, defaulting to us-east-1.
- Enforced the bind.SignerFn address contract with bind.ErrNotAuthorized.
- Removed CARTESI_AUTH_AWS_KMS_REGION and CARTESI_AUTH_AWS_KMS_ENDPOINT.
- AWS KMS now uses the SDK’s standard region and endpoint resolution.
- Updated tests and LocalStack instructions to use AWS_REGION and AWS_ENDPOINT_URL_KMS.
- Documented AWS-provided configuration and the KMS alias risk.
- `assembleSignature` now rejects `r` or `s` components longer than 32 bytes with a descriptive error.
- Added regression tests covering overlong `r` and `s`.
- `normalizeR` passthrough, zero-padding trim, and malformed-padding rejection.
- High-`s` normalization.
- Non-canonical DER `r` and `s` handling through a fake KMS client.
- Unrecoverable signature failure.
- `From()` identity reporting.
- Unauthorized signer rejection, verifying KMS is never called.
- Added the `endtoendtests` build tag to .`golangci.yml`.
- Replaced unused `ethtypes.NewEIP155Signer` with the current `ethtypes.LatestSignerForChainID` in tests.
- Replaced `reflect.DeepEqual` with `bytes.Equal`.
- Recovery now tries both recovery IDs when `Ecrecover` fails.
- Added a regression test for that behavior.
- Reused one Ethereum client in the surviving manual test and closed it after use.
- Replaced deprecated `types.NewTransaction` with `types.NewTx`.
- ERC-20 deposit now creates one transaction-options factory per command.
- The factory’s address is reused for confirmation output.
- Fresh transaction options are derived from that same factory for approval and deposit.
- Existing CLI callers remain compatible through GetTransactOpts.
@renatomaia
renatomaia force-pushed the fix/awsKmsDynamicFeeSigning branch from 7a2a158 to 275baf3 Compare August 28, 2026 01:22
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.

3 participants