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

Improvement RGB Isa instructions #201

Merged
merged 6 commits into from
Mar 1, 2024
Merged

Conversation

crisdut
Copy link
Member

@crisdut crisdut commented Jan 15, 2024

Description

This PR intent:

  • Add new macro instructions: cng and cnc.
  • Add support for use lds and ldg with registers [1].
  • Fix decode for cnp, cns, cng and cnc

[1] Depends:

Copy link
Member

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

Very good work!

I think we need to get rid of old commands - I do not see the usecase for the fixed index. If someone needs one, it is just two instructions, one to load the fixed index into a register.

Can you pls re-work PR by not adding new operations and instead modifying existing ones?

@crisdut
Copy link
Member Author

crisdut commented Jan 19, 2024

Very good work!

I think we need to get rid of old commands - I do not see the usecase for the fixed index. If someone needs one, it is just two instructions, one to load the fixed index into a register.

Today, only the UDA uses these two instructions with fixed indexes. I can change the code after rgb-core new release.

Can you pls re-work PR by not adding new operations and instead modifying existing ones?

Yes, I will make that!

@dr-orlovsky
Copy link
Member

Today, only the UDA uses these two instructions with fixed indexes. I can change the code after rgb-core new release.

Yes. But I will update the UDA script then

@crisdut
Copy link
Member Author

crisdut commented Jan 19, 2024

Today, only the UDA uses these two instructions with fixed indexes. I can change the code after rgb-core new release.

Yes. But I will update the UDA script then

Ok, sure. I reviewed the UDA script and I noticed the ldp uses a fixed index too. I think it would be better to change the ldc and ldp to support register instead of fixed indexes, right?

@dr-orlovsky
Copy link
Member

dr-orlovsky commented Jan 19, 2024

Yes, correct. We than can push constant number to a register and just add one instruction to the script in front of ldc and ldp

@crisdut
Copy link
Member Author

crisdut commented Jan 20, 2024

Hi @dr-orlovsky,

I was thinking, ldc and ldg are equivalent operations, right?

Is this separation due to operations such as Genesis, Transition and Enxtension?

@dr-orlovsky
Copy link
Member

They are not. ldc takes the contract global state, while ldg takes operations's global state (which, with the only except of genesis operation is not ever equal to contract).

@crisdut
Copy link
Member Author

crisdut commented Jan 20, 2024

They are not. ldc takes the contract global state, while ldg takes operations's global state (which, with the only except of genesis operation is not ever equal to contract).

Thanks for reply!

BTW, I finish the changes!

@dr-orlovsky
Copy link
Member

Can you pls re-do this PR against master and not v0.11 branch so we have CI running?

Also can you please run cargo +nightly fmt --all to remove the formatting changes which complicate the review?

@crisdut crisdut changed the base branch from v0.11 to master January 21, 2024 08:33
Copy link

codecov bot commented Jan 21, 2024

Codecov Report

Attention: Patch coverage is 0% with 78 lines in your changes are missing coverage. Please review.

Project coverage is 15.5%. Comparing base (0716f0e) to head (010603f).
Report is 3 commits behind head on master.

Files Patch % Lines
src/vm/op_contract.rs 0.0% 78 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##           master    #201   +/-   ##
======================================
  Coverage    15.5%   15.5%           
======================================
  Files          33      33           
  Lines        4165    4158    -7     
======================================
  Hits          644     644           
+ Misses       3521    3514    -7     
Flag Coverage Δ
rust 15.5% <0.0%> (+<0.1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@crisdut crisdut requested a review from dr-orlovsky January 21, 2024 09:58
Copy link
Member

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

I found several logical mistakes i the past and new code, which we have to address

src/vm/macroasm.rs Outdated Show resolved Hide resolved
src/vm/op_contract.rs Show resolved Hide resolved
src/vm/op_contract.rs Outdated Show resolved Hide resolved
src/vm/op_contract.rs Show resolved Hide resolved
src/vm/op_contract.rs Outdated Show resolved Hide resolved
Copy link
Member

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

Pls see my comment

src/vm/op_contract.rs Outdated Show resolved Hide resolved
@Gigi3d
Copy link

Gigi3d commented Feb 13, 2024

amazing stuff

@dr-orlovsky
Copy link
Member

dr-orlovsky commented Feb 18, 2024

Adding a global contract state seems to be very challenging and will require refactoring validation workflow: #208

I propose to restrict this PR to the changes in already implemented instructions - and leave LdG for v0.12

@crisdut
Copy link
Member Author

crisdut commented Feb 26, 2024

Adding a global contract state seems to be very challenging and will require refactoring validation workflow: #208

Great!

I propose to restrict this PR to the changes in already implemented instructions - and leave LdG for v0.12

I think you mean LdC, because in the master branch this instruction is not implemented yet. Right?

@dr-orlovsky
Copy link
Member

I think you mean LdC, because in the master branch this instruction is not implemented yet. Right?

Yes

@dr-orlovsky dr-orlovsky added the *security* Issues affecting safety/security (include undefined behaviours) label Feb 27, 2024
@dr-orlovsky
Copy link
Member

List of things I have changed:

  • src_reg was not modified, while the commands now accept a source regisger
  • the arguments can now fit byte if we shorten reg no to 16-bit. This also changes the size of the commands
  • LdF was not changed
  • docs had to be updated
  • assembly impl for ldp contained a error

@dr-orlovsky
Copy link
Member

Most of these things I proved in 8752e06, but in other commitments as well

@crisdut
Copy link
Member Author

crisdut commented Feb 27, 2024

Most of these things I proved in 8752e06, but in other commitments as well

Maxim, I think I found other issues, I will publish new commit.

Can you review, please?

@dr-orlovsky
Copy link
Member

Sure!

@dr-orlovsky
Copy link
Member

dr-orlovsky commented Feb 27, 2024

@crisdut why do you think we need this? Reg32, Reg16 and Reg8 are just different bit-length for the registry index, it has nothing to do with a8/a16/a32... The proposed commit breaks word alignment and adds "dummy" bits, which is unnecessary

@crisdut
Copy link
Member Author

crisdut commented Feb 27, 2024

@crisdut why do you think we need this? Reg32, Reg16 and Reg8 are just different bit-length for the registry index, it has nothing to do with a8/a16/a32... The proposed commit breaks word alignment and adds "dummy" bits, which is unnecessary

Oh Sorry, I understood that it was necessary to make these changes to follow with change in registers, but it really makes sense to avoid these changes.

I force-push it to remove it.

@dr-orlovsky
Copy link
Member

Tank you! I know this thing is confusing - I even did the same myself during work on this PR and then recalled that a16 doesn't imply Reg16 :)

Probably I have to rename types in AluVM...

dr-orlovsky
dr-orlovsky previously approved these changes Feb 27, 2024
Copy link
Member

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

LGTM, but I need your approval on my changes, that I do not miss something - and then I will merge

@crisdut
Copy link
Member Author

crisdut commented Feb 28, 2024

LGTM, but I need your approval on my changes, that I do not miss something - and then I will merge

I tested here and the code works.

ACK.

src/vm/macroasm.rs Outdated Show resolved Hide resolved
Copy link
Member

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

ACK 010603f

@crisdut
Copy link
Member Author

crisdut commented Feb 29, 2024

Hi @zoedberg @nicbus

Do you need any help getting this implementation started, or can we do the merge?

@zoedberg
Copy link
Contributor

@crisdut could you please rebase this on top of master? otherwise it doesn't compile in rgb-lib

@crisdut
Copy link
Member Author

crisdut commented Feb 29, 2024

@crisdut could you please rebase this on top of master? otherwise it doesn't compile in rgb-lib

This is very strange, could you add here the reason for the problem.

It is worth remembering that as we changed the AluVM instructions, we also need to update the rgb-schemata as well, as all instructions that used fixed indexes now use registers.

@crisdut
Copy link
Member Author

crisdut commented Feb 29, 2024

It is worth remembering that as we changed the AluVM instructions, we also need to update the rgb-schemata as well, as all instructions that used fixed indexes now use registers.

If you prefer, I can open the PR containing the changes and then you can test it with the two updated crates. What do you think?

@dr-orlovsky
Copy link
Member

@crisdut I think the reason that we break the AluVM compatibility, this first we need to update schemata with a different code

@crisdut
Copy link
Member Author

crisdut commented Mar 1, 2024

@crisdut I think the reason that we break the AluVM compatibility, this first we need to update schemata with a different code

Yes, I believe that's exactly what it is.

But we need to not only change the rgb-schemata, but also the rgb-std, as the size of the inputs in the operations was changed from tiny to small (see here), therefore, the transitions in the rgb-std need to be modified (but specifically, here). Right?

@crisdut
Copy link
Member Author

crisdut commented Mar 1, 2024

BTW,

@zoedberg I created two draft PRs, please see:

Could you check if the problem persists with these PRs?

If yes, please post the error log in the thread.

Hope this helps

@dr-orlovsky
Copy link
Member

Right?

Correct

@zoedberg
Copy link
Contributor

zoedberg commented Mar 1, 2024

@crisdut I've patched the 2 PRs and now it compiles. I've ran rgb-lib's test suite and everything works good so I think we can merge your PRs.

Copy link
Member

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

ACK 010603f

@dr-orlovsky dr-orlovsky merged commit 916ff4f into RGB-WG:master Mar 1, 2024
18 of 21 checks passed
@Gigi3d
Copy link

Gigi3d commented Mar 6, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working *consensus* Issues affecting distributed concensus *security* Issues affecting safety/security (include undefined behaviours)
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants