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

fix(address-hooks): version robustness and hardening #10683

Merged
merged 3 commits into from
Dec 13, 2024

Conversation

michaelfig
Copy link
Member

closes: #10681

Description

Be more robust for Address Hook version compatibility: return an error if the magic bytes match but the version number is unsupported. If the magic bytes don't match, it is not an address hook, so pass through the specimen as the baseAddress with empty hookData.

Also, harden the exports and returned objects if running under HardenedJS.

Security Considerations

Stronger Address Hook classification helps prevent accidental collisions. Hardened return objects and exported functions have fewer mutability concerns.

Scaling Considerations

n/a

Documentation Considerations

n/a

Testing Considerations

Some unhappy-path testing has been added to verify at least these issues have been addressed.

Upgrade Considerations

n/a

@michaelfig michaelfig self-assigned this Dec 11, 2024
@michaelfig michaelfig force-pushed the mfig-no-future-address-hooks branch from 2f1fb4a to 8846a0d Compare December 11, 2024 22:44
Copy link

cloudflare-workers-and-pages bot commented Dec 11, 2024

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 80fee60
Status: ✅  Deploy successful!
Preview URL: https://c51e0c3f.agoric-sdk.pages.dev
Branch Preview URL: https://mfig-no-future-address-hooks.agoric-sdk.pages.dev

View logs

@michaelfig michaelfig force-pushed the mfig-no-future-address-hooks branch from 8846a0d to e437a10 Compare December 11, 2024 22:56
Copy link
Member

@0xpatrickdev 0xpatrickdev left a comment

Choose a reason for hiding this comment

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

The hardening and null prototype changes LGTM. I'll let @gibson042 review the versioning changes.

If convenient, consider adding a @throws annotation to decodeAddressHook like b6d20f7. If not, I'll include it in a PR I'm updating to depend on this.

Copy link
Member

@gibson042 gibson042 left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -25,7 +25,7 @@ const (

// AddressHookMagic is a magic byte prefix that identifies a hooked address.
// Chosen to make bech32 address hooks that look like "agoric10rch..."
var AddressHookMagic = []byte{0x78, 0xf1, 0x70 | AddressHookVersion}
var AddressHookMagic = []byte{0x78, 0xf1, 0x70 /* | AddressHookVersion */}
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: rename to something AddressHookBytePrefix.

}

if (version !== ADDRESS_HOOK_VERSION) {
return `Unsupported address hook version ${version}`;
Copy link
Member

Choose a reason for hiding this comment

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

I didn't get to this function before, but it's bizarre for it to return strings rather than throw exceptions. Please document the reason (or just eliminate the need by e.g. merging it into splitHookedAddress).

...and even if it is important to return rather than throw, consider future-proofing by returning a composite { baseAddress, hookData } | { error } record.

Copy link
Member Author

Choose a reason for hiding this comment

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

it's bizarre

Indeed. It's the style that the bech32 package was written in, and it rubbed off on me. :P Time to clean up that muck.

@michaelfig michaelfig force-pushed the mfig-no-future-address-hooks branch from e437a10 to a8a6172 Compare December 12, 2024 23:21
@michaelfig michaelfig marked this pull request as ready for review December 12, 2024 23:21
@michaelfig michaelfig requested a review from a team as a code owner December 12, 2024 23:21
@michaelfig michaelfig added automerge:no-update (expert!) Automatically merge without updates agd Agoric (Golang) Daemon labels Dec 12, 2024
@michaelfig michaelfig force-pushed the mfig-no-future-address-hooks branch from a8a6172 to 80fee60 Compare December 12, 2024 23:47
@mergify mergify bot merged commit ddff762 into master Dec 13, 2024
81 checks passed
@mergify mergify bot deleted the mfig-no-future-address-hooks branch December 13, 2024 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agd Agoric (Golang) Daemon automerge:no-update (expert!) Automatically merge without updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Address Hooks are misclassified if versions don't match
3 participants