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

Bugfix/encoded bool function parameter #1350

Merged
merged 7 commits into from
Feb 12, 2024

Conversation

adamgall
Copy link
Member

@adamgall adamgall commented Feb 10, 2024

Depends on PR #1349

Description

Introduces some code to convert string "true"/"false" into boolean true or false, when passed into ethers' encodeFunctionData, which seems to be the only way to get that function to spit out the correct encoded data.

Notes

I don't love this current implementation that I just did to check whether the incoming parameter is a"true"/"false" string, and then converts it to a boolean value. Right now that logic is entirely disconnected from the actual type that the user says those parameters should be (which is declared in the functionSignature variable).

Consider a function of the following signature: foo(string bar), and the user wants to encode that string parameter with a value of "true". With this current implementation, it'll encode it as

0xf31a696900000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000,

when the encoding that the user actually wants is

0xf31a6969000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000047472756500000000000000000000000000000000000000000000000000000000

This happens because if we see the string "true" anywhere in the parameter list, we convert it to a bool true regardless of what type the user declared it should be in the functionSignature.

I would consider this PR to be a HOTFIX, to get something out the door quickly.

Issue / Notion doc (if applicable)

n/a

Testing

npm run test to run the unit test suite. Notice how there are failing tests.

There are a handful of failing unit tests in this PR, which should either be commented out, OR fixed, in order to merge.

If we decide to comment out for now, that is an explicit decision to merge with known bugs in this critical code.

The ideal scenario is to refactor the encodeFunction function, to pair up the individual types with their values, so we can make a more informed decision on when to "convert" from a string "true"/"false" to a boolean true/false, instead of optimistically always assuming that those values are supposed to be bool, as in this PR's implementation.

Screenshots (if applicable)

n/a

@adamgall adamgall requested review from mudrila and Da-Colon February 10, 2024 21:47
Copy link

netlify bot commented Feb 10, 2024

Deploy Preview for fractal-framework-interface-dev ready!

Name Link
🔨 Latest commit b0f1692
🔍 Latest deploy log https://app.netlify.com/sites/fractal-framework-interface-dev/deploys/65ca63f44805ff00080f2a20
😎 Deploy Preview https://deploy-preview-1350--fractal-framework-interface-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

expect(encodeFunction('foo', 'string', '')).toEqual(encoded);
});

test('Function encoding with [string="hello, world"', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

For this failing test I'd rather comment this out - our UX flow currently depends on separating params with commas, so in order to get this working - we need to adjust the UX flow itself. Making it look and work more like we have in ProposalTemplate definitely will give us ability to support strings with comma and pretty much any other characters

Copy link
Contributor

Choose a reason for hiding this comment

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

@Da-Colon Added test.skip for those expected-to-fail test cases - feel free to remove those skips if you'll figure out proper implementation

@@ -36,3 +36,27 @@ test('Function encoding with [uint8=100]', () => {
const encoded = new utils.Interface(['function foo(uint8)']).encodeFunctionData('foo', [100]);
expect(encodeFunction('foo', 'uint8', '100')).toEqual(encoded);
});

test('Function encoding with [string="true"]', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This sounds more like an edge-case though, but I guess it highlights overall flakiness and fragileness of our encodeFunction

src/utils/crypto.ts Show resolved Hide resolved
@adamgall adamgall requested a review from xhad February 12, 2024 15:39
Copy link
Contributor

@Da-Colon Da-Colon left a comment

Choose a reason for hiding this comment

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

Approved. I think the fix here would be to bring over the UI components from the Proposal Template setup which separates parameters into thier own inputs so will be much easier to handle the different parameter types

@mudrila mudrila merged commit c159034 into develop Feb 12, 2024
5 of 6 checks passed
@mudrila mudrila deleted the bugfix/encoded-bool-function-parameter branch February 12, 2024 18:36
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