-
Notifications
You must be signed in to change notification settings - Fork 80
investigate creating the sourcemap for the optimized-bytecode #215
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
Comments
So to address this issue we need to change the // instead of
const optimisedBytecode = optimiseBytecode(traversal.output);
// rework to this
const { optimisedBytecode , optimisedTraversal } = optimiseBytecode(traversal); The for (let i = 0; i < runs; i += 1) {
const oldScript = script;
script = replaceOps(script, optimisations);
// Break on fixed point
if (scriptToAsm(oldScript) === scriptToAsm(script)) break;
} after each optimization ( |
One note is that the After this change there wouldn't be a separate 'debugging' bytecode, meaning that we'd remove the |
@mr-zwets started with a PR that works on this. Today we discussed the steps that we think we should take to achieve this fully. After every step we should make sure that the resulting optimised bytecode should stay the exact same as before.
|
Today we started off with quickly implementing steps 1 & 2 without too much effort. With step 3, we decided to still use regex to find the matches, and then count spaces in the strings to convert a string match index to a script index. We got started on step 4, which is still work in progress. What we did is when we find a match, we retrieve the first and last location corresponding to that matched pattern and merge them into a single location entry. We then apply that location entry to every opcode in the replacement and splice the locationData array to remove the old location entries and add the new location entries. We believe this is not yet entirely accurate, because there are certain cases where the last location entry might have a require(checkSig(s, pk));
// results in => CHECKSIG VERIFY
// first location = CHECKSIG, which starts at column 8
// last location = VERIFY, which starts at column 0 So we probably need to look at the min/max values within the replaced location entries. We also just applied the Then after fixing those last remaining issues with location data mapping, we still need to do a similar thing for instruction pointer mapping, so that the |
Today we continued on step 4. We are now correctly updating the location data / sourcemap whenever we apply optimisations. We got started on updating the instruction pointers for After finishing that step, then we should update all the fixtures / tests that are affected by these changes, and we should add a test for multicontract introspection to make sure that our changes have fixed that use-case. |
Today we managed to make some progress with making sure the However, we ran into a difficult problem with bool x = 1 == 2;
console.log(x);
require(x); This example compiles to We considered to keep using the unoptimised bytecode just for the console.logs, but decided that we really do want it to work with introspection properly, which requires us to use the optimised bytecode. We brainstormed about this issue and we came up with the following solution: We move the Next session, we want to implement this plan:
|
Today we tried to get started on the plan above, but we ran into some issues with our previous work. When updating log/require IPs, we did not take the constructor arguments into account (which contribute to the IP number, but not to the Next session, we will need to implement the plan that we mentioned in the previous comment. When implementing step 2a, this will have to change some of the ternary statements that we've added as part of today's commit. Additionally, we noticed that somehow for some console.log entries have strange When updating the stack cleanup code in the debugging file, we added |
Today we implemented most of the "transformations" logic as specified in the comments above. There is still one issue remaining where there is a We haven't figured out the cause of this bug yet, so we've planned another session for tomorrow to figure it out. |
The We also updated the docs and merged the changes into the We still need to expand our test cases to make sure there are no edge cases that still contain some bugs. We also still need to fix the type
|
We'll close this issue as completed even though there are still a few remaining test cases. We will document these test cases in #230 and implement / track them there alongside the other related test cases for advanced transaction builder debugging. |
currently the debug tooling operates on the unoptimized bytecode which has been a source of confusion for developers familiar with the low level workings.
For better support for hand-optimization of contracts it would be great if the Bitauth IDE debugging showed the final, optimized bytecode for the contract.
The text was updated successfully, but these errors were encountered: