-
Notifications
You must be signed in to change notification settings - Fork 15
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: keccak256 #5
Conversation
eth-riscv-runtime/src/lib.rs
Outdated
lateout("a2") third, | ||
lateout("a3") fourth, | ||
in("t0") u32::from(Syscall::Keccak256), | ||
options(nostack, preserves_flags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
lateout
- 256 bytes of keccak hash goes to 4 registers, it's likeout("a0"), out("a1") ...
etc. but marked "late" to tell that it only writes to the register after all inputs are read. -
nostack
- tells the compiler this asm block doesn't use the stack. -
preserves_flags
- means thatasm!
block does not modify the flags register
Saw nostack
in other RISC-V adapters code, e.g this, but it is not necessary I think. Don't have any experience with asm!
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea I feel like the options are not needed here. I think we should remove it if it works without
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sick! Please undraft
let data_bytes = if size != 0 { | ||
emu.cpu | ||
.bus | ||
.get_dram_slice(offset..(offset + size)) | ||
.unwrap() | ||
} else { | ||
&mut [] | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be extracted into a function
eth-riscv-syscalls/src/lib.rs
Outdated
syscalls!( | ||
(0, Return, "return"), | ||
(1, SLoad, "sload"), | ||
(2, SStore, "sstore"), | ||
(3, Call, "call"), | ||
(4, Revert, "revert"), | ||
(5, Caller, "caller"), | ||
(6, Keccak256, "keccak256"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's start using EVM opcodes as syscall ids here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leonardoalt let's do on both PRs (for log also) with opcodes and then in a new PR/commit the rest
r55/src/exec.rs
Outdated
@@ -256,6 +257,30 @@ fn execute_riscv( | |||
let third_u64 = u64::from_be_bytes(padded_bytes); | |||
emu.cpu.xregs.write(12, third_u64); | |||
} | |||
6 => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would also be good to replace the hardcoded ids here by the actual syscall names (in the match arms)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes thanked about that too
Done it on Odyssey's draft
@leonardoalt let's merge both syscalls with ids as regarded opcodes and then make a PR with this improvements:
|
@0xurb ok sounds good, if you could just remove the asm options and see if it works without, we could remove & merge |
@leonardoalt done, |
Quick resolve for
KECCAK256
implementation related to #4cargo run
is passed correctly, but not too sure about this implementationcc: @leonardoalt