Skip to content
This repository was archived by the owner on Apr 8, 2026. It is now read-only.

Commit f89284f

Browse files
authored
go: Expose transient storage API (#708)
1 parent 0e0172d commit f89284f

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

bindings/go/evmc/host.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const struct evmc_host_interface evmc_go_host = {
2727
(evmc_emit_log_fn)emitLog,
2828
(evmc_access_account_fn)accessAccount,
2929
(evmc_access_storage_fn)accessStorage,
30+
(evmc_get_transient_storage_fn)getTransientStorage,
31+
(evmc_set_transient_storage_fn)setTransientStorage,
3032
};
3133

3234

bindings/go/evmc/host.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ type HostContext interface {
103103
createAddr Address, err error)
104104
AccessAccount(addr Address) AccessStatus
105105
AccessStorage(addr Address, key Hash) AccessStatus
106+
GetTransientStorage(addr Address, key Hash) Hash
107+
SetTransientStorage(addr Address, key Hash, value Hash)
106108
}
107109

108110
//export accountExists
@@ -247,3 +249,15 @@ func accessStorage(pCtx unsafe.Pointer, pAddr *C.evmc_address, pKey *C.evmc_byte
247249
ctx := getHostContext(uintptr(pCtx))
248250
return C.enum_evmc_access_status(ctx.AccessStorage(goAddress(*pAddr), goHash(*pKey)))
249251
}
252+
253+
//export getTransientStorage
254+
func getTransientStorage(pCtx unsafe.Pointer, pAddr *C.struct_evmc_address, pKey *C.evmc_bytes32) C.evmc_bytes32 {
255+
ctx := getHostContext(uintptr(pCtx))
256+
return evmcBytes32(ctx.GetTransientStorage(goAddress(*pAddr), goHash(*pKey)))
257+
}
258+
259+
//export setTransientStorage
260+
func setTransientStorage(pCtx unsafe.Pointer, pAddr *C.evmc_address, pKey *C.evmc_bytes32, pVal *C.evmc_bytes32) {
261+
ctx := getHostContext(uintptr(pCtx))
262+
ctx.SetTransientStorage(goAddress(*pAddr), goHash(*pKey), goHash(*pVal))
263+
}

bindings/go/evmc/host_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ func (host *testHostContext) AccessStorage(addr Address, key Hash) AccessStatus
7272
return ColdAccess
7373
}
7474

75+
func (host *testHostContext) GetTransientStorage(addr Address, key Hash) Hash {
76+
return Hash{}
77+
}
78+
79+
func (host *testHostContext) SetTransientStorage(addr Address, key Hash, value Hash) {
80+
}
81+
82+
7583
func TestGetBlockNumberFromTxContext(t *testing.T) {
7684
// Yul: mstore(0, number()) return(0, msize())
7785
code := []byte("\x43\x60\x00\x52\x59\x60\x00\xf3")

0 commit comments

Comments
 (0)