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

feat(cartesi-machine): update machine bindings #102

Merged
merged 6 commits into from
Mar 21, 2025

Conversation

GCdePaula
Copy link
Collaborator

@GCdePaula GCdePaula commented Jan 29, 2025

New bindings for the new C API. Current commit is using release v0.19.0-test2. I believe we should only merge this on a proper release. It's also possible to test without a release (i.e. latest main branch commit), but requires a local docker installation.

Remember to run just clean-emulator, since your local copy will probably have build artifacts of older versions. You need to have the local supporting files too: runjust setup. To test, run cargo test -p cartesi-machine.

@GCdePaula GCdePaula force-pushed the feature/update-bindings branch 5 times, most recently from aa82642 to d05e406 Compare January 30, 2025 16:02
.expect("fail to convert input index")
>= input_index_boundary
{
if input_added.index >= U256::from(input_index_boundary) {

Choose a reason for hiding this comment

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

Why the index boundary have a different type?
And it might be better to convert it only once, outside the loop.

assert_data_eq(
"0x4441036546894c6fcf905b48b722f6b149ec0902955a6445c63cfec478568268",
// cast keccak (cast concat-hex (cast keccak "minhas") (cast keccak "bananas"))
Digest::from_data("minhas".as_bytes()).join(&Digest::from_data("bananas".as_bytes())),

Choose a reason for hiding this comment

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

:-D

@GCdePaula GCdePaula force-pushed the feature/update-bindings branch 2 times, most recently from 5b1d6b5 to edfe2c2 Compare March 11, 2025 18:27
@GCdePaula
Copy link
Collaborator Author

GCdePaula commented Mar 11, 2025

I've done some work updating the machine Lua binding. Currently getting this error

[#2][03/11/2025 15:32:16] Enter match at HEIGHT: 1
[#2][03/11/2025 15:32:16] seal leaf match in tournament 0x856e4424f806D16E8CBC702B3c0F2ede5468eae5 of level 2 for commitment 0x3e38da1bd2e13a060a500f81685c94a0da5221edf5fb689b08be6bd790c8a435
[#2][03/11/2025 15:32:16] seal leaf match reverted: ../../client-lua/player/sender.lua:74: Send transaction `sealLeafMatch((bytes32,bytes32),bytes32,bytes32,bytes32,bytes32[])` reverted:
Error: server returned an error response: error code 3: execution reverted: custom error 0x773af801: 500e47167838b2b9186dc93ef5044d3306badc3da4f131b9d08fc5c008ee485af71849fb1501026e3cbf52a5b655e30f53a335c1c4a7a03e6b0cf94a8800ab2a, data: "0x773af801500e47167838b2b9186dc93ef5044d3306badc3da4f131b9d08fc5c008ee485af71849fb1501026e3cbf52a5b655e30f53a335c1c4a7a03e6b0cf94a8800ab2a"
, current left: 0x9085aa49ed91d470bcbe48b0273f03d815df2c686bd6261ba8b9c82bad1abf7c, current right: 0x1d3793af302afcf7906f403087a54840912d340c4e4fd6ed23d11312f1cc6f0d,
                    my left: 0xe60d1e23d84e5af8d96b3a684ebc68eb6260ad93066f7407e14d5ccf46e14725, my right: 0xc8fceed62a60a603ddaaffb9babe88daccaefb043bb41e69345b889c286a8980, agree_state: 0xf71849fb1501026e3cbf52a5b655e30f53a335c1c4a7a03e6b0cf94a8800ab2a

EDIT: I think this is not an error exactly, just that the Sybil has the incorrect initial state, and the smart contract is rejecting it.

@GCdePaula GCdePaula force-pushed the feature/update-bindings branch 14 times, most recently from acce7cf to 8cd889b Compare March 13, 2025 20:52
@GCdePaula GCdePaula marked this pull request as ready for review March 13, 2025 21:22
@GCdePaula
Copy link
Collaborator Author

Updated emulator version to 0.19, updated Rust bindings for new C API, updated Rust and Lua code that uses machine API.

Added honeypot as a submodule, added it to the build pipeline, and added a new test target that runs integration test using honeypot.

Updated CI.

@GCdePaula GCdePaula force-pushed the feature/update-bindings branch from 8cd889b to a8d3185 Compare March 16, 2025 16:18
@stephenctw
Copy link
Collaborator

I've done some work updating the machine Lua binding. Currently getting this error

[#2][03/11/2025 15:32:16] Enter match at HEIGHT: 1
[#2][03/11/2025 15:32:16] seal leaf match in tournament 0x856e4424f806D16E8CBC702B3c0F2ede5468eae5 of level 2 for commitment 0x3e38da1bd2e13a060a500f81685c94a0da5221edf5fb689b08be6bd790c8a435
[#2][03/11/2025 15:32:16] seal leaf match reverted: ../../client-lua/player/sender.lua:74: Send transaction `sealLeafMatch((bytes32,bytes32),bytes32,bytes32,bytes32,bytes32[])` reverted:
Error: server returned an error response: error code 3: execution reverted: custom error 0x773af801: 500e47167838b2b9186dc93ef5044d3306badc3da4f131b9d08fc5c008ee485af71849fb1501026e3cbf52a5b655e30f53a335c1c4a7a03e6b0cf94a8800ab2a, data: "0x773af801500e47167838b2b9186dc93ef5044d3306badc3da4f131b9d08fc5c008ee485af71849fb1501026e3cbf52a5b655e30f53a335c1c4a7a03e6b0cf94a8800ab2a"
, current left: 0x9085aa49ed91d470bcbe48b0273f03d815df2c686bd6261ba8b9c82bad1abf7c, current right: 0x1d3793af302afcf7906f403087a54840912d340c4e4fd6ed23d11312f1cc6f0d,
                    my left: 0xe60d1e23d84e5af8d96b3a684ebc68eb6260ad93066f7407e14d5ccf46e14725, my right: 0xc8fceed62a60a603ddaaffb9babe88daccaefb043bb41e69345b889c286a8980, agree_state: 0xf71849fb1501026e3cbf52a5b655e30f53a335c1c4a7a03e6b0cf94a8800ab2a

EDIT: I think this is not an error exactly, just that the Sybil has the incorrect initial state, and the smart contract is rejecting it.

Sorry I just saw this. Yes the error means the agree state was wrong. Were you able to solve it? Was it a bug in the code or was it just a misconfiguration?

Copy link
Collaborator

@stephenctw stephenctw left a comment

Choose a reason for hiding this comment

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

Amazing work and great quality written tests. It's a long PR, I'm not sure if I overlook anything, but it looks great to me!

The repository includes examples for different components of Dave:

- **PRT Lua Client (Compute):**
Follow the instructions in the [PRT Lua client README](prt/tests/compute/README.md).
Copy link
Collaborator

@stephenctw stephenctw Mar 20, 2025

Choose a reason for hiding this comment

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

I think compute Lua v.s Rust examples are kind of broken. After the whole rust workspace refactor, only Lua v.s Lua example works. If you think it's a high priority, I'll start working on it.

Also, I think we should adapt just for compute examples as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree! But let's sync later on the priority. Could you open an issue for now?

);

drop(anvil);
Ok(())
}

#[tokio::test]
async fn test_blockchain_reader() -> Result<()> {
let (anvil, provider, input_box_address, consensus_address) = spawn_anvil_and_provider();
async fn test_blockchain_reader_aaa() -> Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why adding _aaa at the end?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have no idea what happened 😅

logs.push(&reset_logs);
Ok(encode_access_logs(logs, encode_input))
} else {
let step_logs = self.machine.log_uarch_step(log_type, false)?;
let step_logs = self.machine.log_step_uarch(LogType::default())?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I actually don't really understand when to set large_data and when to set annotations.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Me neither. Here it's important to set all permutations to be sure the deserialization works.

I think for Dave we don't need either, ever. I think these are just for debugging purposes for the machine team. At least that's what they told me.

@GCdePaula GCdePaula merged commit 11ae5ab into main Mar 21, 2025
1 check passed
@GCdePaula GCdePaula deleted the feature/update-bindings branch March 21, 2025 09:11
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